I lose when writing a test case for the UserCompanyRateLimitValidation class . It's hard for me to mock a class that is created from within this class.
class UserCompanyRateLimitValidation:
def __init__(self, user_public_key):
self.adapter = UserAdapter(user_public_key)
container = self.adapter.get_user_company_rate_limit()
super(UserCompanyRateLimitValidation, self).__init__(container,\
UserCompanyRateLimitValidation.TYPE)
I need to check this class. I wrote a test case like this. I tried to make fun of the UserAdapter class, but I cannot do it completely.
def test_case_1():
self.user_public_key = 'TEST_USER_PUBLIC_KEY_XXXXXX1234567890XXXXX'
UserAdapter_mock = mock(UserAdapter)
when(UserAdapter_mock).get_user_company_rate_limit().\
thenReturn(get_fake_container_object())
self.test_obj = UserCompanyRateLimitValidation(self.user_public_key)
Here, if you see that I was mocking the get_user_company_rate_limit () call from the function being tested, container = self.adapter.get_user_company_rate_limit()
but I still can’t figure out how I can mock this call,
self.adapter = UserAdapter(user_public_key)
source
share