From 3a00d67f55aa572ce5c6d1b554d0326865021211 Mon Sep 17 00:00:00 2001 From: Christopher Bowman Date: Tue, 5 Jul 2016 09:41:21 -0400 Subject: [PATCH] Test save_whitelist() * Test save_whitelist failure scenarios --- webapp/tests/test_whitelist.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/webapp/tests/test_whitelist.py b/webapp/tests/test_whitelist.py index dd427ecd5..37a1b4536 100644 --- a/webapp/tests/test_whitelist.py +++ b/webapp/tests/test_whitelist.py @@ -1,3 +1,5 @@ +import errno +import mock import os import pickle @@ -7,6 +9,8 @@ from django.core.urlresolvers import reverse from django.test import TestCase +from graphite.whitelist.views import save_whitelist + class WhitelistTester(TestCase): settings.WHITELIST_FILE = os.path.join(DATA_DIR, 'lists/whitelist') @@ -93,3 +97,14 @@ def test_whitelist_remove_missing(self): response = self.client.get(url) self.assertEqual(response.status_code, 200) self.assertEqual(response.content, "a.b.c.d\ne.f.g.h") + + def test_save_whitelist(self): + self.addCleanup(self.wipe_whitelist) + self.assertEqual(save_whitelist({'a.b.c.d','e.f.g.h'}), None) + + @mock.patch('os.rename') + def test_save_whitelist_rename_failure(self, rename): + self.addCleanup(self.wipe_whitelist) + rename.side_effect = OSError(errno.EPERM, 'Operation not permitted') + with self.assertRaises(OSError): + save_whitelist({'a.b.c.d','e.f.g.h'})