Skip to content

Commit

Permalink
Test save_whitelist()
Browse files Browse the repository at this point in the history
* Test save_whitelist failure scenarios
  • Loading branch information
cbowman0 committed Jul 5, 2016
1 parent 2d23e70 commit 3a00d67
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions webapp/tests/test_whitelist.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import errno
import mock
import os
import pickle

Expand All @@ -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')

Expand Down Expand Up @@ -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'})

0 comments on commit 3a00d67

Please sign in to comment.