Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
@pook.get('server.com/foo', reply=204)
def test_decorator(self):
res = requests.get('http://server.com/foo')
self.assertEqual(res.status_code, 204)
def test_pook_engine():
url = 'http://twitter.com/api/1/foobar'
status = 404
response_json = {'error': 'foo'}
mock = pook.get(
url,
headers={'content-type': 'application/json'},
reply=status,
response_json=response_json,
)
mock.persist()
requests.get(url)
assert mock.calls == 1
resp = requests.get(url)
assert resp.status_code == status
assert resp.json() == response_json
assert mock.calls == 2
def test_enable_engine():
pook.get('server.com/foo').reply(204)
res = requests.get('http://server.com/foo')
assert res.status_code == 204
def test_context_manager():
with pook.use():
pook.get('server.com/baz', reply=204)
res = requests.get('http://server.com/baz')
assert res.status_code == 204
times=1,
)
patch_regex = r"[0-9]+(((-alpha|-beta|-rc)[0-9]+)|(?P-dev))?"
# pook does not implement urllib3's retry logic so this first request will always return None during tests
patch = tfwrapper.search_on_github(repo, "0.12", patch_regex, "14")
assert patch is None
patch = tfwrapper.search_on_github(repo, "0.12", patch_regex, "14")
assert patch == "14"
patch = tfwrapper.search_on_github(repo, "0.12", patch_regex, "")
assert patch == "19"
assert pook.isdone()
assert not pook.pending_mocks()
assert not pook.unmatched_requests()
)
patch_regex = r"[0-9]+(((-alpha|-beta|-rc)[0-9]+)|(?P-dev))?"
# pook does not implement urllib3's retry logic so this first request will always return None during tests
patch = tfwrapper.search_on_github(repo, "0.12", patch_regex, "14")
assert patch is None
patch = tfwrapper.search_on_github(repo, "0.12", patch_regex, "14")
assert patch == "14"
patch = tfwrapper.search_on_github(repo, "0.12", patch_regex, "")
assert patch == "19"
assert pook.isdone()
assert not pook.pending_mocks()
assert not pook.unmatched_requests()
)
patch_regex = r"[0-9]+(((-alpha|-beta|-rc)[0-9]+)|(?P-dev))?"
# pook does not implement urllib3's retry logic so this first request will always return None during tests
patch = tfwrapper.search_on_github(repo, "0.12", patch_regex, "14")
assert patch is None
patch = tfwrapper.search_on_github(repo, "0.12", patch_regex, "14")
assert patch == "14"
patch = tfwrapper.search_on_github(repo, "0.12", patch_regex, "")
assert patch == "19"
assert pook.isdone()
assert not pook.pending_mocks()
assert not pook.unmatched_requests()
@pook.on
def test_no_match_exception(self):
pook.get('server.com/bar', reply=204)
try:
requests.get('http://server.com/baz')
except Exception:
pass
else:
raise RuntimeError('expected to fail')
@pook.on
def test_simple_pook_request(self):
pook.get('server.com/foo').reply(204)
res = requests.get('http://server.com/foo')
self.assertEqual(res.status_code, 204)
@pook.on
def test_enable_engine():
pook.get('server.com/foo').reply(204)
res = requests.get('http://server.com/foo')
assert res.status_code == 204