Skip to content

Commit

Permalink
added parse response test in client_test.py
Browse files Browse the repository at this point in the history
  • Loading branch information
punit-kulal committed Aug 17, 2023
1 parent 4271d62 commit 505cedc
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion clients/python/rest/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,5 @@ def _set_content_type_header(self, headers):

def _parse_response(self, response) -> SendEventResponse:
if len(response.content) != 0:
event_response = self.wire.unmarshal(str(response.content), SendEventResponse())
event_response = self.wire.unmarshal(response.content, SendEventResponse())
return event_response
14 changes: 12 additions & 2 deletions clients/python/tests/unit/rest/client_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from google.protobuf import json_format, timestamp_pb2

import client
from protos.raystack.raccoon.v1beta1.raccoon_pb2 import SendEventRequest, SendEventResponse, Status, Event
from protos.raystack.raccoon.v1beta1.raccoon_pb2 import SendEventRequest, SendEventResponse, Status, Event, Code
from rest.client import RestClient
from rest.option import RestClientConfigBuilder
from serde.enum import Serialiser, WireType
Expand Down Expand Up @@ -202,13 +202,23 @@ def test_client_send_connection_failure(self):
headers={"Content-Type": "application/json"}, timeout=2.0)
rest_client._parse_response.assert_not_called()

def test_parse_response(self):
def test_parse_response_json(self):
resp = get_stub_response_json()
rest_client = self._get_rest_client()
deserialised_response = rest_client._parse_response(resp)
self.assertEqual(deserialised_response.status, Status.STATUS_SUCCESS)
self.assertEqual(deserialised_response.data["req_guid"], get_static_uuid())
self.assertEqual(deserialised_response.sent_time, get_static_time())
self.assertEqual(deserialised_response.code, Code.CODE_OK)

def test_parse_response_protobuf(self):
resp = get_stub_response_protobuf()
rest_client = self._get_rest_client(wire_type=WireType.PROTOBUF)
deserialised_response = rest_client._parse_response(resp)
self.assertEqual(deserialised_response.status, Status.STATUS_SUCCESS)
self.assertEqual(deserialised_response.data["req_guid"], get_static_uuid())
self.assertEqual(deserialised_response.sent_time, get_static_time())
self.assertEqual(deserialised_response.code, Code.CODE_OK)

def _get_rest_client(self, serialiser=Serialiser.JSON, wire_type=WireType.JSON):
client_config = RestClientConfigBuilder(). \
Expand Down

0 comments on commit 505cedc

Please sign in to comment.