I am working on a personal project that uses the Github API. I currently have this function as a member of a class.
def get_user_data(self):
url = self.GITHUB_API_URL + self.user_name
try:
response = requests.get(url, verify=True)
if response.status_code != 200:
raise RuntimeError('Status: ', response.status_code, 'Problem with the request.')
except RuntimeError as error:
print(error)
data = response.json()
return data
I heard you can use the python library
from unittest.mock import patch
or MagicMock to create the mocks after reading this blog post.
Although this is all confusing to me coming after learning unittesting in Java with Mockito. If anyone can clarify for me how to create mocks within Python unittests in a way I can understand I would appreciate it.
Aucun commentaire:
Enregistrer un commentaire