diff options
Diffstat (limited to 'moonv4/moon_db/tests')
-rw-r--r-- | moonv4/moon_db/tests/configure_db.sh | 9 | ||||
-rw-r--r-- | moonv4/moon_db/tests/test_intraextension.py | 44 | ||||
-rw-r--r-- | moonv4/moon_db/tests/test_tenant.py | 86 |
3 files changed, 139 insertions, 0 deletions
diff --git a/moonv4/moon_db/tests/configure_db.sh b/moonv4/moon_db/tests/configure_db.sh new file mode 100644 index 00000000..bdc259fe --- /dev/null +++ b/moonv4/moon_db/tests/configure_db.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env bash + +apt-get install mysql-server python-mysqldb python-pymysql + +mysql -uroot -ppassword <<EOF +CREATE DATABASE moon DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci; +GRANT ALL ON moon.* TO 'moonuser'@'%' IDENTIFIED BY 'password'; +GRANT ALL ON moon.* TO 'moonuser'@'localhost' IDENTIFIED BY 'password'; +EOF diff --git a/moonv4/moon_db/tests/test_intraextension.py b/moonv4/moon_db/tests/test_intraextension.py new file mode 100644 index 00000000..a2267214 --- /dev/null +++ b/moonv4/moon_db/tests/test_intraextension.py @@ -0,0 +1,44 @@ +# Copyright 2015 Open Platform for NFV Project, Inc. and its contributors +# This software is distributed under the terms and conditions of the 'Apache-2.0' +# license which can be found in the file 'LICENSE' in this package distribution +# or at 'http://www.apache.org/licenses/LICENSE-2.0'. + + +import moon_db +import uuid + +Connector = moon_db.Driver("sql", "mysql+pymysql://moonuser:password@localhost/moon") +Connector.driver.init_db() + + +def create_intra_extension(policy_model="policy_authz"): + ie = dict() + ie['id'] = uuid.uuid4().hex + ie["name"] = "test IE " + uuid.uuid4().hex + ie["policymodel"] = "policy_authz" + ie["description"] = "a simple description." + ie["model"] = policy_model + genre = "admin" + if "authz" in policy_model: + genre = "authz" + ie["genre"] = genre + # ref = self.admin_api.load_intra_extension_dict(self.root_api.root_admin_id, + # intra_extension_dict=ie) + # self.admin_api.populate_default_data(ref) + return ie + + +def test_get_intraextension(): + t = Connector.driver.get_intra_extensions_dict() + assert type(t) == dict + + +def test_set_intra_extension(): + number_of_ie = len(Connector.driver.get_intra_extensions_dict()) + ie = create_intra_extension() + data = Connector.driver.set_intra_extension_dict(ie['id'], ie) + assert type(data) == dict + assert len(Connector.driver.get_intra_extensions_dict()) == number_of_ie+1 + + +# TODO (dthom): all tests can be got from keystone-moon diff --git a/moonv4/moon_db/tests/test_tenant.py b/moonv4/moon_db/tests/test_tenant.py new file mode 100644 index 00000000..7e6cfa82 --- /dev/null +++ b/moonv4/moon_db/tests/test_tenant.py @@ -0,0 +1,86 @@ +# Copyright 2015 Open Platform for NFV Project, Inc. and its contributors +# This software is distributed under the terms and conditions of the 'Apache-2.0' +# license which can be found in the file 'LICENSE' in this package distribution +# or at 'http://www.apache.org/licenses/LICENSE-2.0'. + +import moon_db +import uuid + +Connector = moon_db.Driver("sql", "mysql+pymysql://moonuser:password@localhost/moon") +Connector.driver.init_db() + + +def test_get_tenants(): + t = Connector.driver.get_tenants_dict() + print(t) + assert type(t) == dict + + +def test_add_tenant(): + new_tenant = { + "id": uuid.uuid4().hex, + "name": "demo", + "description": uuid.uuid4().hex, + "intra_authz_extension_id": "", + "intra_admin_extension_id": "", + } + data = Connector.driver.add_tenant_dict(tenant_id=new_tenant['id'], + tenant_dict=new_tenant) + data_id = list(data.keys())[0] + assert new_tenant["id"] == data_id + assert new_tenant["name"] == data[data_id]["name"] + assert new_tenant["intra_authz_extension_id"] == data[data_id]["intra_authz_extension_id"] + assert new_tenant["intra_admin_extension_id"] == data[data_id]["intra_admin_extension_id"] + data = Connector.driver.get_tenants_dict() + assert data != {} + + +def test_del_tenant(): + new_tenant = { + "id": uuid.uuid4().hex, + "name": "demo", + "description": uuid.uuid4().hex, + "intra_authz_extension_id": "", + "intra_admin_extension_id": "", + } + data = Connector.driver.get_tenants_dict() + number_of_tenant = len(data.keys()) + data = Connector.driver.add_tenant_dict(tenant_id=new_tenant['id'], + tenant_dict=new_tenant) + data_id = list(data.keys())[0] + assert new_tenant["name"] == data[data_id]["name"] + assert new_tenant["intra_authz_extension_id"] == data[data_id]["intra_authz_extension_id"] + assert new_tenant["intra_admin_extension_id"] == data[data_id]["intra_admin_extension_id"] + data = Connector.driver.get_tenants_dict() + assert len(data.keys()) == number_of_tenant+1 + Connector.driver.del_tenant(data_id) + data = Connector.driver.get_tenants_dict() + assert len(data.keys()) == number_of_tenant + + +def test_set_tenant(): + new_tenant = { + "id": uuid.uuid4().hex, + "name": "demo", + "description": uuid.uuid4().hex, + "intra_authz_extension_id": "123456", + "intra_admin_extension_id": "0987654", + } + data = Connector.driver.get_tenants_dict() + number_of_tenant = len(data.keys()) + data = Connector.driver.add_tenant_dict(tenant_id=new_tenant['id'], + tenant_dict=new_tenant) + data_id = list(data.keys())[0] + assert new_tenant["name"] == data[data_id]["name"] + assert new_tenant["intra_authz_extension_id"] == data[data_id]["intra_authz_extension_id"] + assert new_tenant["intra_admin_extension_id"] == data[data_id]["intra_admin_extension_id"] + data = Connector.driver.get_tenants_dict() + assert len(data.keys()) == number_of_tenant+1 + + new_tenant["name"] = "demo2" + data = Connector.driver.set_tenant_dict(tenant_id=data_id, tenant_dict=new_tenant) + data_id = list(data.keys())[0] + assert new_tenant["name"] == data[data_id]["name"] + assert new_tenant["intra_authz_extension_id"] == data[data_id]["intra_authz_extension_id"] + assert new_tenant["intra_admin_extension_id"] == data[data_id]["intra_admin_extension_id"] + |