def test_list():
    client = app.test_client()
    response = client.post("/register/", data="http://example.com")
    reference = response.get_data()

    response = client.get("/list/")
    assert response.get_data() == "{}: {}\n".format(reference, "http://example.com")
def test_unknown_error(db):
    endpoint = Endpoint(ref='ref', url='url')
    db.session.add(endpoint)
    db.session.commit()

    with mock.patch('adyen_notification_proxy.proxy.requests') as requests:
        client = app.test_client()
        data = {'merchantReference': 'ref'}
        requests.post.side_effect = Exception()
        response = client.post('/adyen/', data=data)
        assert "[accepted]" in response.get_data()
def test_empty(db):
    with mock.patch('adyen_notification_proxy.proxy.requests') as requests:
        client = app.test_client()
        response = client.post('/adyen/', data={'merchantReference': 'foo'})
        assert not requests.post.called
        assert "[accepted]" in response.get_data()
def test_index():
    client = app.test_client()
    response = client.get("/")
    assert "display this help" in response.get_data()
def test_register_bad_data():
    client = app.test_client()
    response = client.post("/register/")
    assert response.status_code == 400
def test_register_duplicate(db):
    client = app.test_client()
    response = client.post("/register/", data="http://example.com")
    response = client.post("/register/", data="http://example.com")
    assert response.status_code == 200
    assert db.session.query(Endpoint).count() == 1