class ModelRequestMessage(Message): sample_ids = repeated(Int(description='Sample IDs')) model_id = String(description='Model ID (f.e. iJO1366)') phase_id = Int(description='Phase ID') map = String(description='Name of map to show') method = String(description='Simulation method to run') with_fluxes = Bool(description='Add flux information to the response') objective = String(description='Reaction ID to be set as objective')
class PhasePlaneMessage(Message): objective_upper_bound = repeated( Float32(description='Upper bound for theoretical yield objective')) objective_lower_bound = repeated( Float32(description='Lower bound for theoretical yield objective')) objective = repeated(Float32(description='Theoretical objective values')) objective_id = String(description='Objective reaction ID')
class QueryResponse(Message): class Meta: description = 'Information about pets' ids = repeated(Field(Pet, description='Bunch of pets')) pet = Field(Pet, description='The other pet') repeat = repeated(String(description='Bunch of strings'))
class ParameterMessage(Message): in_ = String(json_name='in') # TODO: enum description: str required: bool name: str type: str items: SchemaMessage schema: SchemaMessage
class ModelMessage(Message): model_id = String( description= 'The saved model ID which can be used for retrieving cached information' ) fluxes = map_( Float32()) # TODO: fix not implemented while trying to add description growth_rate = Float32(description='Growth rate for this simulation') model: JSONValue
class ErrorResponse(Message): status = Int32() description = String() # TODO Repeat(String) path = String() # TODO helper for raising errors def raise_(self): if self.status == 501: raise NotImplemented_() # if self.status == 500: # raise ServerError(self.message or '') # if self.status == 404: # raise NotFound(self.message or '') raise RuntimeError('HTTP status {}: {}'.format(self.status, self.description))
class MeasurementMessage(Message): type = String( description= 'The subject of the measurement, e.g. "compound", "protein" or "reaction"' ) id = Int( description= 'identifier associated with the measured subject, e.g. metabolite identifier' ) name = String(description='In case of metabolite, human-readable name') db_name = String( description= 'In case of xref data, the miriam name of the database, e.g. uniprot') mode = String( description='Quantification mode, e.g. "relative" or "quantitative"') measurements = repeated( Float32(description='Measurements taken during the experiment')) units = MapField(str, description='Units in which measurements are taken') rate = String(description='Rate')
class SchemaMessage(Schema): ref = String(json_name='$ref') type: str # TODO: enum description: str items = Field('venom.rpc.reflect.openapi.SchemaMessage') properties = MapField('venom.rpc.reflect.openapi.SchemaMessage') additional_properties = Field('venom.rpc.reflect.openapi.SchemaMessage')
async def test_magic_request_message_auto_unpack(self): def func(self, value: str) -> StringValue: return StringValue(value) inspect = magic_normalize(func, auto_generate_request=True) self.assertEqual(inspect.response, StringValue) self.assertEqual(inspect.request.__meta__.name, 'FuncRequest') self.assertEqual(fields(inspect.request), ( String(name='value'), )) # TODO StringValue() should be equal to StringValue('') self.assertEqual(await inspect.invokable(None, inspect.request()), StringValue('')) self.assertEqual(await inspect.invokable(None, inspect.request('foo')), StringValue('foo'))
def test_stub_rpc_response_repeat_auto(self): class GreeterStub(Stub): @rpc(auto=True) def get_greetings(self) -> List[str]: raise NotImplementedError self.assertEqual(GreeterStub.get_greetings.response.__meta__.name, 'GetGreetingsResponse') self.assertEqual(tuple(fields(GreeterStub.get_greetings.response)), (repeated(String(), name='values'))) self.assertEqual(GreeterStub.greet.response, StringValue) self.assertEqual(GreeterStub.greet.name, 'get_greetings')
def test_stub_rpc_request_repeat_auto(self): class GreeterStub(Stub): @rpc(auto=True) def greet_many(self, names: List[str]) -> str: raise NotImplementedError self.assertEqual(GreeterStub.greet_many.request.__meta__.name, 'GreetManyRequest') self.assertEqual(tuple(fields(GreeterStub.greet_many.request)), (repeated(String(), name='names'), )) self.assertEqual(GreeterStub.greet_many.response, StringValue) self.assertEqual(GreeterStub.greet_many.name, 'greet_many')
def test_stub_rpc_request_auto(self): class GreeterStub(Stub): @rpc(auto=True) def greet(self, name: str, shout: bool = False) -> str: raise NotImplementedError self.assertEqual(GreeterStub.greet.request.__meta__.name, 'GreetRequest') self.assertEqual(tuple(fields(GreeterStub.greet.request)), ( String(name='name'), Bool(name='shout'), )) self.assertEqual(GreeterStub.greet.response, StringValue) self.assertEqual(GreeterStub.greet.name, 'greet')
def test_message_type_hints(self): class Pet(Message): sounds: List[str] size: float speed: int age: int self.assertIsInstance(Pet.__fields__, OrderedDict) self.assertEqual(('sounds', 'size', 'speed', 'age'), tuple(Pet.__fields__.keys())) self.assertEqual( { 'sounds': repeated(String(), name='sounds'), 'size': Field(float, name='size'), 'speed': Field(int, name='speed'), 'age': Field(int, name='age') }, Pet.__fields__)
def test_field_string(self): self.assertEqual(String(), Field(str))
class Pet(Message): id = Int() name = String() tag = String()
class FooInner(Message): i = String()
class Pet(Message): class Meta: description = 'Very important object' pet_id = String(description='Pet ID to query')
class Pet(Message): sound = String()
class Pet(Message): sounds = repeated(String())
class HelloRequest(Message): name = String()
class ExperimentMessage(Message): id = Int(description='Experiment ID') name = String(description='Experiment name')
class ExperimentsRequestMessage(Message): taxon_code = String( descripton= 'Species five-letter mnemonic short_code that must be associated with at least one ' 'sample belonging to the experiment')
class HelloResponse(Message): message = String()
class SampleModelsMessage(Message): response = repeated(String(description='Possible models for the sample'))
class PhaseMessage(Message): id = Int(description='Phase ID') name = String(description='Phase name')
class MetaboliteMediumMessage(Message): id = Int(description='Metabolite ID') name = String(description='Metabolite human-readable name') concentration = Float32(description='Concentration in medium')
class HelloRequest(Message): name = String() shout = Bool()
class Foo(Message): string = String()
class SampleMessage(Message): id = repeated(Int(description='Sample IDs')) name = String(description='Sample name') organism = String(description='Organism short code')
class SampleInfoMessage(Message): genotype_changes = repeated( String(description='Gnomic strings for genotype changes')) measurements = repeated(MeasurementMessage) medium = repeated(MetaboliteMediumMessage)