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)
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')
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))
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'))
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)
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))
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')
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')
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')
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')