tests.HttpTest.testWorking()   A
last analyzed

Complexity

Conditions 2

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 2
Metric Value
cc 2
dl 0
loc 9
ccs 8
cts 8
cp 1
crap 2
rs 9.6667
1
2 1
import sqlite3
3
4 1
import tempfile
5 1
from ppp_logger import app
6 1
from ppp_libmodule.tests import PPPTestCase
7
8
9 1
class HttpTest(PPPTestCase(app)):
10 1
    config_var = 'PPP_LOGGER_CONFIG'
11 1
    def setUp(self):
12 1
        self.fd = tempfile.NamedTemporaryFile('w+')
13 1
        self.config = '{"database_url": "sqlite:///%s"}' % self.fd.name
14 1
        super(HttpTest, self).setUp()
15 1
    def tearDown(self):
16 1
        super(HttpTest, self).tearDown()
17 1
        self.fd.close()
18 1
    def testInvalidMethod(self):
19 1
        self.assertEqual(self.app.put('/', status='*').status_int, 405)
20 1
    def testNotJson(self):
21 1
        self.assertEqual(self.app.post('/', 'foobar', status='*').status_int, 400)
22 1
    def testWorking(self):
23 1
        tree = {'type': 'missing'}
24 1
        q = {'id': 'foo', 'question': '42?',
25
             'responses': [{'tree': tree, 'measures': {}, 'trace': []}]}
26 1
        self.assertStatusInt(q, 200)
27 1
        conn = sqlite3.connect(self.fd.name)
28 1
        with conn:
29 1
            r = conn.execute('SELECT request_id, ppp_request_id, request_question FROM requests;')
30 1
            self.assertEqual(r.fetchall(), [(1, 'foo', '42?')])
31 1
    def testMissingAttribute(self):
32 1
        q = {'question': '42?', 'responses': []}
33 1
        self.assertStatusInt(q, 400)
34 1
    def testBadAttributeType(self):
35 1
        q = {'id': 5, 'question': '42?', 'responses': []}
36 1
        self.assertStatusInt(q, 400)
37 1
    def testMissingResponseAttribute(self):
38 1
        q = {'id': 'foo', 'question': '42?', 'responses': [{}]}
39 1
        self.assertStatusInt(q, 400)
40 1
    def testSentenceResponse(self):
41 1
        tree = 'forty-two?'
42 1
        q = {'id': 'foo', 'question': '42?',
43
             'responses': [{'tree': tree, 'measures': {}, 'trace': []}]}
44 1
        self.assertStatusInt(q, 200)
45 1
    def testBadResponseAttributeType(self):
46 1
        tree = []
47 1
        q = {'id': 'foo', 'question': '42?',
48
             'responses': [{'tree': tree, 'measures': {}, 'trace': []}]}
49
        self.assertStatusInt(q, 400)
50