Created
December 14, 2018 13:32
-
-
Save nikolaik/9aa9ea8c0b46537faa8a967c05c46e27 to your computer and use it in GitHub Desktop.
mock example
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 requests | |
def call_api(text): | |
print('calling example.com') | |
return requests.post('http://example.com', data=text).text | |
def translate_bot(): | |
texts = ['jeg', 'vet', 'ikke', 'hvordan', 'dette', 'fungerer'] | |
return all(['Example' not in call_api(t) for t in texts]) |
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
from unittest.mock import patch | |
from bot import translate_bot | |
@patch('bot.call_api') | |
def test_translate_bot(mockAPICall): | |
mockAPICall.return_value = 'schmø' | |
b = translate_bot() | |
assert b | |
assert mockAPICall.call_count == 6 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment