moon_utilities python unit test 77/49077/1
authorRHE <rebirthmonkey@gmail.com>
Fri, 15 Dec 2017 16:16:46 +0000 (17:16 +0100)
committerRHE <rebirthmonkey@gmail.com>
Fri, 15 Dec 2017 16:16:46 +0000 (17:16 +0100)
Change-Id: I8969aa80788eaca850a773f4bc37f2eac8892f3e
Signed-off-by: RHE <rebirthmonkey@gmail.com>
moonv4/moon_utilities/README.md
moonv4/moon_utilities/requirements.txt
moonv4/moon_utilities/setup.py
moonv4/moon_utilities/tests/unit_python/conftest.py
moonv4/moon_utilities/tests/unit_python/mock_cache.py [moved from moonv4/moon_utilities/tests/unit_python/data_mock.py with 100% similarity]
moonv4/moon_utilities/tests/unit_python/mock_cache_manager.py [moved from moonv4/moon_utilities/tests/unit_python/managers_mock.py with 99% similarity]
moonv4/moon_utilities/tests/unit_python/requirements.txt [new file with mode: 0644]
moonv4/moon_utilities/tests/unit_python/test_cache.py
moonv4/moon_utilities/tests/unit_python/test_cache_manager.py [deleted file]

index f5fa43c..5003b6c 100644 (file)
@@ -1,6 +1,6 @@
 # Moon Python Utilities Package
-This package contains the core module for the Moon project
-It is designed to provide authorization features to all OpenStack components.
+This package contains the core module for the Moon project.
+It is designed to provide authorization feature to all OpenStack components.
 
 For any other information, refer to the parent project:
 
@@ -10,14 +10,24 @@ moon_utilities is a common Python lib for other Moon Python packages
 
 ## Build
 ### Build Python Package
-- `cd moon_utilities`
-- `python3 setup.py sdist bdist_wheel`
+```Bash
+cd moon_utilities
+python3 setup.py sdist bdist_wheel
+```
 
 ### Push Python Package to PIP
+```bash
+cd moon_utilities
+gpg --detach-sign -u "${GPG_ID}" -a dist/moon_db-X.Y.Z-py3-none-any.whl
+gpg --detach-sign -u "${GPG_ID}" -a dist/moon_db-X.Y.Z.tar.gz
+twine upload dist/moon_db-X.Y.Z-py3-none-any.whl dist/moon_db-X.Y.Z-py3-none-any.whl.asc
+twine upload dist/moon_db-X.Y.Z.tar.gz dist/moon_db-X.Y.Z.tar.gz.asc
+```
 
 ## Test
 ### Python Unit Test
-- launch Docker for Python unit tests
-    - `cd moon_utilities`
-    - `docker run --rm --volume $(pwd):/data wukongsun/moon_python_unit_test:latest`
-
+launch Docker for Python unit tests
+```bash
+cd moon_utilities
+docker run --rm --volume $(pwd):/data wukongsun/moon_python_unit_test:latest
+```
index e30f5d2..5b80e5f 100644 (file)
@@ -1,8 +1,3 @@
-kombu !=4.0.1,!=4.0.0
-oslo.messaging
-oslo.config
-oslo.log
-vine
 werkzeug
 flask
 requests
\ No newline at end of file
index cd7a257..21e1141 100644 (file)
@@ -17,11 +17,11 @@ setup(
 
     packages=find_packages(),
 
-    author="Thomas Duval",
+    author='Thomas Duval',
 
-    author_email="thomas.duval@orange.com",
+    author_email='thomas.duval@orange.com',
 
-    description="Some utilities for all the Moon components",
+    description='Some utilities for all the Moon components',
 
     long_description=open('README.md').read(),
 
@@ -32,12 +32,11 @@ setup(
     url='https://git.opnfv.org/cgit/moon',
 
     classifiers=[
-        "Programming Language :: Python",
-        "Development Status :: 1 - Planning",
-        "License :: OSI Approved",
-        "Natural Language :: French",
-        "Operating System :: OS Independent",
-        "Programming Language :: Python :: 3",
+        'Programming Language :: Python :: 3',
+        'Development Status :: 1 - Planning',
+        'License :: OSI Approved',
+        'Natural Language :: English',
+        'Operating System :: OS Independent',
     ],
 
 )
index 17ba785..83350c4 100644 (file)
@@ -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/requirements.txt b/moonv4/moon_utilities/tests/unit_python/requirements.txt
new file mode 100644 (file)
index 0000000..3c1ad60
--- /dev/null
@@ -0,0 +1,2 @@
+pytest
+requests_mock
\ No newline at end of file
index 15c5f22..ae4a4a7 100644 (file)
@@ -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 (file)
index fb2930a..0000000
+++ /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'