def test_single_service(self): class TestMessage(Message): name = StringField() class TestService(Blueprint): @grpcmethod def test_message(self, request: TestMessage, context) -> TestMessage: ... test_service = TestService() self.assertListEqual( [TestMessage.__filename__, test_service.file_name], list(__meta__.keys()) ) self.assertEqual(1, len(__meta__[test_service.file_name].import_files)) self.assertEqual(0, len(__meta__[test_service.file_name].messages)) self.assertEqual(1, len(__meta__[test_service.file_name].services)) import_files = __meta__[test_service.file_name].import_files services = __meta__[test_service.file_name].services self.assertSetEqual({TestMessage.__filename__}, import_files) self.assertEqual(test_service.service_name, services[0].name) self.assertEqual(1, len(services[0].rpcs)) self.assertEqual("test_message", services[0].rpcs[0].__name__) self.assertEqual("TestMessage", services[0].rpcs[0].request_type.__name__) self.assertEqual("TestMessage", services[0].rpcs[0].response_type.__name__)
def test_single_message(self): class TestMessage(Message): name = StringField() self.assertEqual(1, len(__meta__.keys())) self.assertEqual(0, len(__meta__[TestMessage.__filename__].import_files)) self.assertEqual(1, len(__meta__[TestMessage.__filename__].messages)) self.assertEqual(0, len(__meta__[TestMessage.__filename__].services)) messages = __meta__[TestMessage.__filename__].messages self.assertEqual("TestMessage", messages[0].__name__) self.assertEqual(1, len(messages[0].__meta__))
def test_multiple_messages(self): class TestMessageOne(Message): __filename__ = "test" name = StringField() class TestMessageTwo(Message): __filename__ = "test" name = StringField() class TestMessageThree(Message): name = StringField() ref = ReferenceField(TestMessageOne()) self.assertEqual(2, len(__meta__.keys())) self.assertEqual(1, len(__meta__[TestMessageThree.__filename__].import_files)) self.assertEqual(2, len(__meta__[TestMessageOne.__filename__].messages)) self.assertEqual(1, len(__meta__[TestMessageThree.__filename__].messages))