Changeset View
Changeset View
Standalone View
Standalone View
swh/deposit/tests/api/test_deposit_private_list.py
# Copyright (C) 2017-2021 The Software Heritage developers | # Copyright (C) 2017-2021 The Software Heritage developers | ||||
# See the AUTHORS file at the top-level directory of this distribution | # See the AUTHORS file at the top-level directory of this distribution | ||||
# License: GNU General Public License version 3, or any later version | # License: GNU General Public License version 3, or any later version | ||||
# See top-level LICENSE file for more information | # See top-level LICENSE file for more information | ||||
from django.urls import reverse_lazy as reverse | from django.urls import reverse_lazy as reverse | ||||
from rest_framework import status | from rest_framework import status | ||||
from swh.deposit.api.converters import convert_status_detail | from swh.deposit.api.converters import convert_status_detail | ||||
from swh.deposit.config import ( | from swh.deposit.config import ( | ||||
DEPOSIT_STATUS_DEPOSITED, | DEPOSIT_STATUS_DEPOSITED, | ||||
DEPOSIT_STATUS_LOAD_SUCCESS, | |||||
DEPOSIT_STATUS_PARTIAL, | DEPOSIT_STATUS_PARTIAL, | ||||
PRIVATE_LIST_DEPOSITS, | PRIVATE_LIST_DEPOSITS, | ||||
) | ) | ||||
from swh.deposit.models import DepositClient | |||||
from swh.deposit.tests.conftest import internal_create_deposit | |||||
STATUS_DETAIL = { | STATUS_DETAIL = { | ||||
"url": { | "url": { | ||||
"summary": "At least one compatible url field. Failed", | "summary": "At least one compatible url field. Failed", | ||||
"fields": ["testurl"], | "fields": ["testurl"], | ||||
}, | }, | ||||
"metadata": [{"summary": "Mandatory fields missing", "fields": ["9", 10, 1.212],},], | "metadata": [{"summary": "Mandatory fields missing", "fields": ["9", 10, 1.212],},], | ||||
"archive": [ | "archive": [ | ||||
▲ Show 20 Lines • Show All 67 Lines • ▼ Show 20 Lines | def test_deposit_list_exclude(partial_deposit, deposited_deposit, authenticated_client): | ||||
data = response.json() | data = response.json() | ||||
assert data["count"] == 0 | assert data["count"] == 0 | ||||
url = "%s?page_size=1&exclude=dummy" % main_url # that won't exclude anything | url = "%s?page_size=1&exclude=dummy" % main_url # that won't exclude anything | ||||
response = authenticated_client.get(url) | response = authenticated_client.get(url) | ||||
assert response.status_code == status.HTTP_200_OK | assert response.status_code == status.HTTP_200_OK | ||||
data = response.json() | data = response.json() | ||||
assert data["count"] == 2 | assert data["count"] == 2 | ||||
def test_deposit_list_for_username( | |||||
authenticated_client, | |||||
deposit_another_collection, | |||||
completed_deposit, | |||||
deposit_user, | |||||
deposit_another_user, | |||||
): | |||||
# create a new deposit with a user different from deposit_user, | |||||
# the one that created completed_deposit | |||||
internal_create_deposit( | |||||
client=deposit_another_user, | |||||
collection=deposit_another_collection, | |||||
external_id="external-id-bar", | |||||
status=DEPOSIT_STATUS_LOAD_SUCCESS, | |||||
) | |||||
for user in (deposit_user, deposit_another_user): | |||||
# check deposit filtering by username | |||||
url = f"{reverse(PRIVATE_LIST_DEPOSITS)}?username={user.username}" | |||||
json_response = authenticated_client.get(url).json() | |||||
assert len(json_response["results"]) == 1 | |||||
deposit_client = DepositClient.objects.all().get( | |||||
id=json_response["results"][0]["client"] | |||||
) | |||||
assert deposit_client.username == user.username |