Skip to content

Commit

Permalink
Change test case
Browse files Browse the repository at this point in the history
Signed-off-by: Jongmin Kim <[email protected]>
  • Loading branch information
whdalsrnt committed Jun 9, 2021
1 parent e899bff commit fb15827
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 50 deletions.
22 changes: 2 additions & 20 deletions test/service/test_plugin_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from spaceone.core.unittest.runner import RichTestRunner
from spaceone.core import config
from spaceone.core import utils
from spaceone.core.model.mongo_model import MongoModel
from spaceone.core.transaction import Transaction
from spaceone.repository.error.plugin import *
from spaceone.repository.service.plugin_service import PluginService
Expand All @@ -25,6 +24,8 @@ class TestPluginService(unittest.TestCase):
@classmethod
def setUpClass(cls):
config.init_conf(package='spaceone.repository')
config.set_service_config()
config.set_global(MOCK_MODE=True)
connect('test', host='mongomock://localhost')

cls.repository_vo = RepositoryFactory(repository_type='local')
Expand All @@ -41,14 +42,12 @@ def tearDownClass(cls) -> None:
super().tearDownClass()
disconnect()

@patch.object(MongoModel, 'connect', return_value=None)
def tearDown(self, *args) -> None:
print()
print('(tearDown) ==> Delete all plugins')
plugin_vos = Plugin.objects.filter()
plugin_vos.delete()

@patch.object(MongoModel, 'connect', return_value=None)
@patch.object(LocalPluginManager, '_get_registry_url', return_value='registry.hub.docker.com')
def test_register_plugin(self, *args):
params = {
Expand Down Expand Up @@ -107,7 +106,6 @@ def test_register_plugin(self, *args):
self.assertEqual(params['tags'], utils.tags_to_dict(plugin_vo.tags))
self.assertEqual(params['domain_id'], plugin_vo.domain_id)

@patch.object(MongoModel, 'connect', return_value=None)
def test_register_plugin_invalid_template(self, *args):
params = {
'name': 'google_oauth2',
Expand All @@ -130,7 +128,6 @@ def test_register_plugin_invalid_template(self, *args):
with self.assertRaises(ERROR_INVALID_TEMPLATE_SCHEMA):
plugin_svc.register(params)

@patch.object(MongoModel, 'connect', return_value=None)
def test_register_plugin_invalid_capability(self, *args):
params = {
'name': 'google_oauth2',
Expand All @@ -148,7 +145,6 @@ def test_register_plugin_invalid_capability(self, *args):
# with self.assertRaises(ERROR_INVALID_PARAMETER):
# plugin_svc.register(params)

@patch.object(MongoModel, 'connect', return_value=None)
def test_register_plugin_invalid_service_type(self, *args):
params = {
'name': 'google_oauth2',
Expand All @@ -164,7 +160,6 @@ def test_register_plugin_invalid_service_type(self, *args):
# plugin_svc.register(params)

@patch.object(IdentityManager, 'get_project', return_value=None)
@patch.object(MongoModel, 'connect', return_value=None)
@patch.object(LocalPluginManager, '_get_registry_url', return_value='registry.hub.docker.com')
def test_register_plugin_with_project(self, *args):
params = {
Expand All @@ -185,7 +180,6 @@ def test_register_plugin_with_project(self, *args):
self.assertIsInstance(plugin_vo, Plugin)
self.assertEqual(plugin_vo.project_id, params['project_id'])

@patch.object(MongoModel, 'connect', return_value=None)
def test_update_plugin(self, *args):
new_plugin_vo = PluginFactory(domain_id=self.domain_id)
params = {
Expand Down Expand Up @@ -234,7 +228,6 @@ def test_update_plugin(self, *args):
self.assertEqual(params.get('labels', []), plugin_vo.labels)
self.assertEqual(params['tags'], utils.tags_to_dict(plugin_vo.tags))

@patch.object(MongoModel, 'connect', return_value=None)
def test_delete_plugin(self, *args):
new_plugin_vo = PluginFactory(domain_id=self.domain_id)
params = {
Expand All @@ -248,7 +241,6 @@ def test_delete_plugin(self, *args):

self.assertIsNone(result)

@patch.object(MongoModel, 'connect', return_value=None)
def test_enable_plugin(self, *args):
new_plugin_vo = PluginFactory(domain_id=self.domain_id, state='DISABLED')
params = {
Expand All @@ -267,7 +259,6 @@ def test_enable_plugin(self, *args):
self.assertEqual(new_plugin_vo.plugin_id, plugin_vo.plugin_id)
self.assertEqual('ENABLED', plugin_vo.state)

@patch.object(MongoModel, 'connect', return_value=None)
def test_disable_plugin(self, *args):
new_plugin_vo = PluginFactory(domain_id=self.domain_id, state='ENABLED')
params = {
Expand All @@ -287,7 +278,6 @@ def test_disable_plugin(self, *args):
self.assertEqual('DISABLED', plugin_vo.state)

@patch.object(RegistryConnector, 'get_tags', return_value=['1.0', '2.0'])
@patch.object(MongoModel, 'connect', return_value=None)
def test_get_versions(self, *args):
new_plugin_vo = PluginFactory(domain_id=self.domain_id)
params = {
Expand All @@ -306,7 +296,6 @@ def test_get_versions(self, *args):
self.assertIsInstance(version_list, list)

@patch.object(RegistryConnector, 'get_tags', return_value=['1.0', '2.0'])
@patch.object(MongoModel, 'connect', return_value=None)
def test_get_versions_from_multi_repositories(self, *args):
new_repository_vo = RepositoryFactory(repository_type='remote')
new_plugin_vo = PluginFactory(domain_id=self.domain_id, repository=new_repository_vo)
Expand All @@ -324,7 +313,6 @@ def test_get_versions_from_multi_repositories(self, *args):

self.assertIsInstance(version_list, list)

@patch.object(MongoModel, 'connect', return_value=None)
def test_get_plugin(self, *args):
new_plugin_vo = PluginFactory(domain_id=self.domain_id)
params = {
Expand All @@ -342,7 +330,6 @@ def test_get_plugin(self, *args):

self.assertIsInstance(plugin_vo, Plugin)

@patch.object(MongoModel, 'connect', return_value=None)
def test_get_plugin_from_multi_repositories(self, *args):
new_repository_vo = RepositoryFactory(repository_type='remote')
new_plugin_vo = PluginFactory(domain_id=self.domain_id, repository=new_repository_vo)
Expand All @@ -360,7 +347,6 @@ def test_get_plugin_from_multi_repositories(self, *args):

self.assertIsInstance(plugin_vo, Plugin)

@patch.object(MongoModel, 'connect', return_value=None)
def test_list_plugins_by_plugin_id(self, *args):
plugin_vos = PluginFactory.build_batch(10, repository=self.repository_vo,
domain_id=self.domain_id)
Expand All @@ -380,7 +366,6 @@ def test_list_plugins_by_plugin_id(self, *args):
self.assertIsInstance(plugins_vos[0], Plugin)
self.assertEqual(total_count, 1)

@patch.object(MongoModel, 'connect', return_value=None)
def test_list_plugins_by_name(self, *args):
plugin_vos = PluginFactory.build_batch(10, repository=self.repository_vo,
domain_id=self.domain_id)
Expand All @@ -399,7 +384,6 @@ def test_list_plugins_by_name(self, *args):
self.assertIsInstance(plugins_vos[0], Plugin)
self.assertEqual(total_count, 1)

@patch.object(MongoModel, 'connect', return_value=None)
def test_list_plugins_by_repository(self, *args):
new_repository_vo = RepositoryFactory(repository_type='local')
plugin_vos = PluginFactory.build_batch(3, repository=new_repository_vo,
Expand All @@ -423,7 +407,6 @@ def test_list_plugins_by_repository(self, *args):
self.assertIsInstance(plugins_vos[0], Plugin)
self.assertEqual(total_count, 3)

@patch.object(MongoModel, 'connect', return_value=None)
def test_list_plugins_by_tag(self, *args):
PluginFactory(tags=[{'key': 'tag_key_1', 'value': 'tag_value_1'}], repository=self.repository_vo,
domain_id=self.domain_id)
Expand Down Expand Up @@ -451,7 +434,6 @@ def test_list_plugins_by_tag(self, *args):
self.assertIsInstance(plugins_vos[0], Plugin)
self.assertEqual(total_count, 1)

@patch.object(MongoModel, 'connect', return_value=None)
def test_stat_plugin(self, *args):
plugin_vos = PluginFactory.build_batch(10, repository=self.repository_vo,
domain_id=self.domain_id)
Expand Down
16 changes: 2 additions & 14 deletions test/service/test_policy_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from spaceone.core.unittest.runner import RichTestRunner
from spaceone.core import config
from spaceone.core import utils
from spaceone.core.model.mongo_model import MongoModel
from spaceone.core.transaction import Transaction
from spaceone.repository.error.policy import *
from spaceone.repository.service.policy_service import PolicyService
Expand All @@ -23,6 +22,8 @@ class TestPolicyService(unittest.TestCase):
@classmethod
def setUpClass(cls):
config.init_conf(package='spaceone.repository')
config.set_service_config()
config.set_global(MOCK_MODE=True)
connect('test', host='mongomock://localhost')

cls.repository_vo = RepositoryFactory(repository_type='local')
Expand All @@ -39,14 +40,12 @@ def tearDownClass(cls) -> None:
super().tearDownClass()
disconnect()

@patch.object(MongoModel, 'connect', return_value=None)
def tearDown(self, *args) -> None:
print()
print('(tearDown) ==> Delete all policys')
policy_vos = Policy.objects.filter()
policy_vos.delete()

@patch.object(MongoModel, 'connect', return_value=None)
def test_create_policy(self, *args):
params = {
'name': 'Domain Admin',
Expand Down Expand Up @@ -78,7 +77,6 @@ def test_create_policy(self, *args):
self.assertEqual(params['tags'], utils.tags_to_dict(policy_vo.tags))
self.assertEqual(params['domain_id'], policy_vo.domain_id)

@patch.object(MongoModel, 'connect', return_value=None)
def test_duplicate_create_policy(self, *args):
PolicyFactory(domain_id=self.domain_id, repository=self.repository_vo,
name='Domain Admin')
Expand All @@ -95,7 +93,6 @@ def test_duplicate_create_policy(self, *args):
policy_svc.create(params)

@patch.object(IdentityManager, 'get_project', return_value=None)
@patch.object(MongoModel, 'connect', return_value=None)
def test_create_policy_with_project(self, *args):
params = {
'name': 'Domain Admin',
Expand All @@ -114,7 +111,6 @@ def test_create_policy_with_project(self, *args):
self.assertIsInstance(policy_vo, Policy)
self.assertEqual(policy_vo.project_id, params['project_id'])

@patch.object(MongoModel, 'connect', return_value=None)
def test_update_policy(self, *args):
new_policy_vo = PolicyFactory(domain_id=self.domain_id)
params = {
Expand Down Expand Up @@ -143,7 +139,6 @@ def test_update_policy(self, *args):
self.assertEqual(params.get('labels', []), policy_vo.labels)
self.assertEqual(params['tags'], utils.tags_to_dict(policy_vo.tags))

@patch.object(MongoModel, 'connect', return_value=None)
def test_delete_policy(self, *args):
new_policy_vo = PolicyFactory(domain_id=self.domain_id)
params = {
Expand All @@ -157,7 +152,6 @@ def test_delete_policy(self, *args):

self.assertIsNone(result)

@patch.object(MongoModel, 'connect', return_value=None)
def test_get_policy(self, *args):
new_policy_vo = PolicyFactory(domain_id=self.domain_id)
params = {
Expand All @@ -175,7 +169,6 @@ def test_get_policy(self, *args):

self.assertIsInstance(policy_vo, Policy)

@patch.object(MongoModel, 'connect', return_value=None)
def test_get_policy_from_multi_repositories(self, *args):
new_repository_vo = RepositoryFactory(repository_type='remote')
new_policy_vo = PolicyFactory(domain_id=self.domain_id, repository=new_repository_vo)
Expand All @@ -193,7 +186,6 @@ def test_get_policy_from_multi_repositories(self, *args):

self.assertIsInstance(policy_vo, Policy)

@patch.object(MongoModel, 'connect', return_value=None)
def test_list_policies_by_name(self, *args):
policy_vos = PolicyFactory.build_batch(10, repository=self.repository_vo,
domain_id=self.domain_id)
Expand All @@ -213,7 +205,6 @@ def test_list_policies_by_name(self, *args):
self.assertIsInstance(policy_vos[0], Policy)
self.assertEqual(total_count, 1)

@patch.object(MongoModel, 'connect', return_value=None)
def test_list_policies_by_repository(self, *args):
new_repository_vo = RepositoryFactory(repository_type='local')
policy_vos = PolicyFactory.build_batch(3, repository=new_repository_vo,
Expand All @@ -237,7 +228,6 @@ def test_list_policies_by_repository(self, *args):
self.assertIsInstance(policy_vos[0], Policy)
self.assertEqual(total_count, 3)

@patch.object(MongoModel, 'connect', return_value=None)
def test_list_policies_by_tag(self, *args):
PolicyFactory(tags=[{'key': 'tag_key_1', 'value': 'tag_value_1'}], repository=self.repository_vo,
domain_id=self.domain_id)
Expand Down Expand Up @@ -265,7 +255,6 @@ def test_list_policies_by_tag(self, *args):
self.assertIsInstance(policy_vos[0], Policy)
self.assertEqual(total_count, 1)

@patch.object(MongoModel, 'connect', return_value=None)
def test_stat_policy(self, *args):
policy_vos = PolicyFactory.build_batch(10, repository=self.repository_vo,
domain_id=self.domain_id)
Expand Down Expand Up @@ -302,7 +291,6 @@ def test_stat_policy(self, *args):

print_data(values, 'test_stat_policy')

@patch.object(MongoModel, 'connect', return_value=None)
def test_stat_policy_distinct(self, *args):
policy_vos = PolicyFactory.build_batch(10, repository=self.repository_vo,
domain_id=self.domain_id)
Expand Down
Loading

0 comments on commit fb15827

Please sign in to comment.