Skip to content

Commit 87faf50

Browse files
committed
Remove code duplication in tests.
1 parent 4c13be1 commit 87faf50

1 file changed

Lines changed: 10 additions & 14 deletions

File tree

‎tests/test_invalid_config_file.py‎

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,45 +7,41 @@
77
from unittest import TestCase
88
from ppp_core.exceptions import InvalidConfig
99

10-
class InvalidConfFileTestCase(TestCase):
10+
class NoConfFileTestCase(TestCase):
1111
def testNoConfFile(self):
1212
self.app = TestApp(app)
1313
obj = {'language': 'en', 'tree': {}}
1414
self.assertRaises(InvalidConfig, self.app.post_json,
1515
'/', obj, status='*')
1616

17-
def testEmptyConfFile(self):
17+
class InvalidConfFileTestCase(TestCase):
18+
def setUp(self):
19+
super(InvalidConfFileTestCase, self).setUp()
1820
self.app = TestApp(app)
1921
self.config_file = tempfile.NamedTemporaryFile('w+')
2022
os.environ['PPP_CORE_CONFIG'] = self.config_file.name
23+
def tearDown(self):
24+
del os.environ['PPP_CORE_CONFIG']
25+
self.config_file.close()
26+
del self.config_file
27+
super(InvalidConfFileTestCase, self).tearDown()
28+
def testEmptyConfFile(self):
2129
obj = {'language': 'en', 'tree': {}}
2230
self.assertRaises(InvalidConfig, self.app.post_json,
2331
'/', obj, status='*')
24-
del os.environ['PPP_CORE_CONFIG']
25-
del self.config_file
2632

2733
def testModuleWithNoName(self):
28-
self.app = TestApp(app)
29-
self.config_file = tempfile.NamedTemporaryFile('w+')
3034
self.config_file.write('''{"debug": true, "modules": [{
3135
"url": "http://foo/bar/"}]}''')
3236
self.config_file.seek(0)
33-
os.environ['PPP_CORE_CONFIG'] = self.config_file.name
3437
obj = {'language': 'en', 'tree': {}}
3538
self.assertRaises(InvalidConfig, self.app.post_json,
3639
'/', obj, status='*')
37-
del os.environ['PPP_CORE_CONFIG']
38-
del self.config_file
3940

4041
def testModuleWithNoUrl(self):
41-
self.app = TestApp(app)
42-
self.config_file = tempfile.NamedTemporaryFile('w+')
4342
self.config_file.write('''{"debug": true, "modules": [{
4443
"name": "foo"}]}''')
4544
self.config_file.seek(0)
46-
os.environ['PPP_CORE_CONFIG'] = self.config_file.name
4745
obj = {'language': 'en', 'tree': {}}
4846
self.assertRaises(InvalidConfig, self.app.post_json,
4947
'/', obj, status='*')
50-
del os.environ['PPP_CORE_CONFIG']
51-
del self.config_file

0 commit comments

Comments
 (0)