def test_list_schemas_by_tag(self, *args): SchemaFactory(tags=[{ 'key': 'tag_key_1', 'value': 'tag_value_1' }], repository=self.repository_vo, domain_id=self.domain_id) schema_vos = SchemaFactory.build_batch(9, repository=self.repository_vo, domain_id=self.domain_id) list(map(lambda vo: vo.save(), schema_vos)) params = { 'query': { 'filter': [{ 'k': 'tags.tag_key_1', 'v': 'tag_value_1', 'o': 'eq' }] }, 'repository_id': self.repository_id, 'domain_id': self.domain_id } schema_svc = SchemaService() schemas_vos, total_count = schema_svc.list(params) SchemasInfo(schema_vos, total_count) self.assertEqual(len(schemas_vos), 1) self.assertIsInstance(schemas_vos[0], Schema) self.assertEqual(total_count, 1)
def test_update_schema(self, *args): new_schema_vo = SchemaFactory(domain_id=self.domain_id) params = { 'name': new_schema_vo.name, 'schema': { 'type': 'object', 'properties': { 'domain': { 'title': 'Email Domain', 'type': 'string', 'minLength': 4, 'examples': ['Ex) gmail.com'] } }, 'required': ['domain'] }, 'labels': ['ee', 'ff'], 'tags': { 'update_key': 'update_value' }, 'domain_id': self.domain_id } self.transaction.method = 'update' schema_svc = SchemaService(transaction=self.transaction) schema_vo = schema_svc.update(params.copy()) print_data(schema_vo.to_dict(), 'test_update_schema') SchemaInfo(schema_vo) self.assertIsInstance(schema_vo, Schema) self.assertEqual(params['name'], schema_vo.name) self.assertEqual(params.get('schema', {}), schema_vo.schema) self.assertEqual(params.get('labels', []), schema_vo.labels) self.assertEqual(params['tags'], utils.tags_to_dict(schema_vo.tags))
def test_delete_schema(self, *args): new_schema_vo = SchemaFactory(domain_id=self.domain_id) params = {'name': new_schema_vo.name, 'domain_id': self.domain_id} self.transaction.method = 'delete' schema_svc = SchemaService(transaction=self.transaction) result = schema_svc.delete(params) self.assertIsNone(result)
def test_list_schemas_by_repository(self, *args): new_repository_vo = RepositoryFactory(repository_type='local') schema_vos = SchemaFactory.build_batch(3, repository=new_repository_vo, domain_id=self.domain_id) list(map(lambda vo: vo.save(), schema_vos)) schema_vos = SchemaFactory.build_batch(7, repository=self.repository_vo, domain_id=self.domain_id) list(map(lambda vo: vo.save(), schema_vos)) params = { 'repository_id': new_repository_vo.repository_id, 'domain_id': self.domain_id } schema_svc = SchemaService() schemas_vos, total_count = schema_svc.list(params) SchemasInfo(schema_vos, total_count) self.assertEqual(len(schemas_vos), 3) self.assertIsInstance(schemas_vos[0], Schema) self.assertEqual(total_count, 3)
def test_get_schema_from_multi_repositories(self, *args): new_repository_vo = RepositoryFactory(repository_type='remote') new_schema_vo = SchemaFactory(domain_id=self.domain_id, repository=new_repository_vo) params = {'name': new_schema_vo.name, 'domain_id': self.domain_id} self.transaction.method = 'get' schema_svc = SchemaService(transaction=self.transaction) schema_vo = schema_svc.get(params) print_data(schema_vo.to_dict(), 'test_get_schema_from_multi_repositories') SchemaInfo(schema_vo) self.assertIsInstance(schema_vo, Schema)
def test_get_schema(self, *args): new_schema_vo = SchemaFactory(domain_id=self.domain_id) params = { 'name': new_schema_vo.name, 'repository_id': self.repository_id, 'domain_id': self.domain_id } self.transaction.method = 'get' schema_svc = SchemaService(transaction=self.transaction) schema_vo = schema_svc.get(params) print_data(schema_vo.to_dict(), 'test_get_schema') SchemaInfo(schema_vo) self.assertIsInstance(schema_vo, Schema)
def test_duplicate_create_schema(self, *args): SchemaFactory(domain_id=self.domain_id, repository=self.repository_vo, name='aws_access_key') params = { 'name': 'aws_access_key', 'service_type': 'secret.credentials', 'schema': { 'type': 'object', 'properties': {} }, 'domain_id': self.domain_id } self.transaction.method = 'create' schema_svc = SchemaService(transaction=self.transaction) with self.assertRaises(ERROR_SAVE_UNIQUE_VALUES): schema_svc.create(params)
def test_list_schemas_by_name(self, *args): schema_vos = SchemaFactory.build_batch(10, repository=self.repository_vo, domain_id=self.domain_id) list(map(lambda vo: vo.save(), schema_vos)) params = { 'name': schema_vos[0].name, 'repository_id': self.repository_id, 'domain_id': self.domain_id } schema_svc = SchemaService() schemas_vos, total_count = schema_svc.list(params) SchemasInfo(schema_vos, total_count) self.assertEqual(len(schemas_vos), 1) self.assertIsInstance(schemas_vos[0], Schema) self.assertEqual(total_count, 1)
def test_stat_schema_distinct(self, *args): schema_vos = SchemaFactory.build_batch(10, repository=self.repository_vo, domain_id=self.domain_id) list(map(lambda vo: vo.save(), schema_vos)) params = { 'domain_id': self.domain_id, 'repository_id': self.repository_vo.repository_id, 'query': { 'distinct': 'name', 'page': { 'start': 3, 'limit': 4 } } } self.transaction.method = 'stat' schema_svc = SchemaService(transaction=self.transaction) values = schema_svc.stat(params) StatisticsInfo(values) print_data(values, 'test_stat_schema_distinct')
def test_stat_schema(self, *args): schema_vos = SchemaFactory.build_batch(10, repository=self.repository_vo, domain_id=self.domain_id) list(map(lambda vo: vo.save(), schema_vos)) params = { 'domain_id': self.domain_id, 'repository_id': self.repository_vo.repository_id, 'query': { 'aggregate': [{ 'group': { 'keys': [{ 'key': 'name', 'name': 'Schema' }], 'fields': [{ 'operator': 'count', 'name': 'Count' }] } }, { 'sort': { 'key': 'Count', 'desc': True } }] } } self.transaction.method = 'stat' schema_svc = SchemaService(transaction=self.transaction) values = schema_svc.stat(params) StatisticsInfo(values) print_data(values, 'test_stat_schema')
def list(self, params): return SchemaFactory.build_batch(10, **params), 10
def get(self, params): return SchemaFactory(**params)
def update(self, params): params = copy.deepcopy(params) if 'tags' in params: params['tags'] = utils.dict_to_tags(params['tags']) return SchemaFactory(**params)