1
|
|
|
from app.context import context_property |
2
|
|
|
from config.app_config import LocalLevelConfig |
3
|
|
|
from tests import BaseTestCase |
4
|
|
|
|
5
|
|
|
|
6
|
|
|
class TestContextProperty(BaseTestCase): |
7
|
|
|
def test_secret_key(self): |
8
|
|
|
""" |
9
|
|
|
request context 내에서 secret key 접근 |
10
|
|
|
""" |
11
|
|
|
|
12
|
|
|
with self.app.test_request_context(): |
13
|
|
|
self.assertEqual(LocalLevelConfig.SECRET_KEY, context_property.secret_key) |
14
|
|
|
|
15
|
|
|
def test_secret_key_raise_runtime_error_on_outside_context(self): |
16
|
|
|
""" |
17
|
|
|
request context 밖에서 secret key 접근 시 RuntimeError 발생 |
18
|
|
|
""" |
19
|
|
|
|
20
|
|
|
with self.assertRaises(RuntimeError): |
21
|
|
|
_ = context_property.secret_key |
22
|
|
|
|
23
|
|
|
def test_request_payload_without_set(self): |
24
|
|
|
""" |
25
|
|
|
request context 내에서 임의의 값이 set되지 않은 request payload 접근 |
26
|
|
|
-> None으로 평가되어야 함 |
27
|
|
|
""" |
28
|
|
|
|
29
|
|
|
with self.app.test_request_context(): |
30
|
|
|
self.assertIsNone(context_property.request_path_params) |
31
|
|
|
self.assertIsNone(context_property.request_query_params) |
32
|
|
|
self.assertIsNone(context_property.request_json) |
33
|
|
|
|
34
|
|
|
def test_request_payload_with_set(self): |
35
|
|
|
""" |
36
|
|
|
request context 내에서 임의의 값이 set된 request payload 접근 |
37
|
|
|
-> set된 값이 반환되어야 함 |
38
|
|
|
""" |
39
|
|
|
|
40
|
|
|
with self.app.test_request_context(): |
41
|
|
|
context_property.request_path_params = 0 |
42
|
|
|
context_property.request_query_params = 0 |
43
|
|
|
context_property.request_json = 0 |
44
|
|
|
|
45
|
|
|
self.assertEqual(0, context_property.request_path_params) |
46
|
|
|
self.assertEqual(0, context_property.request_query_params) |
47
|
|
|
self.assertEqual(0, context_property.request_json) |
48
|
|
|
|
49
|
|
|
def test_request_payload_raise_runtime_error_on_outside_context(self): |
50
|
|
|
""" |
51
|
|
|
request context 밖에서 request payload 접근 시 RuntimeError 발생 |
52
|
|
|
""" |
53
|
|
|
|
54
|
|
|
with self.assertRaises(RuntimeError): |
55
|
|
|
context_property.request_json = 0 |
56
|
|
|
_ = context_property.request_json |
57
|
|
|
|