Example #1
0
def test_post_landings_success(api_url):
    landoapi = LandoAPIClient(api_url, auth0_access_token='access_token')
    with requests_mock.mock() as m:
        m.post(api_url + '/landings',
               additional_matcher=match_landing_request('D1', 1, 'confirmed'),
               json=canned_landoapi.POST_LANDINGS_SUCCESS)
        assert landoapi.post_landings('D1', 1, 'confirmed')
def test_render_valid_revision_logged_in(app, api_url):
    with requests_mock.mock() as m:
        m.get(
            api_url + '/revisions/D1',
            json=canned_landoapi.GET_REVISION_DEFAULT
        )
        m.get(
            api_url + '/landings?revision_id=D1',
            json=canned_landoapi.GET_LANDINGS_DEFAULT
        )
        m.post(
            api_url + '/landings/dryrun',
            additional_matcher=match_landing_request('D1', 1),
            json=canned_landoapi.POST_LANDINGS_DRYRUN_SUCCESS
        )

        with app.test_client() as client:
            with client.session_transaction() as session:
                session['access_token'] = canned_auth0.VALID_ACCESS_TOKEN
                session['id_token'] = canned_auth0.VALID_ID_TOKEN
                session['userinfo'] = canned_auth0.VALID_USERINFO

                # Pretend we don't need to refresh.
                session['id_token_jwt'] = 'bogus'
                session['last_authenticated'] = time.time() + 100000

            response = client.get('/revisions/D1/')
    assert response.status_code == 200
Example #3
0
def test_post_landings_dryrun_no_access_token(api_url):
    landoapi = LandoAPIClient(api_url, auth0_access_token=None)
    with requests_mock.mock() as m:
        m.post(api_url + '/landings/dryrun',
               additional_matcher=match_landing_request('D1', 1),
               json=canned_landoapi.POST_LANDINGS_DRYRUN_SUCCESS)
        with pytest.raises(AssertionError):
            landoapi.post_landings_dryrun('D1', 1)
Example #4
0
def test_post_landings_dryrun_success(api_url):
    landoapi = LandoAPIClient(api_url, auth0_access_token='access_token')
    with requests_mock.mock() as m:
        m.post(api_url + '/landings/dryrun',
               additional_matcher=match_landing_request('D1', 1),
               json=canned_landoapi.POST_LANDINGS_DRYRUN_SUCCESS)
        result = landoapi.post_landings_dryrun('D1', 1)

    assert canned_landoapi.POST_LANDINGS_DRYRUN_SUCCESS == result
Example #5
0
def test_post_landings_dryrun_connection_error(api_url):
    landoapi = LandoAPIClient(api_url, auth0_access_token='access_token')
    with requests_mock.mock() as m:
        m.post(api_url + '/landings/dryrun',
               additional_matcher=match_landing_request('D1', 1),
               exc=requests.exceptions.ConnectTimeout)
        with pytest.raises(UIError) as exc_info:
            landoapi.post_landings_dryrun('D1', 1)

    assert 'Failed to connect to Lando API.' in exc_info.value.title
Example #6
0
def test_post_landings_http_error_without_valid_response(api_url):
    landoapi = LandoAPIClient(api_url, auth0_access_token='access_token')
    with requests_mock.mock() as m:
        m.post(api_url + '/landings',
               additional_matcher=match_landing_request('D1', 1),
               status_code=400)
        with pytest.raises(LandingSubmissionError) as exc_info:
            landoapi.post_landings('D1', 1, None)

    assert 'Lando API did not respond successfully.' in exc_info.value.error
Example #7
0
def test_post_landings_dryrun_http_error_without_valid_response(api_url):
    landoapi = LandoAPIClient(api_url, auth0_access_token='access_token')
    with requests_mock.mock() as m:
        m.post(api_url + '/landings/dryrun',
               additional_matcher=match_landing_request('D1', 1),
               status_code=400)
        with pytest.raises(UIError) as exc_info:
            landoapi.post_landings_dryrun('D1', 1)

    assert 'Lando API did not respond successfully.' == exc_info.value.title
    assert 400 == exc_info.value.status_code
Example #8
0
def test_post_landings_http_error_with_valid_response(api_url):
    landoapi = LandoAPIClient(api_url, auth0_access_token='access_token')
    with requests_mock.mock() as m:
        m.post(api_url + '/landings',
               additional_matcher=match_landing_request('D1', 1),
               json=canned_landoapi.PROBLEM_BAD_REQUEST,
               status_code=400)
        with pytest.raises(LandingSubmissionError) as exc_info:
            landoapi.post_landings('D1', 1, None)

    assert 'Bad Request: Bad Request Detail' in exc_info.value.error
Example #9
0
def test_post_landings_dryrun_http_error_with_valid_response(api_url):
    landoapi = LandoAPIClient(api_url, auth0_access_token='access_token')
    with requests_mock.mock() as m:
        m.post(api_url + '/landings/dryrun',
               additional_matcher=match_landing_request('D1', 1),
               json=canned_landoapi.PROBLEM_BAD_REQUEST,
               status_code=400)
        with pytest.raises(UIError) as exc_info:
            landoapi.post_landings_dryrun('D1', 1)

    assert 'Bad Request' in exc_info.value.title
    assert 'Bad Request Detail' in exc_info.value.message
    assert 400 == exc_info.value.status_code