forked from h2non/pook
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnose_example.py
42 lines (31 loc) · 950 Bytes
/
nose_example.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# -*- coding: utf-8 -*-
import pook
import requests
@pook.activate
def test_simple_pook_request():
pook.get('server.com/foo').reply(204)
res = requests.get('http://server.com/foo')
assert 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
@pook.get('server.com/foo', reply=204)
def test_decorator():
res = requests.get('http://server.com/foo')
assert res.status_code == 204
def test_context_manager():
with pook.use():
pook.get('server.com/bar', reply=204)
res = requests.get('http://server.com/bar')
assert res.status_code == 204
@pook.on
def test_no_match_exception():
pook.get('server.com/bar', reply=204)
try:
requests.get('http://server.com/baz')
except Exception:
pass
else:
raise RuntimeError('expected to fail')