samedi 28 mars 2020

Mocking multiple API calls in my class and writing a test

So, I am trying to mock some API's in my class, the code looks something like this.

import requests
class myclass:
  def A(self, data):
    response = requests.get("some_url", params)
    if response.data["has_value"]:
      new_response = requests.get("some_url", params)
      **do some validation on data recieved**
  def B(self, data):
    response = requests.get("some_url", params)
    **do some validation on data recieved**
  def _run(self):
    **some code**
    self.A(data)
    self.B(data)

m = myclass()
m.run()

I am trying to test for these and need some help with it. while doing validations we change some fields in data, and I have to verify if the data is correct. how can this be done? Thank you.

Aucun commentaire:

Enregistrer un commentaire