Skip to content

Create mock.py#2

Open
wanda-carlson wants to merge 1 commit intomainfrom
wanda-carlson-patch-2
Open

Create mock.py#2
wanda-carlson wants to merge 1 commit intomainfrom
wanda-carlson-patch-2

Conversation

@wanda-carlson
Copy link
Contributor

No description provided.

@@ -0,0 +1,31 @@
# mock_script.py

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

def fetch_data_from_api(url):
response = requests.get(url)
if response.status_code == 200:
return response.json()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

@wanda-carlson wanda-carlson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

af

else:
return {"error": f"Failed to fetch data. Status code: {response.status_code}"}

if __name__ == "__main__":
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mocked_get.return_value.status_code = 200
mocked_get.return_value.json.return_value = mock_response

result = fetch_data_from_api("https://mockapi.test/data")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link

@henry-richard henry-richard left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dsafafsd

@@ -0,0 +1,31 @@
# mock_script.py

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


with patch('requests.get') as mocked_get:
mocked_get.return_value.status_code = 200
mocked_get.return_value.json.return_value = mock_response

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link

@henry-richard henry-richard left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

efwaaweaerw

@@ -0,0 +1,31 @@
# mock_script.py

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mocked_get.return_value.json.return_value = mock_response

result = fetch_data_from_api("https://mockapi.test/data")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants