diff options
author | RHE <rebirthmonkey@gmail.com> | 2017-12-15 17:16:46 +0100 |
---|---|---|
committer | RHE <rebirthmonkey@gmail.com> | 2017-12-15 17:16:46 +0100 |
commit | 8fd36fdcd34eaff089313c750e5daf6f3801692c (patch) | |
tree | 3b50a7d33950f3ac66a5106c62c18d58c8b7bdcb /moonv4/moon_utilities/tests/unit_python | |
parent | 40144450de989888ab6f0957dd455a2a32d70da7 (diff) |
moon_utilities python unit test
Change-Id: I8969aa80788eaca850a773f4bc37f2eac8892f3e
Signed-off-by: RHE <rebirthmonkey@gmail.com>
Diffstat (limited to 'moonv4/moon_utilities/tests/unit_python')
-rw-r--r-- | moonv4/moon_utilities/tests/unit_python/conftest.py | 16 | ||||
-rw-r--r-- | moonv4/moon_utilities/tests/unit_python/mock_cache.py (renamed from moonv4/moon_utilities/tests/unit_python/data_mock.py) | 0 | ||||
-rw-r--r-- | moonv4/moon_utilities/tests/unit_python/mock_cache_manager.py (renamed from moonv4/moon_utilities/tests/unit_python/managers_mock.py) | 2 | ||||
-rw-r--r-- | moonv4/moon_utilities/tests/unit_python/requirements.txt | 2 | ||||
-rw-r--r-- | moonv4/moon_utilities/tests/unit_python/test_cache.py | 128 | ||||
-rw-r--r-- | moonv4/moon_utilities/tests/unit_python/test_cache_manager.py | 70 |
6 files changed, 132 insertions, 86 deletions
diff --git a/moonv4/moon_utilities/tests/unit_python/conftest.py b/moonv4/moon_utilities/tests/unit_python/conftest.py index 17ba7852..83350c4d 100644 --- a/moonv4/moon_utilities/tests/unit_python/conftest.py +++ b/moonv4/moon_utilities/tests/unit_python/conftest.py @@ -1,7 +1,7 @@ import base64 import json import logging -import managers_mock as pdp_manager +import mock_cache_manager as pdp_manager import pytest import requests_mock @@ -190,20 +190,6 @@ def no_requests(monkeypatch): ) pdp_manager.mock_managers(m) print("End registering URI") - # from moon_db.db_manager import init_engine, run - # engine = init_engine() - # print("engine={}".format(engine)) - # run("upgrade", logging.getLogger("db_manager"), engine) - # print("End populating the DB.") yield m -# @pytest.fixture(autouse=True, scope="session") -# def manage_database(): -# from moon_db.db_manager import init_engine, run -# engine = init_engine() -# run("upgrade", logging.getLogger("db_manager"), engine) -# yield -# print("Will close the DB") - - diff --git a/moonv4/moon_utilities/tests/unit_python/data_mock.py b/moonv4/moon_utilities/tests/unit_python/mock_cache.py index 0da5f024..0da5f024 100644 --- a/moonv4/moon_utilities/tests/unit_python/data_mock.py +++ b/moonv4/moon_utilities/tests/unit_python/mock_cache.py diff --git a/moonv4/moon_utilities/tests/unit_python/managers_mock.py b/moonv4/moon_utilities/tests/unit_python/mock_cache_manager.py index 2effec4e..372e78f0 100644 --- a/moonv4/moon_utilities/tests/unit_python/managers_mock.py +++ b/moonv4/moon_utilities/tests/unit_python/mock_cache_manager.py @@ -1,4 +1,4 @@ -import data_mock as data +import mock_cache as data def mock_managers(m1): diff --git a/moonv4/moon_utilities/tests/unit_python/requirements.txt b/moonv4/moon_utilities/tests/unit_python/requirements.txt new file mode 100644 index 00000000..3c1ad607 --- /dev/null +++ b/moonv4/moon_utilities/tests/unit_python/requirements.txt @@ -0,0 +1,2 @@ +pytest +requests_mock
\ No newline at end of file diff --git a/moonv4/moon_utilities/tests/unit_python/test_cache.py b/moonv4/moon_utilities/tests/unit_python/test_cache.py index 15c5f22a..ae4a4a77 100644 --- a/moonv4/moon_utilities/tests/unit_python/test_cache.py +++ b/moonv4/moon_utilities/tests/unit_python/test_cache.py @@ -1,5 +1,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' diff --git a/moonv4/moon_utilities/tests/unit_python/test_cache_manager.py b/moonv4/moon_utilities/tests/unit_python/test_cache_manager.py deleted file mode 100644 index fb2930aa..00000000 --- a/moonv4/moon_utilities/tests/unit_python/test_cache_manager.py +++ /dev/null @@ -1,70 +0,0 @@ -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' |