I'm trying to mock the object, But it's not happening can anyone help me
payment_gateway
----payment.py
class Razz:
def __init__(self) -> None:
self.base_url = "https://api.example.com/v1"
self.api_key = os.environ["API_KEY"]
self.api_secret = os.environ["SECRET"]
self.kh_account_number = os.environ["ACCOUNT_NUMBER"]
def create_contact(self):
res = request.post(usrl=f"{base_url}/contact", data=payload, auth(self.api_key,self.api_secret)
return "id"
And am importing this class on another fille i.e event_bank_deails.py
from payment_gateway.payment import Razz, PaymentGatewayErrors
PAYMENT_GATEWAY= Razz()
def update_bank_detials(request: Request) -> Response:
contact_id = PAYMENT_GATEWAY.create_contact(body, event_id) # Creating contact
fund_id = PAYMENT_GATEWAY.create_account(contact_id, body) # Creating fund account on razorpayX
return resposes
TestCases file
@patch("event_bank_details.event_bank_details.Razz")
@pytest.mark.parametrize("input, expected_op", UPDATE_EVENT_BANK_DETAILS_INPUT)
def test_update_event_bank_details(mock_email, mock_object, input, expected_op):
from event_bank_details.event_bank_details import update_bank_detials
# mock_object.return_value.create_contact.return_value = None
# mock_object.return_value.create_account.create_account = None
response = update_bank_detials(input)
response.prepare()
response_dict = response.get()
assert response_dict["statusCode"] == expected_op
And then am writing test cases for the update_bank_details function It's throwing an error invalid
API_KEYand
API_SECREATEHow can I mock the
Razzclass
init()` call on update_bank_details function???