コード例 #1
0
def test__checksum_test__invalid_data(user):
    """Tests proper response is returned for invalid data."""
    # Create token and add user permissions
    token = create_token(user)
    utils.add_api_view_permission(user)

    # Set up client and response
    client = APIClient()
    client.credentials(HTTP_AUTHORIZATION=f'Token {token}')
    response = client.post(
        reverse('api:hc_dpd_v1:checksum_test'),
        data={'active_ingredient': [{'drug_code': 'ERROR'}]},
        format='json',
    )
    content = json.loads(response.content)

    # Confirm status code
    assert response.status_code == 400
    assert content['status_code'] == 400

    # Confirm response details
    assert 'errors' in content
    assert content['errors']['non_field'] == []
    assert content['errors']['field'] == {
        'active_ingredient': [{'drug_code': ['A valid integer is required.']}],
    }
コード例 #2
0
def test__has_dpd_view_access__user_with_permission(user):
    """Confirms user with permission passes permission check."""
    # Add permission to user
    utils.add_api_view_permission(user)

    permission = permissions.HasDPDViewAccess()
    request = RequestFactory()
    request.user = user

    assert permission.has_permission(request, None) is True
コード例 #3
0
def test__checksum_list__accessible_by_url(user):
    """Tests that endpoint exists at expected URL."""
    # Create token and add user permissions
    token = create_token(user)
    utils.add_api_view_permission(user)

    # Set up client and response
    client = APIClient()
    client.credentials(HTTP_AUTHORIZATION=f'Token {token}')
    response = client.get('/api/hc-dpd/v1/checksum/?step=1&source=active_ingredient')

    assert response.status_code == 200
コード例 #4
0
def test__checksum_list__200_response_on_user_with_view_permissions(user):
    """Test for 200 response on user with view permission."""
    # Create token and add user permissions
    token = create_token(user)
    utils.add_api_view_permission(user)

    # Set up client and response
    client = APIClient()
    client.credentials(HTTP_AUTHORIZATION=f'Token {token}')
    response = client.get(
        reverse('api:hc_dpd_v1:checksum_list'),
        data={'step': 1, 'source': 'active_ingredient'},
    )

    assert response.status_code == 200
コード例 #5
0
def test__upload_hc_dpd_data__403_response_on_user_with_view_permissions(user):
    """Test for 403 response on user with view permission."""
    # Create token and add user permissions
    token = create_token(user)
    utils.add_api_view_permission(user)

    # Set up client and response
    client = APIClient()
    client.credentials(HTTP_AUTHORIZATION=f'Token {token}')
    response = client.post(
        reverse('api:hc_dpd_v1:upload_hc_dpd_data'),
        data={'active_ingredient': [{'drug_code': 1, 'active_ingredient_code': 'A'}]},
        format='json',
    )

    assert response.status_code == 403
コード例 #6
0
def test__checksum_test__valid_data(user):
    """Tests proper response is returned for valid data."""
    # Create token and add user permissions
    token = create_token(user)
    utils.add_api_view_permission(user)

    # Set up client and response
    client = APIClient()
    client.credentials(HTTP_AUTHORIZATION=f'Token {token}')
    response = client.post(
        reverse('api:hc_dpd_v1:checksum_test'),
        data=utils.CHECKSUM_TEST_DATA,
        format='json',
    )
    content = json.loads(response.content)

    # Confirm status code
    assert response.status_code == 200

    # Confirm response details
    assert len(content) == 13
    assert 'active_ingredient' in content
    assert 'server_checksum' in content['active_ingredient']
    assert len(str(content['active_ingredient']['server_checksum'])) == 10
    assert 'server_checksum_string' in content['active_ingredient']
    assert content['active_ingredient']['server_checksum_string'] == '1ABCDEFGHIJKLMN'
    assert 'active_ingredient' in content
    assert 'biosimilar' in content
    assert 'company' in content
    assert 'drug_product' in content
    assert 'form' in content
    assert 'inactive_product' in content
    assert 'packaging' in content
    assert 'pharmaceutical_standard' in content
    assert 'schedule' in content
    assert 'status' in content
    assert 'therapeutic_class' in content
    assert 'veterinary_species' in content
コード例 #7
0
def test__checksum_test__no_data(user):
    """Tests proper response is returned for valid data."""
    # Create token and add user permissions
    token = create_token(user)
    utils.add_api_view_permission(user)

    # Set up client and response
    client = APIClient()
    client.credentials(HTTP_AUTHORIZATION=f'Token {token}')
    response = client.post(
        reverse('api:hc_dpd_v1:checksum_test'),
        data={},
        format='json',
    )
    content = json.loads(response.content)

    # Confirm status code
    assert response.status_code == 422
    assert content['status_code'] == 422

    # Confirm response details
    assert 'errors' in content
    assert content['errors']['field'] == {}
    assert content['errors']['non_field'] == ['No data submitted for testing.']