Created
November 24, 2020 22:24
-
-
Save hugoleodev/40e98b39e66389df9ea89d6c6d1ad220 to your computer and use it in GitHub Desktop.
tests.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import unittest | |
import responses | |
import json | |
from unittest.mock import patch | |
from main import httpbin_requester, fetch_google_play_installs | |
class HTTPBinRequesterTestCase(unittest.TestCase): | |
@responses.activate | |
def test_httpbin_requester_should_return_the_right_message(self): | |
responses.add(responses.GET, "https://httpbin.org/uuid", json={'uuid': '04ea103d-bf5a-4b6b-be92-ba53538b1815'}, status=200) | |
self.assertEqual("New uuid generated by httpbin: 04ea103d-bf5a-4b6b-be92-ba53538b1815", httpbin_requester()) | |
@responses.activate | |
def test_httpbin_requester_with_404_response(self): | |
responses.add(responses.GET, "https://httpbin.org/uuid", status=404) | |
self.assertEqual("HTTPBin Request Error", httpbin_requester()) | |
@responses.activate | |
def test_httpbin_requester_with_server_error_response(self): | |
responses.add(responses.GET, "https://httpbin.org/uuid", status=500) | |
self.assertEqual("HTTPBin Server Error", httpbin_requester()) | |
class GooglePlaysInstallsTestCase(unittest.TestCase): | |
@patch('main.app') | |
def test_fetch_google_play_installs(self, _google_play_app): | |
fetch_google_play_installs("com.globo.ge.app") | |
_google_play_app.assert_called_with("com.globo.ge.app", lang='pt-br', country='br') | |
with open("google_play_response_fixture.json", "r") as google_play_fixture: | |
_google_play_app.return_value = json.load(google_play_fixture) | |
self.assertEqual("25.000.000+", fetch_google_play_installs("com.globo.ge.app")) | |
if __name__ == "__main__": | |
unittest.main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment