def test_invoke_method_bytes_data(self): dapr = DaprGrpcClient(f'localhost:{self.server_port}') resp = dapr.invoke_method( app_id='targetId', method_name='bytes', data=b'haha', content_type="text/plain", metadata=( ('key1', 'value1'), ('key2', 'value2'), ), http_verb='PUT', ) self.assertEqual(b'haha', resp.data) self.assertEqual("text/plain", resp.content_type) self.assertEqual(3, len(resp.headers)) self.assertEqual(['value1'], resp.headers['hkey1'])
def test_dapr_api_token_insertion(self): dapr = DaprGrpcClient(f'localhost:{self.server_port}') resp = dapr.invoke_method( app_id='targetId', method_name='bytes', data=b'haha', content_type="text/plain", metadata=( ('key1', 'value1'), ('key2', 'value2'), ), ) self.assertEqual(b'haha', resp.data) self.assertEqual("text/plain", resp.content_type) self.assertEqual(4, len(resp.headers)) self.assertEqual(['value1'], resp.headers['hkey1']) self.assertEqual(['test-token'], resp.headers['hdapr-api-token'])
def test_invoke_method_proto_data(self): dapr = DaprGrpcClient(f'localhost:{self.server_port}') req = common_v1.StateItem(key='test') resp = dapr.invoke_method( app_id='targetId', method_name='proto', data=req, metadata=( ('key1', 'value1'), ('key2', 'value2'), ), ) self.assertEqual(3, len(resp.headers)) self.assertEqual(['value1'], resp.headers['hkey1']) self.assertTrue(resp.is_proto()) # unpack to new protobuf object new_resp = common_v1.StateItem() resp.unpack(new_resp) self.assertEqual('test', new_resp.key)