Changeset View
Changeset View
Standalone View
Standalone View
swh/deposit/tests/api/test_deposit_check.py
Show All 11 Lines | |||||
from rest_framework import status | from rest_framework import status | ||||
from rest_framework.test import APITestCase | from rest_framework.test import APITestCase | ||||
from swh.deposit.config import ( | from swh.deposit.config import ( | ||||
DEPOSIT_STATUS_VERIFIED, PRIVATE_CHECK_DEPOSIT, | DEPOSIT_STATUS_VERIFIED, PRIVATE_CHECK_DEPOSIT, | ||||
DEPOSIT_STATUS_DEPOSITED, DEPOSIT_STATUS_REJECTED | DEPOSIT_STATUS_DEPOSITED, DEPOSIT_STATUS_REJECTED | ||||
) | ) | ||||
from swh.deposit.api.private.deposit_check import ( | from swh.deposit.api.private.deposit_check import ( | ||||
SWHChecksDeposit, | SWHChecksDeposit, MANDATORY_ARCHIVE_INVALID, | ||||
MANDATORY_FIELDS_MISSING, INCOMPATIBLE_URL_FIELDS, | MANDATORY_FIELDS_MISSING, INCOMPATIBLE_URL_FIELDS, | ||||
MANDATORY_ARCHIVE_UNSUPPORTED, ALTERNATE_FIELDS_MISSING | MANDATORY_ARCHIVE_UNSUPPORTED, ALTERNATE_FIELDS_MISSING | ||||
) | ) | ||||
from swh.deposit.models import Deposit | from swh.deposit.models import Deposit | ||||
from ..common import BasicTestCase, WithAuthTestCase, CommonCreationRoutine | from ..common import BasicTestCase, WithAuthTestCase, CommonCreationRoutine | ||||
from ..common import FileSystemCreationRoutine | from ..common import FileSystemCreationRoutine | ||||
Show All 27 Lines | def deposit_ok(self): | ||||
self.assertEqual(response.status_code, status.HTTP_200_OK) | self.assertEqual(response.status_code, status.HTTP_200_OK) | ||||
data = json.loads(response.content.decode('utf-8')) | data = json.loads(response.content.decode('utf-8')) | ||||
self.assertEqual(data['status'], DEPOSIT_STATUS_VERIFIED) | self.assertEqual(data['status'], DEPOSIT_STATUS_VERIFIED) | ||||
deposit = Deposit.objects.get(pk=deposit.id) | deposit = Deposit.objects.get(pk=deposit.id) | ||||
self.assertEquals(deposit.status, DEPOSIT_STATUS_VERIFIED) | self.assertEquals(deposit.status, DEPOSIT_STATUS_VERIFIED) | ||||
@istest | @istest | ||||
def deposit_ko(self): | def deposit_with_tarball_with_one_tarball_invalid(self): | ||||
"""Deposit with tarball (of 1 tarball) should fail the checks: rejected | |||||
""" | |||||
deposit_id = self.create_deposit_archive_with_archive() | |||||
deposit = Deposit.objects.get(pk=deposit_id) | |||||
self.assertEquals(DEPOSIT_STATUS_DEPOSITED, deposit.status) | |||||
url = reverse(PRIVATE_CHECK_DEPOSIT, | |||||
args=[self.collection.name, deposit.id]) | |||||
response = self.client.get(url) | |||||
self.assertEqual(response.status_code, status.HTTP_200_OK) | |||||
data = json.loads(response.content.decode('utf-8')) | |||||
self.assertEqual(data['status'], DEPOSIT_STATUS_REJECTED) | |||||
details = data['details'] | |||||
# archive checks failure | |||||
self.assertEqual(len(details['archive']), 1) | |||||
self.assertEqual(details['archive'][0]['summary'], | |||||
MANDATORY_ARCHIVE_INVALID) | |||||
# metadata check failure | |||||
self.assertEqual(len(details['metadata']), 2) | |||||
mandatory = details['metadata'][0] | |||||
self.assertEqual(mandatory['summary'], MANDATORY_FIELDS_MISSING) | |||||
self.assertEqual(set(mandatory['fields']), | |||||
set(['url', 'external_identifier', 'author'])) | |||||
alternate = details['metadata'][1] | |||||
self.assertEqual(alternate['summary'], ALTERNATE_FIELDS_MISSING) | |||||
self.assertEqual(alternate['fields'], ['name or title']) | |||||
# url check failure | |||||
self.assertEqual(details['url']['summary'], INCOMPATIBLE_URL_FIELDS) | |||||
deposit = Deposit.objects.get(pk=deposit.id) | |||||
self.assertEquals(deposit.status, DEPOSIT_STATUS_REJECTED) | |||||
@istest | |||||
def deposit_ko_not_a_valid_tarball(self): | |||||
"""Invalid deposit should fail the checks (-> status rejected) | """Invalid deposit should fail the checks (-> status rejected) | ||||
""" | """ | ||||
deposit_id = self.create_deposit_with_invalid_archive() | deposit_id = self.create_deposit_with_invalid_archive() | ||||
ardumont: > I like this new approach
Cool.
Also, note that i wanted to use it that ARCHIVE_EXTENSION… | |||||
deposit = Deposit.objects.get(pk=deposit_id) | deposit = Deposit.objects.get(pk=deposit_id) | ||||
self.assertEquals(DEPOSIT_STATUS_DEPOSITED, deposit.status) | self.assertEquals(DEPOSIT_STATUS_DEPOSITED, deposit.status) | ||||
url = reverse(PRIVATE_CHECK_DEPOSIT, | url = reverse(PRIVATE_CHECK_DEPOSIT, | ||||
args=[self.collection.name, deposit.id]) | args=[self.collection.name, deposit.id]) | ||||
response = self.client.get(url) | response = self.client.get(url) | ||||
▲ Show 20 Lines • Show All 116 Lines • Show Last 20 Lines |
Cool.
Also, note that i wanted to use it that ARCHIVE_EXTENSION variable content to fully check all here.
But that will:
That's why i only limited to those (for now ;)