コード例 #1
0
def test_generate_signed_url_with_non_public_access_rights(mocker):
    mocker.patch(
        "exporter.common.APIClient.get_dataset",
        return_value={"accessRights": "non-public"},
    )
    mocker.patch(
        "exporter.common.APIClient.get_edition",
        return_value=edition_info,
    )
    mocker.patch(
        "exporter.common.APIClient.has_distributions",
        return_value=True,
    )
    resource_auth_mock = mocker.patch(
        "okdata.resource_auth.ResourceAuthorizer.has_access",
        return_value=False,
    )

    result = generate_signed_url(prefix_key_event, context={})
    resource_auth_mock.assert_called_once_with(
        "blippblopp",
        scope="okdata:dataset:read",
        resource_name="okdata:dataset:befolkingsframskrivninger",
    )
    assert result["statusCode"] == 403
コード例 #2
0
def test_generate_signed_url_when_get_dataset_metadata_404_error():
    responses.add(
        responses.GET,
        metadata_api,
        json={"error": "not found"},
        status=404,
        content_type="application/json",
    )
    result = generate_signed_url(prefix_key_event, context={})
    assert result["statusCode"] == 404
    assert json.loads(result["body"])["message"] == {"error": "not found"}
コード例 #3
0
def test_generate_signed_url_handler_with_prefix(mock_gets):
    result = generate_signed_url(prefix_key_event, context={})
    assert json.loads(result["body"])[2]["key"] == f"{base_key}2.json"
    assert json.loads(result["body"])[9]["key"] == f"{base_key}9.json"
コード例 #4
0
def test_generate_signed_url_handler_specific_object(mock_gets):
    result = generate_signed_url(base_event, context={})
    assert json.loads(result["body"])[0]["key"] == f"{base_key}0.json"