Skip to content

Instantly share code, notes, and snippets.

@nikolaik
Created December 14, 2018 13:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nikolaik/9aa9ea8c0b46537faa8a967c05c46e27 to your computer and use it in GitHub Desktop.
Save nikolaik/9aa9ea8c0b46537faa8a967c05c46e27 to your computer and use it in GitHub Desktop.
mock example
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])
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