1
|
|
|
"""Test HTTP capabilities of the core's frontend.""" |
2
|
|
|
|
3
|
1 |
|
from ppp_libmodule.tests import PPPTestCase |
4
|
1 |
|
from ppp_libmodule.http import HttpRequestHandler |
5
|
|
|
|
6
|
1 |
|
r = None |
7
|
|
|
|
8
|
1 |
|
class RequestHandler: |
9
|
1 |
|
def __init__(self, request): |
10
|
|
|
global r |
11
|
1 |
|
r = request |
12
|
|
|
|
13
|
1 |
|
def answer(self): |
14
|
1 |
|
return [] |
15
|
|
|
|
16
|
1 |
|
def app(environ, start_response): |
17
|
|
|
"""Function called by the WSGI server.""" |
18
|
1 |
|
r = HttpRequestHandler(environ, start_response, RequestHandler).dispatch() |
19
|
1 |
|
return r |
20
|
|
|
|
21
|
1 |
|
class HttpTest(PPPTestCase(app)): |
22
|
1 |
|
def testPostOnly(self): |
23
|
1 |
|
self.assertEqual(self.app.get('/', status='*').status_int, 405) |
24
|
1 |
|
self.assertEqual(self.app.put('/', status='*').status_int, 405) |
25
|
1 |
|
def testNotRoot(self): |
26
|
1 |
|
self.assertEqual(self.app.post_json('/foo', {}, status='*').status_int, 400) |
27
|
1 |
|
def testNotJson(self): |
28
|
1 |
|
self.assertEqual(self.app.post('/', 'foobar', status='*').status_int, 400) |
29
|
1 |
|
def testWorking(self): |
30
|
|
|
global r |
31
|
1 |
|
q = {'id': '1', 'language': 'en', 'tree': {'type': 'triple', |
32
|
|
|
'subject': {'type': 'resource', 'value': 'foo'}, |
33
|
|
|
'predicate': {'type': 'resource', 'value': 'bar'}, |
34
|
|
|
'object': {'type': 'resource', 'value': 'baz'}}, |
35
|
|
|
'measures': {}, 'trace': []} |
36
|
1 |
|
r = None |
37
|
1 |
|
self.assertResponse(q, []) |
38
|
1 |
|
self.assertEqual(r.as_dict(), q) |
39
|
1 |
|
def testNoTree(self): |
40
|
1 |
|
q = {'language': 'en'} |
41
|
|
|
self.assertStatusInt(q, 400) |
42
|
|
|
|