Skip to content

test_directory_permissions#

project_user#

Source code in tests/unit/apps/files/api/directories/test_directory_permissions.py
@pytest.fixture
def project_user(file_tree):
    user, created = MetaxUser.objects.get_or_create(
        username="test_project_user",
        first_name="Project User",
        last_name="Testaaja",
        is_hidden=False,
        csc_projects=[file_tree["storage"].csc_project],
    )
    return user

project_client#

Source code in tests/unit/apps/files/api/directories/test_directory_permissions.py
@pytest.fixture
def project_client(client, project_user):
    client.force_login(project_user)
    return client

test_directory_permissions_project_user#

Source code in tests/unit/apps/files/api/directories/test_directory_permissions.py
def test_directory_permissions_project_user(project_client, file_tree):
    res = project_client.get(
        "/v3/directories",
        {
            "storage_service": file_tree["storage"].storage_service,
            "csc_project": file_tree["storage"].csc_project,
        },
    )
    assert res.data["count"] == 4

test_directory_permissions_dataset_anon_nonpublic#

Source code in tests/unit/apps/files/api/directories/test_directory_permissions.py
def test_directory_permissions_dataset_anon_nonpublic(client, dataset_with_files):
    dataset_with_files.state = "draft"
    dataset_with_files.save()
    res = client.get(
        "/v3/directories",
        {
            "dataset": dataset_with_files.id,
            "storage_service": dataset_with_files.file_set.storage.storage_service,
            "csc_project": dataset_with_files.file_set.storage.csc_project,
        },
    )
    assert res.status_code == 403

test_directory_permissions_dataset_anon_published#

Source code in tests/unit/apps/files/api/directories/test_directory_permissions.py
@pytest.mark.xfail(
    reason="DatasetAccessPolicy.scope_queryset does not work correctly for anonymous users"
)
def test_directory_permissions_dataset_anon_published(client, dataset_with_files):
    dataset_with_files.publish()
    res = client.get(
        "/v3/directories",
        {
            "dataset": dataset_with_files.id,
            "storage_service": dataset_with_files.file_set.storage.storage_service,
            "csc_project": dataset_with_files.file_set.storage.csc_project,
        },
    )
    assert res.status_code == 200
    assert res.data["count"] == 2

test_directory_permissions_dataset_noncreator_published#

Source code in tests/unit/apps/files/api/directories/test_directory_permissions.py
def test_directory_permissions_dataset_noncreator_published(user_client, dataset_with_files):
    dataset_with_files.publish()
    res = user_client.get(
        "/v3/directories",
        {
            "dataset": dataset_with_files.id,
            "storage_service": dataset_with_files.file_set.storage.storage_service,
            "csc_project": dataset_with_files.file_set.storage.csc_project,
        },
    )
    assert res.status_code == 200
    assert res.data["count"] == 2