diff --git a/MANIFEST.in b/MANIFEST.in index 3f5831b7..6c3de5d3 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,10 +1,11 @@ include Makefile include requirements.txt include requirements-test.txt include requirements-swh.txt include requirements-server.txt include requirements-swh-server.txt include version.txt recursive-include swh/deposit/static * recursive-include swh/deposit/fixtures * recursive-include swh/deposit/templates * +recursive-include swh/deposit/tests/*/data * diff --git a/swh/deposit/tests/api/conftest.py b/swh/deposit/tests/api/conftest.py new file mode 100644 index 00000000..c6c57749 --- /dev/null +++ b/swh/deposit/tests/api/conftest.py @@ -0,0 +1,32 @@ +# Copyright (C) 2019 The Software Heritage developers +# See the AUTHORS file at the top-level directory of this distribution +# License: GNU General Public License version 3, or any later version +# See top-level LICENSE file for more information + +import pytest + +from os import path, listdir +from typing import Mapping + + +@pytest.fixture +def atom_dataset(datadir) -> Mapping[str, bytes]: + """Compute the paths to atom files. + + Returns: + Dict of atom name per content (bytes) + + """ + atom_path = path.join(datadir, 'atom') + + data = {} + for filename in listdir(atom_path): + filepath = path.join(atom_path, filename) + with open(filepath, 'rb') as f: + raw_content = f.read() + + # Keep the filename without extension + atom_name = filename.split('.')[0] + data[atom_name] = raw_content + + return data diff --git a/swh/deposit/tests/api/data/atom/codemeta-sample.xml b/swh/deposit/tests/api/data/atom/codemeta-sample.xml new file mode 100644 index 00000000..98c3e06d --- /dev/null +++ b/swh/deposit/tests/api/data/atom/codemeta-sample.xml @@ -0,0 +1,53 @@ + + + + + %s + hal-01587361 + https://hal.inria.fr/hal-01587361 + https://hal.inria.fr/hal-01587361/document + https://hal.inria.fr/hal-01587361/file/AffectationRO-v1.0.0.zip + doi:10.5281/zenodo.438684 + The assignment problem + AffectationRO + Gruenpeter, Morane + [INFO] Computer Science [cs] + [INFO.INFO-RO] Computer Science [cs]/Operations Research [cs.RO] + SOFTWARE + Project in OR: The assignment problemA java implementation for the assignment problem first release + description fr + 2015-06-01 + 2017-10-19 + en + + + url stable + Version sur hal + Version entre par lutilisateur + Mots-cls + Commentaire + Rfrence interne + + Collaboration/Projet + nom du projet + id + + Voir aussi + Financement + Projet ANR + Projet Europen + Platform/OS + Dpendances + Etat du dveloppement + + license + url spdx + + Outils de dveloppement- outil no1 + Outils de dveloppement- outil no2 + http://code.com + language 1 + language 2 + diff --git a/swh/deposit/tests/api/data/atom/entry-data-badly-formatted.xml b/swh/deposit/tests/api/data/atom/entry-data-badly-formatted.xml new file mode 100644 index 00000000..25a417fb --- /dev/null +++ b/swh/deposit/tests/api/data/atom/entry-data-badly-formatted.xml @@ -0,0 +1,2 @@ + + diff --git a/swh/deposit/tests/api/data/atom/entry-data-empty-body.xml b/swh/deposit/tests/api/data/atom/entry-data-empty-body.xml new file mode 100644 index 00000000..e4caf44f --- /dev/null +++ b/swh/deposit/tests/api/data/atom/entry-data-empty-body.xml @@ -0,0 +1,2 @@ + + diff --git a/swh/deposit/tests/api/data/atom/entry-data-minimal.xml b/swh/deposit/tests/api/data/atom/entry-data-minimal.xml new file mode 100644 index 00000000..9432ac0e --- /dev/null +++ b/swh/deposit/tests/api/data/atom/entry-data-minimal.xml @@ -0,0 +1,4 @@ + + + %s + diff --git a/swh/deposit/tests/api/data/atom/entry-data-parsing-error-prone.xml b/swh/deposit/tests/api/data/atom/entry-data-parsing-error-prone.xml new file mode 100644 index 00000000..34710195 --- /dev/null +++ b/swh/deposit/tests/api/data/atom/entry-data-parsing-error-prone.xml @@ -0,0 +1,5 @@ + + + Composing a Web of Audio Applications + + diff --git a/swh/deposit/tests/api/data/atom/entry-data0.xml b/swh/deposit/tests/api/data/atom/entry-data0.xml new file mode 100644 index 00000000..2b0ccc00 --- /dev/null +++ b/swh/deposit/tests/api/data/atom/entry-data0.xml @@ -0,0 +1,26 @@ + + + Awesome Compiler + hal + urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a + %s + 2017-10-07T15:17:08Z + some awesome author + something + awesome-compiler + This is an awesome compiler destined to +awesomely compile stuff +and other stuff + compiler,programming,language + 2005-10-07T17:17:08Z + 2005-10-07T17:17:08Z + release note + related link + + Awesome + https://hoster.org/awesome-compiler + GNU/Linux + 0.0.1 + running + all + diff --git a/swh/deposit/tests/api/data/atom/entry-data1.xml b/swh/deposit/tests/api/data/atom/entry-data1.xml new file mode 100644 index 00000000..e4f415c7 --- /dev/null +++ b/swh/deposit/tests/api/data/atom/entry-data1.xml @@ -0,0 +1,24 @@ + + + hal + urn:uuid:2225c695-cfb8-4ebb-aaaa-80da344efa6a + 2017-10-07T15:17:08Z + some awesome author + something + awesome-compiler + This is an awesome compiler destined to +awesomely compile stuff +and other stuff + compiler,programming,language + 2005-10-07T17:17:08Z + 2005-10-07T17:17:08Z + release note + related link + + Awesome + https://hoster.org/awesome-compiler + GNU/Linux + 0.0.1 + running + all + diff --git a/swh/deposit/tests/api/data/atom/error-with-decimal.xml b/swh/deposit/tests/api/data/atom/error-with-decimal.xml new file mode 100644 index 00000000..be002442 --- /dev/null +++ b/swh/deposit/tests/api/data/atom/error-with-decimal.xml @@ -0,0 +1,38 @@ + + + Composing a Web of Audio Applications + hal + hal-01243065 + hal-01243065 + https://hal-test.archives-ouvertes.fr/hal-01243065 + test + + + DSP programming,Web,Composability,Faust + 2017-05-03T16:08:47+02:00 + The Web offers a great opportunity to share, deploy and use programs without installation difficulties. In this article we explore the idea of freely combining/composing real-time audio applications deployed on the Web using Faust audio DSP language. + 1 + 10.4 + phpstorm + stable + + linux + php + python + C + + GNU General Public License v3.0 only + + + CeCILL Free Software License Agreement v1.1 + + + HAL + hal@ccsd.cnrs.fr + + + Someone Nice + someone@nice.fr + FFJ + + diff --git a/swh/deposit/tests/api/data/atom/tei-sample.xml b/swh/deposit/tests/api/data/atom/tei-sample.xml new file mode 100644 index 00000000..cf2266af --- /dev/null +++ b/swh/deposit/tests/api/data/atom/tei-sample.xml @@ -0,0 +1 @@ +HAL TEI export of hal-01587083CCSDDistributed under a Creative Commons Attribution 4.0 International License

HAL API platform

questionnaire software metadataMoraneGruenpeter7de56c632362954fa84172cad80afe4einria.fr1556733MoraneGruenpeterf85a43a5fb4a2e0778a77e017f28c8fdgmail.com2017-09-29 11:21:322017-10-03 17:20:132017-10-03 17:20:132017-09-292017-09-29contributorMoraneGruenpeterf85a43a5fb4a2e0778a77e017f28c8fdgmail.comCCSDhal-01587083https://hal.inria.fr/hal-01587083gruenpeter:hal-0158708320172017questionnaire software metadataMoraneGruenpeter7de56c632362954fa84172cad80afe4einria.fr1556733EnglishComputer Science [cs]SoftwareIRILLInitiative pour la Recherche et l'Innovation sur le Logiciel Libre
https://www.irill.org/
Universite Pierre et Marie Curie - Paris 6UPMC
4 place Jussieu - 75005 Paris
http://www.upmc.fr/
Institut National de Recherche en Informatique et en AutomatiqueInria
Domaine de VoluceauRocquencourt - BP 10578153 Le Chesnay Cedex
http://www.inria.fr/en/
Universite Paris Diderot - Paris 7UPD7
5 rue Thomas-Mann - 75205 Paris cedex 13
http://www.univ-paris-diderot.fr
diff --git a/swh/deposit/tests/api/test_deposit_atom.py b/swh/deposit/tests/api/test_deposit_atom.py index b04da6d6..a8fcc532 100644 --- a/swh/deposit/tests/api/test_deposit_atom.py +++ b/swh/deposit/tests/api/test_deposit_atom.py @@ -1,473 +1,313 @@ # Copyright (C) 2017-2019 The Software Heritage developers # See the AUTHORS file at the top-level directory of this distribution # License: GNU General Public License version 3, or any later version # See top-level LICENSE file for more information +import pytest + from django.urls import reverse from io import BytesIO from rest_framework import status -from rest_framework.test import APITestCase from swh.deposit.config import COL_IRI, DEPOSIT_STATUS_DEPOSITED -from swh.deposit.models import Deposit, DepositRequest +from swh.deposit.models import Deposit, DepositRequest, DepositCollection from swh.deposit.parsers import parse_xml -from ..common import BasicTestCase, WithAuthTestCase + +def test_post_deposit_atom_201_even_with_decimal( + authenticated_client, deposit_collection, atom_dataset): + """Posting an initial atom entry should return 201 with deposit receipt + + """ + atom_error_with_decimal = atom_dataset['error-with-decimal'] + + response = authenticated_client.post( + reverse(COL_IRI, args=[deposit_collection.name]), + content_type='application/atom+xml;type=entry', + data=atom_error_with_decimal, + HTTP_SLUG='external-id', + HTTP_IN_PROGRESS='false') + + # then + assert response.status_code == status.HTTP_201_CREATED + + response_content = parse_xml(BytesIO(response.content)) + deposit_id = response_content['deposit_id'] + + deposit = Deposit.objects.get(pk=deposit_id) + dr = DepositRequest.objects.get(deposit=deposit) + + assert dr.metadata is not None + sw_version = dr.metadata.get('codemeta:softwareVersion') + assert sw_version == '10.4' + + +def test_post_deposit_atom_400_with_empty_body( + authenticated_client, deposit_collection, atom_dataset): + """Posting empty body request should return a 400 response + + """ + response = authenticated_client.post( + reverse(COL_IRI, args=[deposit_collection.name]), + content_type='application/atom+xml;type=entry', + data=atom_dataset['entry-data-empty-body']) + assert response.status_code == status.HTTP_400_BAD_REQUEST + + +def test_post_deposit_atom_400_badly_formatted_atom( + authenticated_client, deposit_collection, atom_dataset): + """Posting a badly formatted atom should return a 400 response + + """ + response = authenticated_client.post( + reverse(COL_IRI, args=[deposit_collection.name]), + content_type='application/atom+xml;type=entry', + data=atom_dataset['entry-data-badly-formatted']) + assert response.status_code == status.HTTP_400_BAD_REQUEST + + +def test_post_deposit_atom_parsing_error( + authenticated_client, deposit_collection, atom_dataset): + """Posting parsing error prone atom should return 400 + + """ + response = authenticated_client.post( + reverse(COL_IRI, args=[deposit_collection.name]), + content_type='application/atom+xml;type=entry', + data=atom_dataset['entry-data-parsing-error-prone']) + assert response.status_code == status.HTTP_400_BAD_REQUEST + + +def test_post_deposit_atom_no_slug_header( + authenticated_client, deposit_collection, atom_dataset): + """Posting an atom entry without a slug header should return a 400 + + """ + url = reverse(COL_IRI, args=[deposit_collection.name]) + + # when + response = authenticated_client.post( + url, + content_type='application/atom+xml;type=entry', + data=atom_dataset['entry-data0'], + # + headers + HTTP_IN_PROGRESS='false') + + assert b'Missing SLUG header' in response.content + assert response.status_code == status.HTTP_400_BAD_REQUEST + + +def test_post_deposit_atom_unknown_collection( + authenticated_client, atom_dataset): + """Posting an atom entry to an unknown collection should return a 404 + + """ + unknown_collection = 'unknown-one' + with pytest.raises(DepositCollection.DoesNotExist): + DepositCollection.objects.get(name=unknown_collection) + + response = authenticated_client.post( + reverse(COL_IRI, args=[unknown_collection]), # <- unknown collection + content_type='application/atom+xml;type=entry', + data=atom_dataset['entry-data0'], + HTTP_SLUG='something') + assert response.status_code == status.HTTP_404_NOT_FOUND + + +def test_post_deposit_atom_entry_initial( + authenticated_client, deposit_collection, atom_dataset): + """Posting an initial atom entry should return 201 with deposit receipt + + """ + # given + external_id = 'urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a' + + with pytest.raises(Deposit.DoesNotExist): + Deposit.objects.get(external_id=external_id) + + atom_entry_data = atom_dataset['entry-data0'] % external_id.encode('utf-8') + + # when + response = authenticated_client.post( + reverse(COL_IRI, args=[deposit_collection.name]), + content_type='application/atom+xml;type=entry', + data=atom_entry_data, + HTTP_SLUG=external_id, + HTTP_IN_PROGRESS='false') + + # then + assert response.status_code == status.HTTP_201_CREATED + + response_content = parse_xml(BytesIO(response.content)) + deposit_id = response_content['deposit_id'] + + deposit = Deposit.objects.get(pk=deposit_id) + assert deposit.collection == deposit_collection + assert deposit.external_id == external_id + assert deposit.status == DEPOSIT_STATUS_DEPOSITED + + # one associated request to a deposit + deposit_request = DepositRequest.objects.get(deposit=deposit) + assert deposit_request.metadata is not None + assert deposit_request.raw_metadata == atom_entry_data.decode('utf-8') + assert bool(deposit_request.archive) is False + + +def test_post_deposit_atom_entry_with_codemeta( + authenticated_client, deposit_collection, atom_dataset): + """Posting an initial atom entry should return 201 with deposit receipt + + """ + # given + external_id = 'urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a' + + with pytest.raises(Deposit.DoesNotExist): + Deposit.objects.get(external_id=external_id) + + atom_entry_data = atom_dataset['codemeta-sample'] % external_id.encode('utf-8') # noqa + + # when + response = authenticated_client.post( + reverse(COL_IRI, args=[deposit_collection.name]), + content_type='application/atom+xml;type=entry', + data=atom_entry_data, + HTTP_SLUG=external_id, + HTTP_IN_PROGRESS='false') + + # then + assert response.status_code == status.HTTP_201_CREATED + + response_content = parse_xml(BytesIO(response.content)) + + deposit_id = response_content['deposit_id'] + + deposit = Deposit.objects.get(pk=deposit_id) + assert deposit.collection == deposit_collection + assert deposit.external_id == external_id + assert deposit.status == DEPOSIT_STATUS_DEPOSITED + + # one associated request to a deposit + deposit_request = DepositRequest.objects.get(deposit=deposit) + assert deposit_request.metadata is not None + assert deposit_request.raw_metadata == atom_entry_data.decode('utf-8') + assert bool(deposit_request.archive) is False + + +def test_post_deposit_atom_entry_tei( + authenticated_client, deposit_collection, atom_dataset): + """Posting initial atom entry as TEI should return 201 with receipt + + """ + # given + external_id = 'urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a' + with pytest.raises(Deposit.DoesNotExist): + Deposit.objects.get(external_id=external_id) + + atom_entry_data = atom_dataset['tei-sample'] + + # when + response = authenticated_client.post( + reverse(COL_IRI, args=[deposit_collection.name]), + content_type='application/atom+xml;type=entry', + data=atom_entry_data, + HTTP_SLUG=external_id, + HTTP_IN_PROGRESS='false') + + # then + assert response.status_code == status.HTTP_201_CREATED + + response_content = parse_xml(BytesIO(response.content)) + deposit_id = response_content['deposit_id'] + + deposit = Deposit.objects.get(pk=deposit_id) + assert deposit.collection == deposit_collection + assert deposit.external_id == external_id + assert deposit.status == DEPOSIT_STATUS_DEPOSITED + + # one associated request to a deposit + deposit_request = DepositRequest.objects.get(deposit=deposit) + assert deposit_request.metadata is not None + assert deposit_request.raw_metadata == atom_entry_data.decode('utf-8') + assert bool(deposit_request.archive) is False -class DepositAtomEntryTestCase(APITestCase, WithAuthTestCase, BasicTestCase): - """Try and post atom entry deposit. +def test_post_deposit_atom_entry_multiple_steps( + authenticated_client, deposit_collection, atom_dataset): + """After initial deposit, updating a deposit should return a 201 """ - def setUp(self): - super().setUp() - - self.atom_entry_data0 = b""" - - Awesome Compiler - hal - urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a - %s - 2017-10-07T15:17:08Z - some awesome author - something - awesome-compiler - This is an awesome compiler destined to -awesomely compile stuff -and other stuff - compiler,programming,language - 2005-10-07T17:17:08Z - 2005-10-07T17:17:08Z - release note - related link - - Awesome - https://hoster.org/awesome-compiler - GNU/Linux - 0.0.1 - running - all -""" - - self.atom_entry_data1 = b""" - - hal - urn:uuid:2225c695-cfb8-4ebb-aaaa-80da344efa6a - 2017-10-07T15:17:08Z - some awesome author - something - awesome-compiler - This is an awesome compiler destined to -awesomely compile stuff -and other stuff - compiler,programming,language - 2005-10-07T17:17:08Z - 2005-10-07T17:17:08Z - release note - related link - - Awesome - https://hoster.org/awesome-compiler - GNU/Linux - 0.0.1 - running - all -""" - - self.atom_entry_data_badly_formatted = b""" -""" - - self.atom_error_with_decimal = b""" - - Composing a Web of Audio Applications - hal - hal-01243065 - hal-01243065 - https://hal-test.archives-ouvertes.fr/hal-01243065 - test - - - DSP programming,Web,Composability,Faust - 2017-05-03T16:08:47+02:00 - The Web offers a great opportunity to share, deploy and use programs without installation difficulties. In this article we explore the idea of freely combining/composing real-time audio applications deployed on the Web using Faust audio DSP language. - 1 - 10.4 - phpstorm - stable - - linux - php - python - C - - GNU General Public License v3.0 only - - - CeCILL Free Software License Agreement v1.1 - - - HAL - hal@ccsd.cnrs.fr - - - Someone Nice - someone@nice.fr - FFJ - - -""" # noqa - - def test_post_deposit_atom_201_even_with_decimal(self): - """Posting an initial atom entry should return 201 with deposit receipt - - """ - # given - # when - response = self.client.post( - reverse(COL_IRI, args=[self.collection.name]), - content_type='application/atom+xml;type=entry', - data=self.atom_error_with_decimal, - HTTP_SLUG='external-id', - HTTP_IN_PROGRESS='false') - - # then - self.assertEqual(response.status_code, status.HTTP_201_CREATED) - - response_content = parse_xml(BytesIO(response.content)) - deposit_id = response_content['deposit_id'] - - deposit = Deposit.objects.get(pk=deposit_id) - dr = DepositRequest.objects.get(deposit=deposit) - - self.assertIsNotNone(dr.metadata) - sw_version = dr.metadata.get('codemeta:softwareVersion') - self.assertEqual(sw_version, '10.4') - - def test_post_deposit_atom_400_with_empty_body(self): - """Posting empty body request should return a 400 response - - """ - atom_entry_data_empty_body = b""" -""" - - response = self.client.post( - reverse(COL_IRI, args=[self.collection.name]), - content_type='application/atom+xml;type=entry', - data=atom_entry_data_empty_body) - self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) - - def test_post_deposit_atom_400_badly_formatted_atom(self): - """Posting a badly formatted atom should return a 400 response - - """ - response = self.client.post( - reverse(COL_IRI, args=[self.collection.name]), - content_type='application/atom+xml;type=entry', - data=self.atom_entry_data_badly_formatted) - self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) - - def test_post_deposit_atom_400_with_parsing_error(self): - """Posting parsing error prone atom should return 400 - - """ - atom_entry_data_parsing_error_prone = b""" - - Composing a Web of Audio Applications - - -""" - response = self.client.post( - reverse(COL_IRI, args=[self.collection.name]), - content_type='application/atom+xml;type=entry', - data=atom_entry_data_parsing_error_prone) - self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) - - def test_post_deposit_atom_400_without_slug_header(self): - """Posting an atom entry without a slug header should return a 400 - - """ - url = reverse(COL_IRI, args=[self.collection.name]) - - # when - response = self.client.post( - url, - content_type='application/atom+xml;type=entry', - data=self.atom_entry_data0, - # + headers - HTTP_IN_PROGRESS='false') - - self.assertIn(b'Missing SLUG header', response.content) - self.assertEqual(response.status_code, - status.HTTP_400_BAD_REQUEST) - - def test_post_deposit_atom_404_unknown_collection(self): - """Posting an atom entry to an unknown collection should return a 404 - - """ - atom_entry_data3 = b""" - - something -""" - - response = self.client.post( - reverse(COL_IRI, args=['unknown-one']), - content_type='application/atom+xml;type=entry', - data=atom_entry_data3, - HTTP_SLUG='something') - self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) - - def test_post_deposit_atom_entry_initial(self): - """Posting an initial atom entry should return 201 with deposit receipt - - """ - # given - external_id = 'urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a' - - with self.assertRaises(Deposit.DoesNotExist): - Deposit.objects.get(external_id=external_id) - - atom_entry_data = self.atom_entry_data0 % external_id.encode('utf-8') - - # when - response = self.client.post( - reverse(COL_IRI, args=[self.collection.name]), - content_type='application/atom+xml;type=entry', - data=atom_entry_data, - HTTP_SLUG='external-id', - HTTP_IN_PROGRESS='false') - - # then - self.assertEqual(response.status_code, status.HTTP_201_CREATED) - - response_content = parse_xml(BytesIO(response.content)) - deposit_id = response_content['deposit_id'] - - deposit = Deposit.objects.get(pk=deposit_id) - self.assertEqual(deposit.collection, self.collection) - self.assertEqual(deposit.external_id, external_id) - self.assertEqual(deposit.status, DEPOSIT_STATUS_DEPOSITED) - self.assertEqual(deposit.client, self.user) - - # one associated request to a deposit - deposit_request = DepositRequest.objects.get(deposit=deposit) - self.assertIsNotNone(deposit_request.metadata) - self.assertEqual( - deposit_request.raw_metadata, atom_entry_data.decode('utf-8')) - self.assertFalse(bool(deposit_request.archive)) - - def test_post_deposit_atom_entry_with_codemeta(self): - """Posting an initial atom entry should return 201 with deposit receipt - - """ - # given - external_id = 'urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a' - - with self.assertRaises(Deposit.DoesNotExist): - Deposit.objects.get(external_id=external_id) - - atom_entry_data = b""" - - - - %s - hal-01587361 - https://hal.inria.fr/hal-01587361 - https://hal.inria.fr/hal-01587361/document - https://hal.inria.fr/hal-01587361/file/AffectationRO-v1.0.0.zip - doi:10.5281/zenodo.438684 - The assignment problem - AffectationRO - Gruenpeter, Morane - [INFO] Computer Science [cs] - [INFO.INFO-RO] Computer Science [cs]/Operations Research [cs.RO] - SOFTWARE - Project in OR: The assignment problemA java implementation for the assignment problem first release - description fr - 2015-06-01 - 2017-10-19 - en - - - url stable - Version sur hal - Version entre par lutilisateur - Mots-cls - Commentaire - Rfrence interne - - Collaboration/Projet - nom du projet - id - - Voir aussi - Financement - Projet ANR - Projet Europen - Platform/OS - Dpendances - Etat du dveloppement - - license - url spdx - - Outils de dveloppement- outil no1 - Outils de dveloppement- outil no2 - http://code.com - language 1 - language 2 - """ % external_id.encode('utf-8') # noqa - - # when - response = self.client.post( - reverse(COL_IRI, args=[self.collection.name]), - content_type='application/atom+xml;type=entry', - data=atom_entry_data, - HTTP_SLUG='external-id', - HTTP_IN_PROGRESS='false') - - # then - self.assertEqual(response.status_code, status.HTTP_201_CREATED) - - response_content = parse_xml(BytesIO(response.content)) - - deposit_id = response_content['deposit_id'] - - deposit = Deposit.objects.get(pk=deposit_id) - self.assertEqual(deposit.collection, self.collection) - self.assertEqual(deposit.external_id, external_id) - self.assertEqual(deposit.status, DEPOSIT_STATUS_DEPOSITED) - self.assertEqual(deposit.client, self.user) - - # one associated request to a deposit - deposit_request = DepositRequest.objects.get(deposit=deposit) - self.assertIsNotNone(deposit_request.metadata) - self.assertEqual( - deposit_request.raw_metadata, atom_entry_data.decode('utf-8')) - - self.assertFalse(bool(deposit_request.archive)) - - def test_post_deposit_atom_entry_tei(self): - """Posting initial atom entry as TEI should return 201 with receipt - - """ - # given - external_id = 'urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a' - with self.assertRaises(Deposit.DoesNotExist): - Deposit.objects.get(external_id=external_id) - - atom_entry_data = b"""HAL TEI export of hal-01587083CCSDDistributed under a Creative Commons Attribution 4.0 International License

HAL API platform

questionnaire software metadataMoraneGruenpeter7de56c632362954fa84172cad80afe4einria.fr1556733MoraneGruenpeterf85a43a5fb4a2e0778a77e017f28c8fdgmail.com2017-09-29 11:21:322017-10-03 17:20:132017-10-03 17:20:132017-09-292017-09-29contributorMoraneGruenpeterf85a43a5fb4a2e0778a77e017f28c8fdgmail.comCCSDhal-01587083https://hal.inria.fr/hal-01587083gruenpeter:hal-0158708320172017questionnaire software metadataMoraneGruenpeter7de56c632362954fa84172cad80afe4einria.fr1556733EnglishComputer Science [cs]SoftwareIRILLInitiative pour la Recherche et l'Innovation sur le Logiciel Libre
https://www.irill.org/
Universite Pierre et Marie Curie - Paris 6UPMC
4 place Jussieu - 75005 Paris
http://www.upmc.fr/
Institut National de Recherche en Informatique et en AutomatiqueInria
Domaine de VoluceauRocquencourt - BP 10578153 Le Chesnay Cedex
http://www.inria.fr/en/
Universite Paris Diderot - Paris 7UPD7
5 rue Thomas-Mann - 75205 Paris cedex 13
http://www.univ-paris-diderot.fr
""" # noqa - - # when - response = self.client.post( - reverse(COL_IRI, args=[self.collection.name]), - content_type='application/atom+xml;type=entry', - data=atom_entry_data, - HTTP_SLUG=external_id, - HTTP_IN_PROGRESS='false') - - # then - self.assertEqual(response.status_code, status.HTTP_201_CREATED) - - response_content = parse_xml(BytesIO(response.content)) - deposit_id = response_content['deposit_id'] - - deposit = Deposit.objects.get(pk=deposit_id) - self.assertEqual(deposit.collection, self.collection) - self.assertEqual(deposit.external_id, external_id) - self.assertEqual(deposit.status, DEPOSIT_STATUS_DEPOSITED) - self.assertEqual(deposit.client, self.user) - - # one associated request to a deposit - deposit_request = DepositRequest.objects.get(deposit=deposit) - self.assertIsNotNone(deposit_request.metadata) - self.assertEqual( - deposit_request.raw_metadata, atom_entry_data.decode('utf-8')) - self.assertFalse(bool(deposit_request.archive)) - - def test_post_deposit_atom_entry_multiple_steps(self): - """After initial deposit, updating a deposit should return a 201 - - """ - # given - external_id = 'urn:uuid:2225c695-cfb8-4ebb-aaaa-80da344efa6a' - - with self.assertRaises(Deposit.DoesNotExist): - deposit = Deposit.objects.get(external_id=external_id) - - # when - response = self.client.post( - reverse(COL_IRI, args=[self.collection.name]), - content_type='application/atom+xml;type=entry', - data=self.atom_entry_data1, - HTTP_IN_PROGRESS='True', - HTTP_SLUG=external_id) - - # then - self.assertEqual(response.status_code, status.HTTP_201_CREATED) - - response_content = parse_xml(BytesIO(response.content)) - deposit_id = int(response_content['deposit_id']) - - deposit = Deposit.objects.get(pk=deposit_id) - self.assertEqual(deposit.collection, self.collection) - self.assertEqual(deposit.external_id, external_id) - self.assertEqual(deposit.status, 'partial') - self.assertEqual(deposit.client, self.user) - - # one associated request to a deposit - deposit_requests = DepositRequest.objects.filter(deposit=deposit) - self.assertEqual(len(deposit_requests), 1) - - atom_entry_data = b""" - - %s -""" % external_id.encode('utf-8') - - update_uri = response._headers['location'][1] - - # when updating the first deposit post - response = self.client.post( - update_uri, - content_type='application/atom+xml;type=entry', - data=atom_entry_data, - HTTP_IN_PROGRESS='False') - - # then - self.assertEqual(response.status_code, status.HTTP_201_CREATED) - - response_content = parse_xml(BytesIO(response.content)) - deposit_id = int(response_content['deposit_id']) - - deposit = Deposit.objects.get(pk=deposit_id) - self.assertEqual(deposit.collection, self.collection) - self.assertEqual(deposit.external_id, external_id) - self.assertEqual(deposit.status, DEPOSIT_STATUS_DEPOSITED) - self.assertEqual(deposit.client, self.user) - - self.assertEqual(len(Deposit.objects.all()), 1) - - # now 2 associated requests to a same deposit - deposit_requests = DepositRequest.objects.filter( - deposit=deposit).order_by('id') - self.assertEqual(len(deposit_requests), 2) - - expected_meta = [ - { - 'metadata': parse_xml(self.atom_entry_data1), - 'raw_metadata': self.atom_entry_data1.decode('utf-8'), - }, - { - 'metadata': parse_xml(atom_entry_data), - 'raw_metadata': atom_entry_data.decode('utf-8'), - } - ] - - for i, deposit_request in enumerate(deposit_requests): - actual_metadata = deposit_request.metadata - self.assertEqual(actual_metadata, - expected_meta[i]['metadata']) - self.assertEqual(deposit_request.raw_metadata, - expected_meta[i]['raw_metadata']) - self.assertFalse(bool(deposit_request.archive)) + # given + external_id = 'urn:uuid:2225c695-cfb8-4ebb-aaaa-80da344efa6a' + + with pytest.raises(Deposit.DoesNotExist): + deposit = Deposit.objects.get(external_id=external_id) + + # when + response = authenticated_client.post( + reverse(COL_IRI, args=[deposit_collection.name]), + content_type='application/atom+xml;type=entry', + data=atom_dataset['entry-data1'], + HTTP_IN_PROGRESS='True', + HTTP_SLUG=external_id) + + # then + assert response.status_code == status.HTTP_201_CREATED + + response_content = parse_xml(BytesIO(response.content)) + deposit_id = int(response_content['deposit_id']) + + deposit = Deposit.objects.get(pk=deposit_id) + assert deposit.collection == deposit_collection + assert deposit.external_id == external_id + assert deposit.status == 'partial' + + # one associated request to a deposit + deposit_requests = DepositRequest.objects.filter(deposit=deposit) + assert len(deposit_requests) == 1 + + atom_entry_data = atom_dataset['entry-data-minimal'] % external_id.encode('utf-8') # noqa + + update_uri = response._headers['location'][1] + + # when updating the first deposit post + response = authenticated_client.post( + update_uri, + content_type='application/atom+xml;type=entry', + data=atom_entry_data, + HTTP_IN_PROGRESS='False') + + # then + assert response.status_code == status.HTTP_201_CREATED + + response_content = parse_xml(BytesIO(response.content)) + deposit_id = int(response_content['deposit_id']) + + deposit = Deposit.objects.get(pk=deposit_id) + assert deposit.collection == deposit_collection + assert deposit.external_id == external_id + assert deposit.status == DEPOSIT_STATUS_DEPOSITED + + assert len(Deposit.objects.all()) == 1 + + # now 2 associated requests to a same deposit + deposit_requests = DepositRequest.objects.filter( + deposit=deposit).order_by('id') + assert len(deposit_requests) == 2 + + atom_entry_data1 = atom_dataset['entry-data1'] + expected_meta = [ + { + 'metadata': parse_xml(atom_entry_data1), + 'raw_metadata': atom_entry_data1.decode('utf-8'), + }, + { + 'metadata': parse_xml(atom_entry_data), + 'raw_metadata': atom_entry_data.decode('utf-8'), + } + ] + + for i, deposit_request in enumerate(deposit_requests): + actual_metadata = deposit_request.metadata + assert actual_metadata == expected_meta[i]['metadata'] + assert deposit_request.raw_metadata == expected_meta[i]['raw_metadata'] + assert bool(deposit_request.archive) is False