def test_interface_descriptor__from_interface(interface: Interface): d = InterfaceDescriptor.from_interface(interface) assert d.version == ebonite.__version__ sig = Signature(args=[ Field('arg1', Container(5), False) ], output=Field(None, Container(5), False)) assert d.methods == [InterfaceMethodDescriptor.from_signature('method1', sig)]
def test_is_serializable__named_tuple(): ntuple = NamedTuple('ntuple', [('field1', str)]) assert is_serializable(ntuple('aaa')) assert is_serializable( Signature([Field('aaa', int, False)], Field(None, int, False)))
def test_create_spec__no_file(): field = Field('field', int, False) spec = create_spec('mymethod', Signature([field], field)) assert spec == { "summary": "Calls 'mymethod' method on model", 'requestBody': { 'required': True, "content": { "application/json": { 'schema': { 'type': 'object', 'properties': { 'field': { 'type': 'integer' } } } } } }, 'responses': { '200': { 'description': 'successful response', "content": { "application/json": { 'schema': { 'type': 'object', 'properties': { 'data': { 'type': 'integer' }, 'ok': { 'type': 'boolean' } } } } } }, '400': { 'description': 'incorrect request', "content": { "application/json": { 'schema': { 'type': 'object', 'properties': { 'error': { 'type': 'string' }, 'ok': { 'type': 'boolean' } } } } } } } }
def get_function_signature(f) -> Signature: """ Get function arguments as list of :class:`~pyjackson.core.Field` and annotated return type :param f: function :return: Signature named tuple """ ret = Field(None, f.__annotations__.get('return'), False) return Signature(get_function_fields(f), ret)
def test_create_spec__with_file(): field = Field('field', BytesDatasetType(), False) spec = create_spec('mymethod', Signature([field], field), 'iface_name', 'method_doc') assert spec == { "summary": "Calls 'mymethod' method on iface_name. Method description: method_doc", 'requestBody': { 'required': True, 'content': { 'multipart/form-data': { 'schema': { 'type': 'object', 'properties': { 'field': { 'type': 'string', 'format': 'binary' } } } } } }, 'responses': { '200': { "description": "successful response", 'content': { 'multipart/form-data': { 'type': 'string', 'format': 'binary' } } }, '400': { 'description': 'incorrect request', "content": { "application/json": { 'schema': { 'type': 'object', 'properties': { 'error': { 'type': 'string' }, 'ok': { 'type': 'boolean' } } } } } } } }
def __init__(self, model): self.model = model exposed = {**self.exposed} executors = {**self.executors} for name in self.model.exposed_methods: in_type, out_type = self.model.method_signature(name) exposed[name] = Signature([Field("vector", in_type, False)], Field(None, out_type, False)) executors[name] = self._exec_factory(name, out_type) self.exposed = exposed self.executors = executors
def test_create_spec__with_file(): field = Field('field', FilelikeDatasetType(), False) spec = create_spec('mymethod', Signature([field], field)) assert spec == { 'definitions': { 'error': { 'type': 'object', 'properties': { 'error': { 'type': 'string' }, 'ok': { 'type': 'boolean' } } } }, 'parameters': [{ 'description': 'field', 'in': 'formData', 'name': 'field', 'required': True, 'type': 'file' }], 'responses': { '200': { "description": "resp descr", 'content': { '*/*': { 'type': 'string', 'format': 'binary' } } }, '400': { 'description': 'resp descr', 'schema': { '$ref': '#/definitions/error' } } }, 'summary': 'mymethod' }
def test_create_spec__no_file(): field = Field('field', int, False) spec = create_spec('mymethod', Signature([field], field)) assert spec == { 'definitions': { 'error': { 'type': 'object', 'properties': { 'error': { 'type': 'string' }, 'ok': { 'type': 'boolean' } } }, 'request_mymethod': { 'type': 'object', 'properties': { 'field': { 'type': 'integer' } } }, 'response_mymethod': { 'type': 'object', 'properties': { 'data': { 'type': 'integer' }, 'ok': { 'type': 'boolean' } } } }, 'parameters': [{ 'in': 'body', 'name': 'body', 'required': True, 'schema': { '$ref': '#/definitions/request_mymethod' } }], 'responses': { '200': { 'description': 'resp descr', 'schema': { '$ref': '#/definitions/response_mymethod' } }, '400': { 'description': 'resp descr', 'schema': { '$ref': '#/definitions/error' } } }, 'summary': 'mymethod' }