예제 #1
0
async def bot_fixture(event_loop):
    """ Bot fixture """
    pook.on()
    _bot = Bot(API_TOKEN)
    yield _bot
    await _bot.close()
    pook.off()
예제 #2
0
def test_persistent():
    pook.on()
    pook.get("https://www.example.com").persist().reply(200).json(
        {"data": True})
    for counter in range(5):
        res = requests.get("https://www.example.com")
        assert res.json().get('data')
    pook.off()
예제 #3
0
def test_pook_whitelist():
    pook.on()
    # pook.enable_network("www.example.com")  # Broken, at least on Python 3.7
    pook.enable_network()
    res = requests.get(
        "https://www.example.com")  # Unmatched, so it is redirected
    with pytest.raises(Exception):
        assert res.json()
    pook.off()
예제 #4
0
 def client():
     import pook  # Alternatively, one could use pook decorators, etc.
     pook.on()
     # Still need to write this for every API call in the server or at least this test suite
     (pook.get("https://www.behance.net/v2/projects?api_key=u_n_m_o_c_k_200")
      .persist()
      .reply(200)
      .json({"projects": "lazy"}))
     yield app.test_client()
     pook.off()
예제 #5
0
def test_pook_content_matching():
    pook.on()
    pook.get("https://www.example.com").times(2).body("abc").reply(200).json(
        {"data": True})
    res = requests.get("https://www.example.com", data="abc")
    assert res.json().get('data')
    with pytest.raises(Exception):
        requests.get("https://www.example.com",
                     data="def")  # Will throw once again
    pook.off()
예제 #6
0
def test_pook_pending():
    pook.on()
    pook.get("https://www.example.com").times(2).reply(200).json(
        {"data": True})
    for counter in [1, 0]:
        res = requests.get("https://www.example.com")
        assert res.json().get('data')
        assert pook.pending() == counter

    with pytest.raises(Exception):  # Will throw as there's no mocks
        res = requests.get("https://www.example.com")

    pook.off()
예제 #7
0
}).json({'body': 'FIRST'}))
# Register with same URL but diff BODY
(pook.post('httpbin.org/post').json({
    'foo': 'ha'
}).type('json').header('Client', 'requests').reply(204).headers({
    'server':
    'pook'
}).json({'body': 'SECOND'}))

res = requests.post('http://httpbin.org/post',
                    data=json.dumps({'foo': 'bar'}),
                    headers={
                        'Client': 'requests',
                        'Content-Type': 'application/json'
                    })
print(res.status_code)
print(res.headers)
print(res.content)

res = requests.post('http://httpbin.org/post',
                    data=json.dumps({'foo': 'ha'}),
                    headers={
                        'Client': 'requests',
                        'Content-Type': 'application/json'
                    })
print(res.status_code)
print(res.headers)
print(res.content)

pook.off()
예제 #8
0
def test_pook_status():
    pook.on()
    assert pook.isactive()
    pook.off()
    assert not pook.isactive()
예제 #9
0
def test_pook_off():
    pook.off()  # Called off.
    with pytest.raises(pook.exceptions.PookNoMatches):  # Still raises even though called off!
        res = requests.get("http://www.i-forgot-to-set-my-env-variable.com/")