Exemplo 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)
Exemplo n.º 2
0
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'
Exemplo n.º 3
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'))
Exemplo n.º 4
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')
Exemplo n.º 5
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))
Exemplo n.º 6
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)
Exemplo n.º 7
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')
Exemplo n.º 8
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'))
Exemplo n.º 9
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))
Exemplo n.º 10
0
def test_start_stop():
    svr = mock_server(simple_server.demo_app)
    port = svr.start()
    assert_server_running(port)
    svr.stop()
    assert_port_closed(port)
Exemplo n.º 11
0
def test_contextmanager():
    with mock_server(simple_server.demo_app) as port:
        assert_server_running(port)
    assert_port_closed(port)
Exemplo n.º 12
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')
Exemplo n.º 13
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')
Exemplo n.º 14
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')
Exemplo n.º 15
0
def test_start_stop():
    svr = mock_server(simple_server.demo_app)
    port = svr.start()
    assert_server_running(port)
    svr.stop()
    assert_port_closed(port)
Exemplo n.º 16
0
def test_contextmanager():
    with mock_server(simple_server.demo_app) as port:
        assert_server_running(port)
    assert_port_closed(port)
Exemplo n.º 17
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')
Exemplo n.º 18
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')
Exemplo n.º 19
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')
Exemplo n.º 20
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')
Exemplo n.º 21
0
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
Exemplo n.º 22
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')
Exemplo n.º 23
0
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