diff options
author | ahmed.helmy <ahmad.helmy@orange.com> | 2017-12-14 16:52:00 +0200 |
---|---|---|
committer | ahmed.helmy <ahmad.helmy@orange.com> | 2017-12-14 16:52:00 +0200 |
commit | e2b6487fcd0d4e72adfa904030151a40a41a8c14 (patch) | |
tree | 290a7d14baa36c87e79ff6942256b32e1b489c41 /moonv4/moon_utilities/tests/unit_python/test_cache_manager.py | |
parent | a9b97c466df39ec3db1e01d8fe68a90ec220c88f (diff) |
add unit tests for cache module
Change-Id: I2dcfa65867ddfe2a505c2432a52fa8869ae5589a
Signed-off-by: ahmed.helmy <ahmad.helmy@orange.com>
Diffstat (limited to 'moonv4/moon_utilities/tests/unit_python/test_cache_manager.py')
-rw-r--r-- | moonv4/moon_utilities/tests/unit_python/test_cache_manager.py | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/moonv4/moon_utilities/tests/unit_python/test_cache_manager.py b/moonv4/moon_utilities/tests/unit_python/test_cache_manager.py new file mode 100644 index 00000000..fb2930aa --- /dev/null +++ b/moonv4/moon_utilities/tests/unit_python/test_cache_manager.py @@ -0,0 +1,70 @@ +import pytest +import data_mock as data + + +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' |