def test_render__with_markdown_description(self): renderer = self.mocker.patch( 'lily.entrypoint.renderer.SchemaRenderer') serialize = Mock() renderer.return_value.render.return_value = Mock( serialize=serialize, enums=[]) serialize.side_effect = [ {'output': 'schema'}, {'query': 'schema'}, {'body': 'schema'}, ] meta = Meta( title='hi', description='./description.md', domain=Domain(id='h', name='hh')) access = Access(access_list=['EVERYONE'], is_private=True) source = Source(fn) self.mocker.patch.object(BaseRenderer, 'render').return_value = { 'READ_CARD': { 'method': 'get', 'path_conf': { 'path': '/hi', 'pattern': '/hi', 'parameters': [], }, 'meta': meta, 'access': access, 'input': Input(query_parser=Mock(), body_parser=Mock()), 'output': Output(serializer=Mock()), 'source': source, } } result = CommandsRenderer().render() meta = Meta( title='hi', description='# this is test of markdown description', domain=Domain(id='h', name='hh')) assert result == { 'enums': [], 'READ_CARD': { 'access': access, 'meta': meta, 'method': 'get', 'path_conf': { 'parameters': [], 'path': '/hi', }, 'schemas': { 'input_body': {'body': 'schema'}, 'input_query': {'query': 'schema'}, 'output': {'output': 'schema'}, }, 'source': source, 'examples': {}, } }
def command(self, is_private=None, domain_id=None): def fn(): pass if is_private is None: is_private = random.choice([True, False]) if domain_id is None: domain_id = faker.word() command = { 'method': random.choice(['GET', 'POST', 'PUT', 'DELETE']), 'path_conf': { 'path': 'conf' }, 'meta': Meta(title=faker.sentence(), description=faker.sentence(), domain=Domain(id=domain_id, name='domain')), 'access': Access(is_private=is_private, access_list=['ANY']), 'source': Source(fn), 'schemas': { 'some': 'schemas' }, 'examples': { 'some': 'examples' }, } return command
from lily import Domain ACCOUNT_AUTHENTICATION = Domain( id='account_authentication', name='Account & Auth Management')
from lily import Domain CATALOGUE = Domain(id='catalogue', name='Catalogue Items Management')
def test_render__with_examples(self): renderer = self.mocker.patch( 'lily.entrypoint.renderer.SchemaRenderer') serialize = Mock() renderer.return_value.render.return_value = Mock( serialize=serialize, enums=[]) serialize.side_effect = [ {'output': 'schema'}, {'query': 'schema'}, {'body': 'schema'}, ] meta = Meta( title='hi', description='ho', domain=Domain(id='h', name='hh')) access = Access(access_list=['EVERYONE'], is_private=True) source = Source(fn) self.mocker.patch.object(BaseRenderer, 'render').return_value = { 'READ_CARD': { 'method': 'get', 'path_conf': { 'path': '/hi', 'pattern': '/hi', 'parameters': [], }, 'meta': meta, 'access': access, 'input': Input(query_parser=Mock(), body_parser=Mock()), 'output': Output(serializer=Mock()), 'source': source, } } with open(self.examples_filepath, 'w') as f: f.write(json.dumps({ 'READ_CARD': { '200 (OK)': { 'request': { 'path': '/hi', 'parameters': {}, }, }, }, })) assert CommandsRenderer().render() == { 'enums': [], 'READ_CARD': { 'access': access, 'meta': meta, 'method': 'get', 'path_conf': { 'parameters': [], 'path': '/hi', }, 'schemas': { 'input_body': {'body': 'schema'}, 'input_query': {'query': 'schema'}, 'output': {'output': 'schema'}, }, 'source': source, 'examples': { '200 (OK)': { 'request': { 'path': '/hi', 'parameters': {}, }, }, }, } }
def test_render__many_commands(self): renderer = self.mocker.patch( 'lily.entrypoint.renderer.SchemaRenderer') serialize = Mock() renderer.return_value.render.return_value = Mock( serialize=serialize, enums=[]) serialize.side_effect = [ {'output': 'read.schema'}, {'query': 'read.schema'}, {'body': 'read.schema'}, {'output': 'delete.schema'}, {'query': 'delete.schema'}, {'body': 'delete.schema'}, ] meta = Meta( title='hi', description='ho', domain=Domain(id='h', name='hh')) access = Access(access_list=['EVERYONE'], is_private=True) source = Source(fn) self.mocker.patch.object( BaseRenderer, 'render' ).return_value = OrderedDict([ ( 'READ_CARD', { 'method': 'get', 'path_conf': { 'path': '/hi', 'pattern': '/hi', 'parameters': [], }, 'meta': meta, 'access': access, 'input': Input(query_parser=Mock(), body_parser=Mock()), 'output': Output(serializer=Mock()), 'source': source, }, ), ( 'DELETE_TASK', { 'method': 'delete', 'path_conf': { 'path': '/hi/{id}', 'pattern': '/hi/(?P<id>\\d+)', 'parameters': [{'name': 'id', 'type': 'integer'}], }, 'meta': meta, 'access': access, 'input': Input(query_parser=Mock(), body_parser=Mock()), 'output': Output(serializer=Mock()), 'source': source, } )]) assert CommandsRenderer().render() == { 'enums': [], 'READ_CARD': { 'access': access, 'meta': meta, 'method': 'get', 'path_conf': { 'parameters': [], 'path': '/hi', }, 'schemas': { 'input_body': {'body': 'read.schema'}, 'input_query': {'query': 'read.schema'}, 'output': {'output': 'read.schema'}, }, 'source': source, 'examples': {}, }, 'DELETE_TASK': { 'access': access, 'meta': meta, 'method': 'delete', 'path_conf': { 'path': '/hi/{id}', 'parameters': [{'name': 'id', 'type': 'integer'}], }, 'schemas': { 'input_body': {'body': 'delete.schema'}, 'input_query': {'query': 'delete.schema'}, 'output': {'output': 'delete.schema'}, }, 'source': source, 'examples': {}, }, }
from lily import Domain DOWNLOAD_REQUESTS = Domain(id='download_requests', name='Download Requests Management')
from lily.base.test import Client from lily.base.commands import S3UploadSignCommands from lily.base.command import command_override from lily import ( Meta, name, Domain, Access, ) MySignCommands = S3UploadSignCommands.overwrite(get=command_override( name=name.Execute('SIGN', 'PROCESS'), meta=Meta(title=( 'Sign Process dedicated to upload and conversion of media ' 'file'), domain=Domain(id='hey', name='hi')), access=Access(access_list=['PREMIUM', 'SUPER_PREMIUM']))) urlpatterns.extend([ re_path(r'^sign/$', MySignCommands.as_view(), name='test.sign'), ]) class MySignCommandsTestCase(TestCase): uri = reverse('test.sign') @pytest.fixture(autouse=True) def initfixtures(self, mocker): self.mocker = mocker