Skip to content

Commit

Permalink
feat(example): add nose example
Browse files Browse the repository at this point in the history
  • Loading branch information
h2non committed Dec 8, 2016
1 parent 3129a64 commit 2799da1
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 1 deletion.
7 changes: 7 additions & 0 deletions docs/examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,13 @@ Time TTL limited mock



``py.test`` integration
^^^^^^^^^^^^^^^^^^^^^^^^

.. literalinclude:: ../examples/pytest_example.py



Simulated error exception on mock matching
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Expand Down
40 changes: 40 additions & 0 deletions examples/nose_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# -*- 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


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


def test_no_match_exception():
pook.get('server.com/bar', reply=204)
try:
requests.get('http://server.com/baz')
except:
pass
else:
raise RuntimeError('expected to fail')
2 changes: 1 addition & 1 deletion tests/integration/engines/nose_suite.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-

import requests
import pook
import requests


@pook.activate
Expand Down

0 comments on commit 2799da1

Please sign in to comment.