def test_mumps_immunity_results(client, app_specific_illnesses, monkeypatch,
                                request_data,
                                response_status, mumps_probability):
    """Test all normally active components. Use range of normal values and edge cases."""

    def mocked_one_dose_immunity(*ignored_args):
        return 1.00  # 1.00 for one shot

    def mocked_two_dose_immunity(*ignored_args):
        return 2.00  # 2.00 for two shots

    monkeypatch.setattr(illnesses.mumps, 'one_dose_immunity', mocked_one_dose_immunity)
    monkeypatch.setattr(illnesses.mumps, 'two_dose_immunity', mocked_two_dose_immunity)

    app = app_specific_illnesses(illnesses=[Mumps])
    with app.test_client() as test_client:
        flat_request_data = ImmutableMultiDict(flatten_dict(request_data))

        assert test_client.get('immunity/').status_code == 200
        response = test_client.post(
            'immunity/', data=flat_request_data)
        assert 'http://localhost/immunity/results/' == response.headers['Location']

        response = test_client.get('http://localhost/immunity/results/', follow_redirects=True)
        assert response.status_code == response_status
        # Use probability of mumps immunity to test response content.
        assert f'{mumps_probability}'.encode('utf-8') in response.data
def test_immunity_validate_measles_input(client, app_specific_illnesses,
                                         request_data, messages):
    app = app_specific_illnesses(illnesses=[Measles])
    with app.test_client() as test_client:
        flat_request_data = ImmutableMultiDict(flatten_dict(request_data))

    assert test_client.get('immunity/').status_code == 200

    response = test_client.post('immunity/', data=flat_request_data)

    for error in messages:
        assert error in response.data
Exemplo n.º 3
0
def test_immunity_validate_common_data_input(client, app_specific_illnesses,
                                             request_data,
                                             messages):
    """Validate birth year, shared data."""
    app = app_specific_illnesses(illnesses=[])
    with app.test_client() as test_client:
        flat_request_data = ImmutableMultiDict(flatten_dict(request_data))

        assert test_client.get('immunity/').status_code == 200

        response = test_client.post(
            'immunity/', data=flat_request_data)
        for error in messages:
            assert error in response.data
Exemplo n.º 4
0
def test_immunity_session_contents_all_data(client, app_specific_illnesses,
                                            request_data):
    app = app_specific_illnesses(illnesses=[])
    with app.test_client() as test_client:
        flat_request_data = ImmutableMultiDict(flatten_dict(request_data))

        assert test_client.get('immunity/').status_code == 200

        response = test_client.post(
            'immunity/', data=flat_request_data, content_type='application/x-www-form-urlencoded')

        assert flask.session['birth_year'] == int(request_data['birth_year'])

        # Ensure successful redirect to results in response.
        assert 'http://localhost/immunity/results/' == response.headers['Location']
Exemplo n.º 5
0
def test_immunity_common_data(client, app_specific_illnesses):
    """Test response and redirect on good data."""
    request_data = {'birth_year': 2019, }

    app = app_specific_illnesses(illnesses=[])
    with app.test_client() as test_client:
        flat_request_data = ImmutableMultiDict(flatten_dict(request_data))

    assert test_client.get('immunity/').status_code == 200

    response = test_client.post(
        'immunity/', data=flat_request_data)

    assert response.status_code == 302  # Redirected to results page.
    assert response.headers['Location'] == 'http://localhost/immunity/results/'
def test_measles_immunity_results(client, app_specific_illnesses, request_data,
                                  response_status, measles_probability):
    """Test all normally active components. Use range of normal values and edge cases."""
    app = app_specific_illnesses(illnesses=[Measles])
    with app.test_client() as test_client:
        flat_request_data = ImmutableMultiDict(flatten_dict(request_data))

        assert test_client.get('immunity/').status_code == 200
        response = test_client.post('immunity/', data=flat_request_data)
        assert 'http://localhost/immunity/results/' == response.headers[
            'Location']

        response = test_client.get('http://localhost/immunity/results/',
                                   follow_redirects=True)
        assert response.status_code == response_status
        # Use probability of measles immunity to test response content.
        assert f'{measles_probability:.2f}'.encode('utf-8') in response.data
Exemplo n.º 7
0
def test_immunity_results(client, app,
                          request_data,
                          response_status, measles_probability):
    """Test all normally active components. Use range of normal values and edge cases."""

    flat_request_data = ImmutableMultiDict(flatten_dict(request_data))

    assert client.get('immunity/').status_code == 200
    response = client.post(
        'immunity/', data=flat_request_data)
    assert 'http://localhost/immunity/results/' == response.headers['Location']

    response = client.get('http://localhost/immunity/results/', follow_redirects=True)
    assert response.status_code == response_status
    # Use probability of measles immunity to test response content.
    assert f'{measles_probability}'.encode('utf-8') in response.data
    # Ensure no errors thrown.
    assert b'Error' not in response.data
Exemplo n.º 8
0
def test_immunity_all_good_data(client, app):
    """Test response and redirect on good data."""
    request_data = {'birth_year': 1985,
                    'measles': {'on_time_measles_vaccinations': 1},
                    'mumps': {'on_time_mumps_vaccinations': 2,
                              'mumps_illness': False},
                    }

    with client as test_client:
        flat_request_data = ImmutableMultiDict(flatten_dict(request_data))

    assert test_client.get('immunity/').status_code == 200

    response = test_client.post(
        'immunity/', data=flat_request_data)

    assert response.status_code == 302  # Redirected to results page.
    assert response.headers['Location'] == 'http://localhost/immunity/results/'
def test_immunity_session_contents_mumps(app_specific_illnesses,
                                         request_data,
                                         monkeypatch):
    app = app_specific_illnesses(illnesses=[Mumps])
    with app.test_client() as test_client:
        flat_request_data = ImmutableMultiDict(flatten_dict(request_data))

        assert test_client.get('immunity/').status_code == 200

        response = test_client.post(
            'immunity/', data=flat_request_data)

        assert flask.session['birth_year'] == request_data['birth_year']
        assert flask.session['mumps'] == {
            'on_time_mumps_vaccinations': request_data['mumps']['on_time_mumps_vaccinations'],
            'mumps_illness': request_data['mumps']['mumps_illness']}

        # Ensure successful redirect to results in response.
        assert 'http://localhost/immunity/results/' == response.headers['Location']
def test_flatten_dict(test_dict, flattened_dict):
    result = flatten_dict(test_dict)
    print(result)
    assert result == flattened_dict
            'e': {
                'f': 6
            }
        }
    }, [('a', 1), ('b-c', 3), ('b-d', 4), ('b-e-f', 6)]),
    ({
        'a': 1,
        'b': {
            'c': 2,
            'd': 4,
            'e': {
                'f': 6,
                'g': {
                    'h': 8,
                    'i': {
                        'j': 10
                    },
                }
            },
        },
    }, [('a', 1), ('b-c', 2), ('b-d', 4), ('b-e-f', 6), ('b-e-g-h', 8),
        ('b-e-g-i-j', 10)]),
])
def test_flatten_dict(test_dict, flattened_dict):
    result = flatten_dict(test_dict)
    print(result)
    assert result == flattened_dict


print(flatten_dict({'a': 1, 'b': {'c': 2, 'd': 3, 'e': {'f': 6}}}))