aboutsummaryrefslogtreecommitdiffstats
path: root/moonv4/moon_utilities/tests/unit_python/test_cache.py
blob: ae4a4a77c1f6bacfd49108f003494bdef0588421 (plain)
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
import pytest
import mock_cache as data


def test_cache():
    from moon_utilities import cache
    c = cache.Cache()
    assert isinstance(c.authz_requests, dict)


def test_get_subject_success():
    from moon_utilities import cache
    cache_obj = cache.Cache()
    policy_id = 'policy_id_1'
    name = 'subject_name'
    subject_id = cache_obj.get_subject(policy_id, name)
    assert subject_id is not None


def test_get_subject_failure():
    from moon_utilities import cache
    cache_obj = cache.Cache()
    policy_id = 'policy_id_1'
    name = 'invalid name'
    with pytest.raises(Exception) as exception_info:
        cache_obj.get_subject(policy_id, name)
    assert str(exception_info.value) == '400: Subject Unknown'


def test_get_object_success():
    from moon_utilities import cache
    cache_obj = cache.Cache()
    policy_id = 'policy_id_1'
    name = 'object_name'
    object_id = cache_obj.get_object(policy_id, name)
    assert object_id is not None


def test_get_object_failure():
    from moon_utilities import cache
    cache_obj = cache.Cache()
    policy_id = 'policy_id_1'
    name = 'invalid name'
    with pytest.raises(Exception) as exception_info:
        cache_obj.get_object(policy_id, name)
    assert str(exception_info.value) == '400: Subject Unknown'


def test_get_action_success():
    from moon_utilities import cache
    cache_obj = cache.Cache()
    policy_id = 'policy_id_1'
    name = 'action_name'
    action_id = cache_obj.get_action(policy_id, name)
    assert action_id is not None


def test_get_action_failure():
    from moon_utilities import cache
    cache_obj = cache.Cache()
    policy_id = 'policy_id_1'
    name = 'invalid name'
    with pytest.raises(Exception) as exception_info:
        cache_obj.get_action(policy_id, name)
    assert str(exception_info.value) == '400: Subject Unknown'


def test_cache_manager():
    from moon_utilities import cache
    cache_obj = cache.Cache()
    assert cache_obj.pdp is not None
    assert cache_obj.meta_rules is not None
    assert len(cache_obj.meta_rules) == 2
    assert cache_obj.policies is not None
    assert len(cache_obj.policies) == 2
    assert cache_obj.models is not None


def test_get_subject_success():
    from moon_utilities import cache
    cache_obj = cache.Cache()
    policy_id = 'policy_id_1'
    name = 'subject_name'
    subject_id = cache_obj.get_subject(policy_id, name)
    assert subject_id is not None


def test_get_subject_failure():
    from moon_utilities import cache
    cache_obj = cache.Cache()
    policy_id = 'policy_id_1'
    name = 'invalid name'
    with pytest.raises(Exception) as exception_info:
        cache_obj.get_subject(policy_id, name)
    assert str(exception_info.value) == '400: Subject Unknown'


def test_get_object_success():
    from moon_utilities import cache
    cache_obj = cache.Cache()
    policy_id = 'policy_id_1'
    name = 'object_name'
    object_id = cache_obj.get_object(policy_id, name)
    assert object_id is not None


def test_get_object_failure():
    from moon_utilities import cache
    cache_obj = cache.Cache()
    policy_id = 'policy_id_1'
    name = 'invalid name'
    with pytest.raises(Exception) as exception_info:
        cache_obj.get_object(policy_id, name)
    assert str(exception_info.value) == '400: Subject Unknown'


def test_get_action_success():
    from moon_utilities import cache
    cache_obj = cache.Cache()
    policy_id = 'policy_id_1'
    name = 'action_name'
    action_id = cache_obj.get_action(policy_id, name)
    assert action_id is not None


def test_get_action_failure():
    from moon_utilities import cache
    cache_obj = cache.Cache()
    policy_id = 'policy_id_1'
    name = 'invalid name'
    with pytest.raises(Exception) as exception_info:
        cache_obj.get_action(policy_id, name)
    assert str(exception_info.value) == '400: Subject Unknown'