Completed
Push — verbose-log ( bcf960 )
by Valentin
01:50
created

tests.InvalidConfFileTestCase.tearDown()   A

Complexity

Conditions 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2
Metric Value
cc 1
dl 0
loc 5
ccs 0
cts 5
cp 0
crap 2
rs 9.4285
1
"""Tests what happens if the config file is invalid."""
2
3 1
import os
4 1
import tempfile
5 1
from ppp_core import app
6
from webtest import TestApp
7
from unittest import TestCase
8
from ppp_libmodule.exceptions import InvalidConfig
9
10
11
class NoConfFileTestCase(TestCase):
12
    def testNoConfFile(self):
13
        self.app = TestApp(app)
14
        obj = {'id': '1', 'language': 'en', 'tree': {'type': 'missing'},
15
               'measures': {}, 'trace': []}
16
        self.assertRaises(InvalidConfig, self.app.post_json,
17
                          '/', obj, status='*')
18
19
class InvalidConfFileTestCase(TestCase):
20
    def setUp(self):
21
        super(InvalidConfFileTestCase, self).setUp()
22
        self.app = TestApp(app)
23
        self.config_file = tempfile.NamedTemporaryFile('w+')
24
        os.environ['PPP_CORE_CONFIG'] = self.config_file.name
25
    def tearDown(self):
26
        del os.environ['PPP_CORE_CONFIG']
27
        self.config_file.close()
28
        del self.config_file
29
        super(InvalidConfFileTestCase, self).tearDown()
30
    def testEmptyConfFile(self):
31
        obj = {'id': '1', 'language': 'en', 'tree': {'type': 'missing'},
32
               'measures': {}, 'trace': []}
33
        self.assertRaises(InvalidConfig, self.app.post_json,
34
                          '/', obj, status='*')
35
36
    def testModuleWithNoName(self):
37
        self.config_file.write('''{"debug": true, "modules": [{
38
            "url": "http://foo/bar/"}]}''')
39
        self.config_file.seek(0)
40
        obj = {'id': '1', 'language': 'en', 'tree': {'type': 'missing'},
41
               'measures': {}, 'trace': []}
42
        self.assertRaises(InvalidConfig, self.app.post_json,
43
                          '/', obj, status='*')
44
45
    def testModuleWithNoUrl(self):
46
        self.config_file.write('''{"debug": true, "modules": [{
47
            "name": "foo"}]}''')
48
        self.config_file.seek(0)
49
        obj = {'id': '1', 'language': 'en', 'tree': {'type': 'missing'},
50
               'measures': {}, 'trace': []}
51
        self.assertRaises(InvalidConfig, self.app.post_json,
52
                          '/', obj, status='*')
53