Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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()
# Enable mock engine
pook.on()
(pook.post('httpbin.org/post')
.jsonschema(schema)
.reply(204)
.json({'error': 'simulated'}))
res = requests.post('http://httpbin.org/post',
data=json.dumps({'foo': 'bar'}))
print('Status:', res.status_code)
print('Body:', res.json())
print('Is done:', pook.isdone())
print('Pending mocks:', pook.pending_mocks())
@pook.get('http://httpbin.org/status/500', reply=204)
@pook.get('http://httpbin.org/status/400', reply=200, persist=True)
def fetch(url):
return requests.get(url)
# Test function
res = fetch('http://httpbin.org/status/400')
print('#1 status:', res.status_code)
res = fetch('http://httpbin.org/status/500')
print('#2 status:', res.status_code)
print('Is done:', pook.isdone())
print('Pending mocks:', pook.pending_mocks())
# Disable mock engine
pook.off()
# Test real request
res = requests.get('http://httpbin.org/status/400')
print('Test status:', res.status_code)
pook.on()
mock = pook.get('http://httpbin.org/ip',
reply=404, response_type='json',
response_json={'error': 'not found'})
conn = http.client.HTTPConnection('httpbin.org')
conn.request('GET', '/ip')
res = conn.getresponse()
print('Status:', res.status, res.reason)
print('Headers:', res.headers)
print('Body:', res.read())
print('Mock calls:', mock.calls)
print('Is done:', pook.isdone())
print('Pending mocks:', pook.pending_mocks())
print('Unmatched requests:', pook.unmatched_requests())
# Enable mock engine
pook.on()
pook.get('httpbin.org/ip',
reply=403, response_type='json',
response_headers={'pepe': 'lopez'},
response_json={'error': 'not found'},
callback=on_match)
res = requests.get('http://httpbin.org/ip')
print('Status:', res.status_code)
print('Headers:', res.headers)
print('Body:', res.json())
print('Is done:', pook.isdone())
print('Pending mocks:', pook.pending_mocks())
print('Unmatched requests:', pook.unmatched_requests())
pook.get('httpbin.org/headers',
reply=404, response_type='json',
response_headers={'server': 'pook'},
response_json={'error': 'not found'})
res = requests.get('http://httpbin.org/ip')
print('Status:', res.status_code)
print('Headers:', res.headers)
print('Body:', res.json())
res = requests.get('http://httpbin.org/headers')
print('Status:', res.status_code)
print('Headers:', res.headers)
print('Body:', res.json())
print('Is done:', pook.isdone())
print('Pending mocks:', pook.pending_mocks())
print('Unmatched requests:', pook.unmatched_requests())
(pook.get('httpbin.org')
.headers({'Client': 'requests'})
.persist()
.reply(400)
.headers({'server': 'pook'})
.json({'error': 'simulated'}))
res = requests.get('http://httpbin.org',
headers={'Client': 'requests'})
print('Status:', res.status_code)
print('Headers:', res.headers)
print('Body:', res.json())
print('Is done:', pook.isdone())
print('Pending mocks:', pook.pending_mocks())
.json({'foo': 'bar'})
.type('json')
.header('Client', 'requests')
.reply(204)
.headers({'server': 'pook'})
.json({'error': 'simulated'}))
res = requests.post('http://httpbin.org/post',
data=json.dumps({'foo': 'bar'}),
headers={'Client': 'requests',
'Content-Type': 'application/json'})
print('Status:', res.status_code)
print('Body:', res.json())
print('Is done:', pook.isdone())
print('Pending mocks:', pook.pending_mocks())