Merge "Improve tacker.objects related file UT coverage"
This commit is contained in:
commit
6b4cf268a9
@ -19,10 +19,10 @@ from tacker.tests.unit.objects import fakes
|
||||
from tacker.tests import uuidsentinel
|
||||
|
||||
|
||||
class TestVnfd(SqlTestCase):
|
||||
class TestVnfLcmSubScriptions(SqlTestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestVnfd, self).setUp()
|
||||
super(TestVnfLcmSubScriptions, self).setUp()
|
||||
self.context = context.get_admin_context()
|
||||
self.vnf_package = self._create_vnf_package()
|
||||
self.vnf_package_vnfd = self._create_and_upload_vnf_package_vnfd()
|
||||
|
@ -60,3 +60,56 @@ class TestVnfPackageVnfd(SqlTestCase):
|
||||
self.context, vnf_pack_vnfd_obj.vnfd_id)
|
||||
self.assertEqual('test_provider', result.vnf_provider)
|
||||
self.assertEqual('test_version', result.vnf_software_version)
|
||||
|
||||
def test_get_vnf_package_vnfd(self):
|
||||
vnf_pack = vnf_package.VnfPackage(context=self.context,
|
||||
**fakes.vnf_package_data)
|
||||
vnf_pack.create()
|
||||
vnf_pack_vnfd_obj = vnf_package_vnfd.VnfPackageVnfd(
|
||||
context=self.context, **fakes.vnf_pack_vnfd_data(vnf_pack.id))
|
||||
vnf_pack_vnfd_obj.create()
|
||||
result = vnf_pack_vnfd_obj.get_vnf_package_vnfd(
|
||||
vnf_pack_vnfd_obj.id)
|
||||
# due to vnf_pack_vnfd_obj.get_vnf_package_vnfd() is not connect to
|
||||
# DB actually, it will return None as a result here
|
||||
actual_result = None
|
||||
self.assertEqual(result, actual_result)
|
||||
|
||||
def test_get_vnf_package_vnfd_by_vnfid(self):
|
||||
vnf_pack = vnf_package.VnfPackage(context=self.context,
|
||||
**fakes.vnf_package_data)
|
||||
vnf_pack.create()
|
||||
vnf_pack_vnfd_obj = vnf_package_vnfd.VnfPackageVnfd(
|
||||
context=self.context, **fakes.vnf_pack_vnfd_data(vnf_pack.id))
|
||||
vnf_pack_vnfd_obj.create()
|
||||
result = vnf_pack_vnfd_obj.get_vnf_package_vnfd_by_vnfid(
|
||||
self.context, vnf_pack_vnfd_obj.id)
|
||||
# due to vnf_pack_vnfd_obj.get_vnf_package_vnfd() is not connect to
|
||||
# DB actually, it will return None as a result here
|
||||
actual_result = None
|
||||
self.assertEqual(result, actual_result)
|
||||
|
||||
def test_get_by_vnfd_id(self):
|
||||
vnf_pack = vnf_package.VnfPackage(context=self.context,
|
||||
**fakes.vnf_package_data)
|
||||
vnf_pack.create()
|
||||
vnf_pack_vnfd_obj = vnf_package_vnfd.VnfPackageVnfd(
|
||||
context=self.context, **fakes.vnf_pack_vnfd_data(vnf_pack.id))
|
||||
vnf_pack_vnfd_obj.create()
|
||||
vnf_pack_vnfd_obj.get_by_vnfdId(
|
||||
self.context, vnf_pack_vnfd_obj.vnfd_id)
|
||||
|
||||
def test_get_by_package_id(self):
|
||||
vnf_pack = vnf_package.VnfPackage(context=self.context,
|
||||
**fakes.vnf_package_data)
|
||||
vnf_pack.create()
|
||||
vnf_pack_vnfd_obj = vnf_package_vnfd.VnfPackageVnfd(
|
||||
context=self.context, **fakes.vnf_pack_vnfd_data(vnf_pack.id))
|
||||
vnf_pack_vnfd_obj.create()
|
||||
result = vnf_pack_vnfd_obj.get_by_vnfdId(
|
||||
self.context, vnf_pack_vnfd_obj.package_uuid)
|
||||
vnf_pack_vnfd_obj.deleted = True
|
||||
# due to vnf_pack_vnfd_obj.get_vnf_package_vnfd() is not connect to
|
||||
# DB actually, it will return None as a result here
|
||||
actual_result = None
|
||||
self.assertEqual(result, actual_result)
|
||||
|
66
tacker/tests/unit/objects/test_vnfd.py
Normal file
66
tacker/tests/unit/objects/test_vnfd.py
Normal file
@ -0,0 +1,66 @@
|
||||
# Copyright (C) 2020 NTT DATA
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import datetime
|
||||
import ddt
|
||||
|
||||
from tacker import context
|
||||
from tacker.db import api as sqlalchemy_api
|
||||
from tacker.db.nfvo import nfvo_db
|
||||
from tacker import objects
|
||||
from tacker.tests.unit.db.base import SqlTestCase
|
||||
from tacker.tests.unit.objects import fakes
|
||||
from tacker.tests import uuidsentinel
|
||||
|
||||
get_engine = sqlalchemy_api.get_engine
|
||||
|
||||
|
||||
@ddt.ddt
|
||||
class TestVnfd(SqlTestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestVnfd, self).setUp()
|
||||
self.context = context.get_admin_context()
|
||||
self.vims = nfvo_db.Vim(**fakes.vim_data)
|
||||
self.engine = get_engine()
|
||||
self.conn = self.engine.connect()
|
||||
self.vim = nfvo_db.Vim()
|
||||
self.vnfd_data = {
|
||||
"id": uuidsentinel.id,
|
||||
"tenant_id": uuidsentinel.vnfd_id,
|
||||
"name": "name",
|
||||
"description": "description",
|
||||
"mgmt_driver": "mgmt_driver",
|
||||
"deleted_at": datetime.datetime.now()
|
||||
}
|
||||
self.vnfd_object = objects.vnfd.Vnfd(
|
||||
context=self.context, **self.vnfd_data)
|
||||
|
||||
def test_obj_from_db_obj(self):
|
||||
db_obj = {"key": "value"}
|
||||
result = self.vnfd_object.obj_from_db_obj(
|
||||
self.context, db_obj)
|
||||
self.assertIsInstance(result, objects.vnfd.Vnfd)
|
||||
|
||||
def test_destroy(self):
|
||||
self.vnfd_object.destroy(self.vnfd_object.id)
|
||||
|
||||
def test_delete(self):
|
||||
self.vnfd_object.delete(self.vnfd_object.id)
|
||||
|
||||
def test_check_vnfd_attribute(self):
|
||||
result = self.vnfd_object.check_vnfd(
|
||||
self.vnfd_object.id)
|
||||
self.assertEqual(result, "FALSE")
|
74
tacker/tests/unit/objects/test_vnfd_attribute.py
Normal file
74
tacker/tests/unit/objects/test_vnfd_attribute.py
Normal file
@ -0,0 +1,74 @@
|
||||
# Copyright (C) 2021 FUJITSU
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import ddt
|
||||
from unittest import mock
|
||||
|
||||
from tacker import context
|
||||
from tacker.db import api as sqlalchemy_api
|
||||
from tacker.db.nfvo import nfvo_db
|
||||
from tacker import objects
|
||||
from tacker.tests.unit.db.base import SqlTestCase
|
||||
from tacker.tests.unit.objects import fakes
|
||||
from tacker.tests import uuidsentinel
|
||||
|
||||
get_engine = sqlalchemy_api.get_engine
|
||||
|
||||
|
||||
@ddt.ddt
|
||||
class TestVnfdAttribute(SqlTestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestVnfdAttribute, self).setUp()
|
||||
self.context = context.get_admin_context()
|
||||
self.vims = nfvo_db.Vim(**fakes.vim_data)
|
||||
self.engine = get_engine()
|
||||
self.conn = self.engine.connect()
|
||||
self.vim = nfvo_db.Vim()
|
||||
self.vnfd_attribute_data = {
|
||||
"id": uuidsentinel.id,
|
||||
"vnfd_id": uuidsentinel.vnfd_id,
|
||||
"key": "key",
|
||||
"value": "value"
|
||||
}
|
||||
self.vnfd_attribute_object = objects.vnfd_attribute.VnfdAttribute(
|
||||
context=self.context, **self.vnfd_attribute_data)
|
||||
|
||||
@mock.patch.object(objects.vnfd_attribute, '_vnfd_attribute_create')
|
||||
def test_create(self, mock_vnfd_create):
|
||||
mock_vnfd_create.return_value = {
|
||||
"id": uuidsentinel.id,
|
||||
"vnfd_id": uuidsentinel.vnfd_id,
|
||||
"key": "key",
|
||||
"value": "value"
|
||||
}
|
||||
self.vnfd_attribute_object.create()
|
||||
|
||||
def test_obj_from_db_obj(self):
|
||||
db_obj = {"key": "value"}
|
||||
result = self.vnfd_attribute_object.obj_from_db_obj(
|
||||
self.context, db_obj)
|
||||
self.assertIsInstance(result, objects.vnfd_attribute.VnfdAttribute)
|
||||
|
||||
def test_destroy(self):
|
||||
self.vnfd_attribute_object.destroy(self.vnfd_attribute_object.id)
|
||||
|
||||
def test_delete(self):
|
||||
self.vnfd_attribute_object.delete(self.vnfd_attribute_object.id)
|
||||
|
||||
def test_check_vnfd_attribute(self):
|
||||
result = self.vnfd_attribute_object.check_vnfd_attribute(
|
||||
self.vnfd_attribute_object.id)
|
||||
self.assertEqual(result, "FALSE")
|
Loading…
Reference in New Issue
Block a user