tests.NoConfFileTestCase   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 7
Duplicated Lines 0 %

Test Coverage

Coverage 100%
Metric Value
dl 0
loc 7
ccs 5
cts 5
cp 1
rs 10
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A testNoConfFile() 0 6 1
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 1
from webtest import TestApp
7 1
from unittest import TestCase
8 1
from ppp_libmodule.exceptions import InvalidConfig
9
10
11 1
class NoConfFileTestCase(TestCase):
12 1
    def testNoConfFile(self):
13 1
        self.app = TestApp(app)
14 1
        obj = {'id': '1', 'language': 'en', 'tree': {'type': 'missing'},
15
               'measures': {}, 'trace': []}
16 1
        self.assertRaises(InvalidConfig, self.app.post_json,
17
                          '/', obj, status='*')
18
19 1
class InvalidConfFileTestCase(TestCase):
20 1
    def setUp(self):
21 1
        super(InvalidConfFileTestCase, self).setUp()
22 1
        self.app = TestApp(app)
23 1
        self.config_file = tempfile.NamedTemporaryFile('w+')
24 1
        os.environ['PPP_CORE_CONFIG'] = self.config_file.name
25 1
    def tearDown(self):
26 1
        del os.environ['PPP_CORE_CONFIG']
27 1
        self.config_file.close()
28 1
        del self.config_file
29 1
        super(InvalidConfFileTestCase, self).tearDown()
30 1
    def testEmptyConfFile(self):
31 1
        obj = {'id': '1', 'language': 'en', 'tree': {'type': 'missing'},
32
               'measures': {}, 'trace': []}
33 1
        self.assertRaises(InvalidConfig, self.app.post_json,
34
                          '/', obj, status='*')
35
36 1
    def testModuleWithNoName(self):
37 1
        self.config_file.write('''{"debug": true, "modules": [{
38
            "url": "http://foo/bar/"}]}''')
39 1
        self.config_file.seek(0)
40 1
        obj = {'id': '1', 'language': 'en', 'tree': {'type': 'missing'},
41
               'measures': {}, 'trace': []}
42 1
        self.assertRaises(InvalidConfig, self.app.post_json,
43
                          '/', obj, status='*')
44
45 1
    def testModuleWithNoUrl(self):
46 1
        self.config_file.write('''{"debug": true, "modules": [{
47
            "name": "foo"}]}''')
48 1
        self.config_file.seek(0)
49 1
        obj = {'id': '1', 'language': 'en', 'tree': {'type': 'missing'},
50
               'measures': {}, 'trace': []}
51 1
        self.assertRaises(InvalidConfig, self.app.post_json,
52
                          '/', obj, status='*')
53