How to use pook - 10 common examples

To help you get started, we’ve selected a few pook examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github h2non / pook / tests / integration / engines / unittest_suite.py View on Github external
    @pook.get('server.com/foo', reply=204)
    def test_decorator(self):
        res = requests.get('http://server.com/foo')
        self.assertEqual(res.status_code, 204)
github mindflayer / python-mocket / tests / tests27 / test_pook.py View on Github external
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
github h2non / pook / tests / integration / engines / nose_suite.py View on Github external
def test_enable_engine():
    pook.get('server.com/foo').reply(204)
    res = requests.get('http://server.com/foo')
    assert res.status_code == 204
github h2non / pook / examples / pytest_example.py View on Github external
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
github claranet / terraform-wrapper / test_cache_requests.py View on Github external
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()
github claranet / terraform-wrapper / test_cache_requests.py View on Github external
)

            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()
github claranet / terraform-wrapper / test_cache_requests.py View on Github external
)

            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()
github h2non / pook / tests / integration / engines / unittest_suite.py View on Github external
    @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')
github h2non / pook / tests / integration / engines / unittest_suite.py View on Github external
    @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)
github h2non / pook / tests / integration / engines / nose_suite.py View on Github external
@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