-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_exceptions.py
39 lines (28 loc) · 1.02 KB
/
test_exceptions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
"""
Test the exceptions.
"""
import json
from unittest import TestCase
from pyfreelan.server.application import APP
from pyfreelan.server.application.exceptions import HTTPException
class ExceptionTests(TestCase):
def setUp(self):
self.app = APP
def test_http_exception_translates_to_response(self):
message = 'Some error'
status_code = 404
headers = {'a': '1', 'b': '2'}
ex = HTTPException(
message=message,
status_code=status_code,
headers=headers,
)
self.assertEqual(message, ex.message)
self.assertEqual(status_code, ex.status_code)
self.assertEqual(headers, ex.headers)
with self.app.test_request_context():
response = ex.to_response()
self.assertEqual({'message': message}, json.loads(response.data))
self.assertEqual(status_code, response.status_code)
for key, value in headers.iteritems():
self.assertEqual(value, response.headers.get(key))