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_get_access_token_success(queue_processor): with mock_server(mock_token_request_success) as port: test_server_url = 'http://127.0.0.1:{}'.format(port) queue_processor.WECHAT_URL = test_server_url token_result = queue_processor.get_access_token() assert token_result != None assert token_result == 'TEST_ACCESS_TOKEN'
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_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_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_start_stop(): svr = mock_server(simple_server.demo_app) port = svr.start() assert_server_running(port) svr.stop() assert_port_closed(port)
def test_contextmanager(): with mock_server(simple_server.demo_app) as port: assert_server_running(port) assert_port_closed(port)
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')
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_get_access_token_error(queue_processor): with mock_server(mock_token_request_error) as port: test_server_url = 'http://127.0.0.1:{}'.format(port) queue_processor.WECHAT_URL = test_server_url token_result = queue_processor.get_access_token() assert token_result == None
def test_process_message_error(queue_processor, message): with mock_server(mock_send_message_request_error) as port: test_server_url = 'http://127.0.0.1:{}'.format(port) queue_processor.WECHAT_URL = test_server_url send_result = queue_processor.process_message(message) assert send_result == False