Ticket #28823: test_bug.py

File test_bug.py, 1.1 KB (added by Paolo D'Apice, 7 years ago)

Sample test case

Line 
1from django.test import TestCase, override_settings
2from django.conf import settings
3
4TEST_SETTINGS = {
5 'MY_DATA': {
6 'foo': 1,
7 'bar': 2
8 }
9}
10
11
12class Dummy:
13 def foo(self):
14 return settings.MY_DATA.get('foo')
15
16 def bar(self):
17 return settings.MY_DATA.get('bar')
18
19
20@override_settings(**TEST_SETTINGS)
21class SimpleTest(TestCase):
22 def setUp(self):
23 self.dummy = Dummy()
24
25 def test_foobar(self):
26 self.assertEqual(self.dummy.foo(), 1)
27 self.assertEqual(self.dummy.bar(), 2)
28
29 @override_settings()
30 def test_delete_my_data(self):
31 del settings.MY_DATA
32 with self.assertRaises(AttributeError):
33 self.dummy.foo()
34 with self.assertRaises(AttributeError):
35 self.dummy.bar()
36
37 @override_settings()
38 def test_delete_foo(self):
39 del settings.MY_DATA['foo']
40 self.assertIsNone(self.dummy.foo())
41 self.assertEqual(self.dummy.bar(), 2)
42
43 def test_foobar_again(self):
44 self.assertEqual(self.dummy.foo(), 1)
45 self.assertEqual(self.dummy.bar(), 2)
Back to Top