diff options
author | WuKong <rebirthmonkey@gmail.com> | 2017-12-15 21:43:14 +0100 |
---|---|---|
committer | WuKong <rebirthmonkey@gmail.com> | 2017-12-15 21:43:14 +0100 |
commit | f8008b22aab089a1d925da390e45b67d2f65d6cb (patch) | |
tree | 7476861cfc099dc6d92f1a7c0e53188e9e21ee79 /moonv4/moon_db/tests/unit_python/conftest.py | |
parent | 65c16b6c8e807dffef0a724ce203e1ffd5ca6cc7 (diff) |
moon_db python unit test init
Change-Id: Iba8deac5177c3499c89d6742874d3daf9fe3289a
Signed-off-by: WuKong <rebirthmonkey@gmail.com>
Diffstat (limited to 'moonv4/moon_db/tests/unit_python/conftest.py')
-rw-r--r-- | moonv4/moon_db/tests/unit_python/conftest.py | 66 |
1 files changed, 5 insertions, 61 deletions
diff --git a/moonv4/moon_db/tests/unit_python/conftest.py b/moonv4/moon_db/tests/unit_python/conftest.py index b9f38d7c..c2e5e579 100644 --- a/moonv4/moon_db/tests/unit_python/conftest.py +++ b/moonv4/moon_db/tests/unit_python/conftest.py @@ -4,6 +4,8 @@ import logging import os import pytest import requests_mock +import mock_components +import mock_keystone CONF = { "openstack": { @@ -120,34 +122,6 @@ CONF = { } } -COMPONENTS = ( - "logging", - "openstack/keystone", - "database", - "slave", - "components/manager", - "components/orchestrator", - "components/interface", -) - - -def get_b64_conf(component=None): - if component == "components": - return base64.b64encode( - json.dumps(CONF["components"]).encode('utf-8')+b"\n").decode('utf-8') - elif component in CONF: - return base64.b64encode( - json.dumps( - CONF[component]).encode('utf-8')+b"\n").decode('utf-8') - elif not component: - return base64.b64encode( - json.dumps(CONF).encode('utf-8')+b"\n").decode('utf-8') - elif "/" in component: - key1, _, key2 = component.partition("/") - return base64.b64encode( - json.dumps( - CONF[key1][key2]).encode('utf-8')+b"\n").decode('utf-8') - @pytest.fixture def db(): @@ -159,39 +133,9 @@ def set_consul_and_db(monkeypatch): """ Modify the response from Requests module """ with requests_mock.Mocker(real_http=True) as m: - for component in COMPONENTS: - m.register_uri( - 'GET', 'http://consul:8500/v1/kv/{}'.format(component), - json=[{'Key': component, 'Value': get_b64_conf(component)}] - ) - m.register_uri( - 'GET', 'http://consul:8500/v1/kv/components?recurse=true', - json=[ - {"Key": key, "Value": get_b64_conf(key)} for key in COMPONENTS - ], - ) - m.register_uri( - 'POST', 'http://keystone:5000/v3/auth/tokens', - headers={'X-Subject-Token': "111111111"} - ) - m.register_uri( - 'DELETE', 'http://keystone:5000/v3/auth/tokens', - headers={'X-Subject-Token': "111111111"} - ) - m.register_uri( - 'POST', 'http://keystone:5000/v3/users?name=testuser&domain_id=default', - json={"users": {}} - ) - m.register_uri( - 'GET', 'http://keystone:5000/v3/users?name=testuser&domain_id=default', - json={"users": {}} - ) - m.register_uri( - 'POST', 'http://keystone:5000/v3/users/', - json={"users": [{ - "id": "1111111111111" - }]} - ) + mock_components.register_components(m) + mock_keystone.register_keystone(m) + from moon_db.db_manager import init_engine, main engine = init_engine() main("upgrade", logging.getLogger("db_manager"), engine) |