Completed
Pull Request — master (#20)
by Valentin
02:37 queued 01:31
created

tests.InvalidConfFileTestCase   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Test Coverage

Coverage 0%
Metric Value
dl 0
loc 34
ccs 0
cts 24
cp 0
rs 10
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A testModuleWithNoUrl() 0 8 1
A setUp() 0 5 1
A testEmptyConfFile() 0 5 1
A tearDown() 0 5 1
A testModuleWithNoName() 0 8 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
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