Esempio n. 1
0
def test_MockApp_assert_has_calls_unordered_ok():
    app = MockApp()
    with mock_server(app) as port:
        urlopen('http://127.0.0.1:%d/hello' % port)
        urlopen('http://127.0.0.1:%d/cruel' % port)
        urlopen('http://127.0.0.1:%d/world' % port)
    app.assert_has_calls(['GET /cruel', 'GET /hello'], any_order=True)
Esempio n. 2
0
def test_MockApp_assert_any_call():
    app = MockApp()
    with mock_server(app) as port:
        urlopen('http://127.0.0.1:%d/hello' % port)
        urlopen('http://127.0.0.1:%d/cruel' % port)
        urlopen('http://127.0.0.1:%d/world' % port)
    app.assert_any_call('GET /cruel')
Esempio n. 3
0
def test_MockApp_assert_has_calls_unordered_fails():
    app = MockApp()
    with mock_server(app) as port:
        urlopen('http://127.0.0.1:%d/hello' % port)
        urlopen('http://127.0.0.1:%d/world' % port)
    assert_raises(AssertionError, lambda:
        app.assert_has_calls(['GET /cruel', 'GET /planet'], any_order=True))
Esempio n. 4
0
def test_MockApp_assert_called_once_with_two_calls():
    app = MockApp()
    with mock_server(app) as port:
        urlopen('http://127.0.0.1:%d/hello' % port)
        urlopen('http://127.0.0.1:%d/world' % port)
    assert_raises(AssertionError, lambda:
        app.assert_called_once_with('GET /world'))
Esempio n. 5
0
def test_MockApp_assert_called_once_with_two_calls():
    app = MockApp()
    with mock_server(app) as port:
        urlopen('http://127.0.0.1:%d/hello' % port)
        urlopen('http://127.0.0.1:%d/world' % port)
    assert_raises(AssertionError,
                  lambda: app.assert_called_once_with('GET /world'))
Esempio n. 6
0
def test_MockApp_assert_any_call():
    app = MockApp()
    with mock_server(app) as port:
        urlopen('http://127.0.0.1:%d/hello' % port)
        urlopen('http://127.0.0.1:%d/cruel' % port)
        urlopen('http://127.0.0.1:%d/world' % port)
    app.assert_any_call('GET /cruel')
Esempio n. 7
0
def test_MockApp_assert_has_calls_ordered_ok():
    app = MockApp()
    with mock_server(app) as port:
        urlopen('http://127.0.0.1:%d/hello' % port)
        urlopen('http://127.0.0.1:%d/cruel' % port)
        urlopen('http://127.0.0.1:%d/world' % port)
    app.assert_has_calls(['GET /cruel', 'GET /world'], any_order=False)
Esempio n. 8
0
def test_MockApp_assert_has_calls_unordered_fails():
    app = MockApp()
    with mock_server(app) as port:
        urlopen('http://127.0.0.1:%d/hello' % port)
        urlopen('http://127.0.0.1:%d/world' % port)
    assert_raises(
        AssertionError,
        lambda: app.assert_has_calls(['GET /cruel', 'GET /planet'],
                                     any_order=True))
Esempio n. 9
0
def test_MockApp_assert_called_once_with():
    app = MockApp()
    with mock_server(app) as port:
        urlopen('http://127.0.0.1:%d/hello' % port)
    app.assert_called_once_with('GET /hello')
Esempio n. 10
0
def test_MockApp_custom_headers():
    app = MockApp(headers=[('Authorization', 'Bearer abc')])
    with mock_server(app) as port:
        resp = urlopen('http://127.0.0.1:%d/world' % port)
        assert resp.headers['authorization'] == 'Bearer abc', resp.headers
    app.assert_any_call('GET /world')
Esempio n. 11
0
def test_MockApp_custom_body():
    app = MockApp(body=b'oh noes')
    with mock_server(app) as port:
        resp = urlopen('http://127.0.0.1:%d/world' % port).read()
        assert resp == b'oh noes', 'got {!r}'.format(resp)
    app.assert_any_call('GET /world')
Esempio n. 12
0
def test_MockApp_custom_response():
    app = MockApp(response='403 Forbidden')
    with mock_server(app) as port:
        assert_raises(HTTPError, lambda:
            urlopen('http://127.0.0.1:%d/world' % port))
    app.assert_any_call('GET /world')
Esempio n. 13
0
def test_MockApp_assert_called_once_with():
    app = MockApp()
    with mock_server(app) as port:
        urlopen('http://127.0.0.1:%d/hello' % port)
    app.assert_called_once_with('GET /hello')
Esempio n. 14
0
def test_MockApp_custom_headers():
    app = MockApp(headers=[('Authorization', 'Bearer abc')])
    with mock_server(app) as port:
        resp = urlopen('http://127.0.0.1:%d/world' % port)
        assert resp.headers['authorization'] == 'Bearer abc', resp.headers
    app.assert_any_call('GET /world')
Esempio n. 15
0
def test_MockApp_custom_body():
    app = MockApp(body=b'oh noes')
    with mock_server(app) as port:
        resp = urlopen('http://127.0.0.1:%d/world' % port).read()
        assert resp == b'oh noes', 'got {!r}'.format(resp)
    app.assert_any_call('GET /world')
Esempio n. 16
0
def test_MockApp_custom_response():
    app = MockApp(response='403 Forbidden')
    with mock_server(app) as port:
        assert_raises(HTTPError,
                      lambda: urlopen('http://127.0.0.1:%d/world' % port))
    app.assert_any_call('GET /world')