def testHandle_MissingSourceClientId(self, _): handler = client_plugin.ApiGetFleetspeakPendingMessagesHandler() args = client_plugin.ApiGetFleetspeakPendingMessagesArgs( client_id="C.1111111111111111") fleetspeak_proto = admin_pb2.GetPendingMessagesResponse() text_format.Parse( """ messages: { source: { service_name: "s1" } } """, fleetspeak_proto) expected_result = (client_plugin.ApiGetFleetspeakPendingMessagesResult. FromTextFormat(""" messages: { source: { service_name: "s1" } } """)) with mock.patch.object(fleetspeak_utils, "GetFleetspeakPendingMessages", return_value=fleetspeak_proto): result = handler.Handle(args) self.assertEqual(result, expected_result)
def GetFleetspeakPendingMessages( self, args: api_client.ApiGetFleetspeakPendingMessagesArgs, context: Optional[api_call_context.ApiCallContext] = None ) -> api_client.ApiGetFleetspeakPendingMessagesHandler: return api_client.ApiGetFleetspeakPendingMessagesHandler()
def testHandle(self, _): handler = client_plugin.ApiGetFleetspeakPendingMessagesHandler() args = client_plugin.ApiGetFleetspeakPendingMessagesArgs( client_id="C.1111111111111111", offset=1, limit=2, want_data=True) fleetspeak_proto = admin_pb2.GetPendingMessagesResponse() text_format.Parse( """ messages: { message_id: "m1" source: { client_id: "\x00\x00\x00\x00\x00\x00\x00\x01" service_name: "s1" } source_message_id: "m2" destination : { client_id: "\x00\x00\x00\x00\x00\x00\x00\x02" service_name: "s2" } message_type: "mt" creation_time: { seconds: 1617187637 nanos: 101000 } data: { [type.googleapis.com/google.protobuf.Timestamp] { seconds: 1234 } } validation_info: { tags: { key: "k1" value: "v1" } } result: { processed_time: { seconds: 1617187637 nanos: 101000 } failed: True failed_reason: "fr" } priority: LOW background: true annotations: { entries: { key: "ak1" value: "av1" } } } """, fleetspeak_proto) expected_result = client_plugin.ApiGetFleetspeakPendingMessagesResult.FromTextFormat( """ messages: { message_id: "m1" source: { client_id: "C.0000000000000001" service_name: "s1" } source_message_id: "m2" destination : { client_id: "C.0000000000000002" service_name: "s2" } message_type: "mt" creation_time: 1617187637000101 data: { [type.googleapis.com/google.protobuf.Timestamp] { seconds: 1234 } } validation_info: { tags: { key: "k1" value: "v1" } } result: { processed_time: 1617187637000101 failed: True failed_reason: "fr" } priority: LOW background: true annotations: { entries: { key: "ak1" value: "av1" } } } """) with mock.patch.object(fleetspeak_utils, "GetFleetspeakPendingMessages", return_value=fleetspeak_proto) as mock_get: result = handler.Handle(args) self.assertEqual(mock_get.call_args[0][0], "C.1111111111111111") self.assertEqual(mock_get.call_args[1]["offset"], 1) self.assertEqual(mock_get.call_args[1]["limit"], 2) self.assertEqual(mock_get.call_args[1]["want_data"], True) self.assertEqual(result, expected_result)