I have a class called 'OrderClient':
import some.api.location.ApiClient
class OrderClient:
def __init__(self):
api_client = ApiClient()
def _request(self, method)
return getattr(api_client, method)
def call_get_list_of_things(self):
response = self._request('get_list_of_things')
return response # this will return a list e.g [1, 2, 3, 4]
I want to test this class, specifically the function call_get_list_of_things which gets a list from ApiClient. ApiClient is an object.
Here's what I have:
import unittest
from unittest.mock import MagicMock
from unittest.mock import patch
import OrderClient
class TestOrderClient(unittest.TestCase):
def setUp(self):
self.client = OrderClient()
@patch(OrderClient.ApiClient)
def test_get_list_of_things(self, api_client):
api_client.get_list_of_things = MagicMock(return_value='{somefakevalues}')
self.assert(self.client.call_get_list_of_things(), [1, 2, 3, 4]
So I don't want to call the API to obtain the structure of OrderClient. I want to specify what the return_value is when get_list_of_things is called. I'll then assert it with the list [1, 2, 3, 4] to check if it's correct. Let's assume get_list_of_things returns [1, 2, 3, 4]. But since it's an object, how do I structure the return_value code? How do I test an object, not explicitly some json? Is the API actually providing me with some json modelled into an object, but I'm just missing something?
Would really appreciate the help, thank you!
Aucun commentaire:
Enregistrer un commentaire