Skip to content

Commit

Permalink
Merge pull request #17 from whdalsrnt/master
Browse files Browse the repository at this point in the history
Change tags message type
  • Loading branch information
whdalsrnt authored Apr 10, 2021
2 parents d51199d + 86046e6 commit 4890d13
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 66 deletions.
6 changes: 3 additions & 3 deletions src/spaceone/config/info/domain_config_info.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import functools
from spaceone.api.core.v1 import tag_pb2
from spaceone.api.config.v1 import domain_config_pb2
from spaceone.core.pygrpc.message_type import *
from spaceone.core import utils
from spaceone.config.model.domain_config_model import DomainConfig

__all__ = ['DomainConfigInfo', 'DomainConfigsInfo']
Expand All @@ -15,10 +15,10 @@ def DomainConfigInfo(domain_config_vo: DomainConfig, minimal=False):
if not minimal:
info.update({
'data': change_struct_type(domain_config_vo.data),
'tags': [tag_pb2.Tag(key=tag.key, value=tag.value) for tag in domain_config_vo.tags],
'tags': change_struct_type(utils.tags_to_dict(domain_config_vo.tags)),
'schema': domain_config_vo.schema,
'domain_id': domain_config_vo.domain_id,
'created_at': change_timestamp_type(domain_config_vo.created_at)
'created_at': utils.datetime_to_iso8601(domain_config_vo.created_at)
})

return domain_config_pb2.DomainConfigInfo(**info)
Expand Down
6 changes: 3 additions & 3 deletions src/spaceone/config/info/user_config_info.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import functools
from spaceone.api.core.v1 import tag_pb2
from spaceone.api.config.v1 import user_config_pb2
from spaceone.core.pygrpc.message_type import *
from spaceone.core import utils
from spaceone.config.model.user_config_model import UserConfig

__all__ = ['UserConfigInfo', 'UserConfigsInfo']
Expand All @@ -15,9 +15,9 @@ def UserConfigInfo(user_config_vo: UserConfig, minimal=False):
if not minimal:
info.update({
'data': change_struct_type(user_config_vo.data),
'tags': [tag_pb2.Tag(key=tag.key, value=tag.value) for tag in user_config_vo.tags],
'tags': change_struct_type(utils.tags_to_dict(user_config_vo.tags)),
'domain_id': user_config_vo.domain_id,
'created_at': change_timestamp_type(user_config_vo.created_at)
'created_at': utils.datetime_to_iso8601(user_config_vo.created_at)
})

return user_config_pb2.UserConfigInfo(**info)
Expand Down
12 changes: 10 additions & 2 deletions src/spaceone/config/service/domain_config_service.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import logging

from spaceone.core.service import *
from spaceone.core import utils
from spaceone.config.manager.domain_config_manager import DomainConfigManager

_LOGGER = logging.getLogger(__name__)
Expand All @@ -25,14 +26,17 @@ def create(self, params):
'name': 'str',
'data': 'dict',
'schema': 'str',
'tags': 'list',
'tags': 'dict',
'domain_id': 'str'
}
Returns:
domain_config_vo (object)
"""

if 'tags' in params:
params['tags'] = utils.dict_to_tags(params['tags'])

return self.domain_config_mgr.create_domain_config(params)

@transaction(append_meta={'authorization.scope': 'DOMAIN'})
Expand All @@ -45,13 +49,17 @@ def update(self, params):
'name': 'str',
'data': 'dict',
'schema': 'str',
'tags': 'list',
'tags': 'dict',
'domain_id': 'str'
}
Returns:
domain_config_vo (object)
"""

if 'tags' in params:
params['tags'] = utils.dict_to_tags(params['tags'])

return self.domain_config_mgr.update_domain_config(params)

@transaction(append_meta={'authorization.scope': 'DOMAIN'})
Expand Down
12 changes: 10 additions & 2 deletions src/spaceone/config/service/user_config_service.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import logging

from spaceone.core.service import *
from spaceone.core import utils
from spaceone.config.manager.user_config_manager import UserConfigManager

_LOGGER = logging.getLogger(__name__)
Expand All @@ -24,14 +25,17 @@ def create(self, params):
params (dict): {
'name': 'str',
'data': 'dict',
'tags': 'list',
'tags': 'dict',
'domain_id': 'str'
}
Returns:
user_config_vo (object)
"""

if 'tags' in params:
params['tags'] = utils.dict_to_tags(params['tags'])

return self.user_config_mgr.create_user_config(params)

@transaction(append_meta={'authorization.scope': 'DOMAIN'})
Expand All @@ -43,13 +47,17 @@ def update(self, params):
params (dict): {
'name': 'str',
'data': 'dict',
'tags': 'list',
'tags': 'dict',
'domain_id': 'str'
}
Returns:
user_config_vo (object)
"""

if 'tags' in params:
params['tags'] = utils.dict_to_tags(params['tags'])

return self.user_config_mgr.update_user_config(params)

@transaction(append_meta={'authorization.scope': 'DOMAIN'})
Expand Down
31 changes: 17 additions & 14 deletions test/api/test_domain_config_api.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import unittest
import copy
from unittest.mock import patch
from mongoengine import connect, disconnect
from google.protobuf.json_format import MessageToDict
Expand All @@ -19,9 +20,17 @@
class _MockDomainConfigService(BaseService):

def create(self, params):
params = copy.deepcopy(params)
if 'tags' in params:
params['tags'] = utils.dict_to_tags(params['tags'])

return DomainConfigFactory(**params)

def update(self, params):
params = copy.deepcopy(params)
if 'tags' in params:
params['tags'] = utils.dict_to_tags(params['tags'])

return DomainConfigFactory(**params)

def delete(self, params):
Expand Down Expand Up @@ -62,12 +71,9 @@ def test_create_domain_config(self, mock_parse_request, *args):
'config_key': 'config_value'
},
'schema': utils.random_string(),
'tags': [
{
'key': 'tag_key',
'value': 'tag_value'
}
],
'tags': {
utils.random_string(): utils.random_string()
},
'domain_id': utils.generate_id('domain')
}
mock_parse_request.return_value = (params, {})
Expand All @@ -81,7 +87,7 @@ def test_create_domain_config(self, mock_parse_request, *args):
self.assertIsInstance(domain_config_info, domain_config_pb2.DomainConfigInfo)
self.assertEqual(domain_config_info.name, params['name'])
self.assertDictEqual(MessageToDict(domain_config_info.data), params['data'])
self.assertListEqual(domain_config_data['tags'], params['tags'])
self.assertDictEqual(domain_config_data['tags'], params['tags'])
self.assertEqual(domain_config_info.domain_id, params['domain_id'])
self.assertIsNotNone(getattr(domain_config_info, 'created_at', None))

Expand All @@ -95,12 +101,9 @@ def test_update_domain_config(self, mock_parse_request, *args):
'update_config_key': 'update_config_value'
},
'schema': utils.random_string(),
'tags': [
{
'key': 'update_key',
'value': 'update_value'
}
],
'tags': {
'update_key': 'update_value'
},
'domain_id': utils.generate_id('domain')
}
mock_parse_request.return_value = (params, {})
Expand All @@ -113,7 +116,7 @@ def test_update_domain_config(self, mock_parse_request, *args):

self.assertIsInstance(domain_config_info, domain_config_pb2.DomainConfigInfo)
self.assertDictEqual(MessageToDict(domain_config_info.data), params['data'])
self.assertListEqual(domain_config_data['tags'], params['tags'])
self.assertDictEqual(domain_config_data['tags'], params['tags'])

@patch.object(BaseAPI, '__init__', return_value=None)
@patch.object(Locator, 'get_service', return_value=_MockDomainConfigService())
Expand Down
32 changes: 18 additions & 14 deletions test/api/test_user_config_api.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import unittest
import copy
from unittest.mock import patch
from mongoengine import connect, disconnect
from google.protobuf.json_format import MessageToDict
Expand All @@ -19,9 +20,18 @@
class _MockUserConfigService(BaseService):

def create(self, params):
params = copy.deepcopy(params)
if 'tags' in params:
params['tags'] = utils.dict_to_tags(params['tags'])

return UserConfigFactory(**params)

def update(self, params):

params = copy.deepcopy(params)
if 'tags' in params:
params['tags'] = utils.dict_to_tags(params['tags'])

return UserConfigFactory(**params)

def delete(self, params):
Expand Down Expand Up @@ -61,12 +71,9 @@ def test_create_user_config(self, mock_parse_request, *args):
'data': {
'config_key': 'config_value'
},
'tags': [
{
'key': 'tag_key',
'value': 'tag_value'
}
],
'tags': {
utils.random_string(): utils.random_string()
},
'domain_id': utils.generate_id('domain')
}
mock_parse_request.return_value = (params, {})
Expand All @@ -80,7 +87,7 @@ def test_create_user_config(self, mock_parse_request, *args):
self.assertIsInstance(user_config_info, user_config_pb2.UserConfigInfo)
self.assertEqual(user_config_info.name, params['name'])
self.assertDictEqual(MessageToDict(user_config_info.data), params['data'])
self.assertListEqual(user_config_data['tags'], params['tags'])
self.assertDictEqual(user_config_data['tags'], params['tags'])
self.assertEqual(user_config_info.domain_id, params['domain_id'])
self.assertIsNotNone(getattr(user_config_info, 'created_at', None))

Expand All @@ -93,12 +100,9 @@ def test_update_user_config(self, mock_parse_request, *args):
'data': {
'update_config_key': 'update_config_value'
},
'tags': [
{
'key': 'update_key',
'value': 'update_value'
}
],
'tags': {
'update_key': 'update_value'
},
'domain_id': utils.generate_id('domain')
}
mock_parse_request.return_value = (params, {})
Expand All @@ -111,7 +115,7 @@ def test_update_user_config(self, mock_parse_request, *args):

self.assertIsInstance(user_config_info, user_config_pb2.UserConfigInfo)
self.assertDictEqual(MessageToDict(user_config_info.data), params['data'])
self.assertListEqual(user_config_data['tags'], params['tags'])
self.assertDictEqual(user_config_data['tags'], params['tags'])

@patch.object(BaseAPI, '__init__', return_value=None)
@patch.object(Locator, 'get_service', return_value=_MockUserConfigService())
Expand Down
22 changes: 8 additions & 14 deletions test/service/test_domain_config_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,9 @@ def test_create_domain_config(self, *args):
'key': 'value'
},
'schema': 'test_schema',
'tags': [
{
'key': 'tag_key',
'value': 'tag_value'
}
],
'tags': {
utils.random_string(): utils.random_string()
},
'domain_id': utils.generate_id('domain')
}

Expand All @@ -69,7 +66,7 @@ def test_create_domain_config(self, *args):
self.assertEqual(params['name'], domain_config_vo.name)
self.assertEqual(params['data'], domain_config_vo.data)
self.assertEqual(params['schema'], domain_config_vo.schema)
self.assertEqual(params.get('tags', {}), domain_config_vo.to_dict()['tags'])
self.assertEqual(params['tags'], utils.tags_to_dict(domain_config_vo.tags))
self.assertEqual(params['domain_id'], domain_config_vo.domain_id)

@patch.object(MongoModel, 'connect', return_value=None)
Expand All @@ -82,12 +79,9 @@ def test_update_domain_config(self, *args):
'update_data_key': 'update_data_value'
},
'schema': 'update_schema',
'tags': [
{
'key': 'update_key',
'value': 'update_value'
}
],
'tags': {
'update_key': 'update_value'
},
'domain_id': self.domain_id
}

Expand All @@ -101,7 +95,7 @@ def test_update_domain_config(self, *args):
self.assertIsInstance(domain_config_vo, DomainConfig)
self.assertEqual(params['data'], domain_config_vo.data)
self.assertEqual(params['schema'], domain_config_vo.schema)
self.assertEqual(params.get('tags', {}), domain_config_vo.to_dict()['tags'])
self.assertEqual(params['tags'], utils.tags_to_dict(domain_config_vo.tags))
self.assertEqual(params['domain_id'], domain_config_vo.domain_id)

@patch.object(MongoModel, 'connect', return_value=None)
Expand Down
22 changes: 8 additions & 14 deletions test/service/test_user_config_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,9 @@ def test_create_user_config(self, *args):
'data': {
'key': 'value'
},
'tags': [
{
'key': 'tag_key',
'value': 'tag_value'
}
],
'tags': {
utils.random_string(): utils.random_string()
},
'domain_id': utils.generate_id('domain')
}

Expand All @@ -67,7 +64,7 @@ def test_create_user_config(self, *args):
self.assertIsInstance(user_config_vo, UserConfig)
self.assertEqual(params['name'], user_config_vo.name)
self.assertEqual(params['data'], user_config_vo.data)
self.assertEqual(params.get('tags', {}), user_config_vo.to_dict()['tags'])
self.assertEqual(params['tags'], utils.tags_to_dict(user_config_vo.tags))
self.assertEqual(params['domain_id'], user_config_vo.domain_id)

@patch.object(MongoModel, 'connect', return_value=None)
Expand All @@ -79,12 +76,9 @@ def test_update_user_config(self, *args):
'data': {
'update_data_key': 'update_data_value'
},
'tags': [
{
'key': 'update_key',
'value': 'update_value'
}
],
'tags': {
'update_key': 'update_value'
},
'domain_id': self.domain_id
}

Expand All @@ -97,7 +91,7 @@ def test_update_user_config(self, *args):

self.assertIsInstance(user_config_vo, UserConfig)
self.assertEqual(params['data'], user_config_vo.data)
self.assertEqual(params.get('tags', {}), user_config_vo.to_dict()['tags'])
self.assertEqual(params['tags'], utils.tags_to_dict(user_config_vo.tags))
self.assertEqual(params['domain_id'], user_config_vo.domain_id)

@patch.object(MongoModel, 'connect', return_value=None)
Expand Down

0 comments on commit 4890d13

Please sign in to comment.