Passed
Push — master ( 0bc911...dd3d6b )
by Mingyu
52s
created

tests.app.context.test_context_property   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 24
dl 0
loc 54
rs 10
c 0
b 0
f 0
wmc 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A TestContextProperty.test_secret_key() 0 9 2
A TestContextProperty.test_request_payload_with_set() 0 10 2
A TestContextProperty.test_request_payload_without_set() 0 8 2
A TestContextProperty.test_request_payload_raise_runtime_error_on_outside_context() 0 8 2
A TestContextProperty.test_secret_key_raise_runtime_error_on_outside_context() 0 7 2
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(
14
                LocalLevelConfig.SECRET_KEY,
15
                context_property.secret_key
16
            )
17
18
    def test_secret_key_raise_runtime_error_on_outside_context(self):
19
        """
20
        request context 밖에서 secret key 접근 시 RuntimeError 발생
21
        """
22
23
        with self.assertRaises(RuntimeError):
24
            _ = context_property.secret_key
25
26
    def test_request_payload_without_set(self):
27
        """
28
        request context 내에서 임의의 값이 set되지 않은 request payload 접근
29
        -> None으로 평가되어야 함
30
        """
31
32
        with self.app.test_request_context():
33
            self.assertIsNone(context_property.request_payload)
34
35
    def test_request_payload_with_set(self):
36
        """
37
        request context 내에서 임의의 값이 set된 request payload 접근
38
        -> set된 값이 반환되어야 함
39
        """
40
41
        with self.app.test_request_context():
42
            context_property.request_payload = 0
43
44
            self.assertEqual(0, context_property.request_payload)
45
46
    def test_request_payload_raise_runtime_error_on_outside_context(self):
47
        """
48
        request context 밖에서 request payload 접근 시 RuntimeError 발생
49
        """
50
51
        with self.assertRaises(RuntimeError):
52
            context_property.request_payload = 0
53
            _ = context_property.request_payload
54