I have an APIView that hits an external API itself to aggregate results. I've defined it as such:
class SampleView(APIView):
api = query_api()
def get(self, request, id):
result = self.api.query(id)
return HttpResponse(status=200)
I have a mocked out API to make this testable without having that external API as a dependency in my unit tests. I would like to do something like SampleView.api = fake_api() before running unit tests.
How do I swap out a single attribute like this, in order to replace a concrete class with a mocked out one for unit testing?
Aucun commentaire:
Enregistrer un commentaire