Changeset View
Changeset View
Standalone View
Standalone View
swh/deposit/tests/api/test_deposit_multipart.py
Show First 20 Lines • Show All 394 Lines • ▼ Show 20 Lines | def test_post_deposit_multipart_only_archive_and_atom_entry(self): | ||||
# then | # then | ||||
self.assertEqual(response.status_code, | self.assertEqual(response.status_code, | ||||
status.HTTP_415_UNSUPPORTED_MEDIA_TYPE) | status.HTTP_415_UNSUPPORTED_MEDIA_TYPE) | ||||
self.assertTrue( | self.assertTrue( | ||||
'You must provide both 1 application/zip (or ' | 'You must provide both 1 application/zip (or ' | ||||
'application/x-tar) and 1 atom+xml entry for ' | 'application/x-tar) and 1 atom+xml entry for ' | ||||
'multipart deposit' in response.content.decode('utf-8') | 'multipart deposit' in response.content.decode('utf-8') | ||||
) | ) | ||||
def test_post_deposit_multipart_400_when_badly_formatted_xml(self): | |||||
# given | |||||
url = reverse(COL_IRI, args=[self.collection.name]) | |||||
data_atom_entry_ko = b"""<?xml version="1.0"?> | |||||
<entry xmlns="http://www.w3.org/2005/Atom" | |||||
xmlns:dcterms="http://purl.org/dc/terms/"> | |||||
<titleTitle</title> | |||||
<id>urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a</id> | |||||
moranegg: We need to review the tests to follow a more restrictive grammar. | |||||
</entry> | |||||
""" | |||||
archive_content = b'some content representing archive' | |||||
archive = InMemoryUploadedFile( | |||||
BytesIO(archive_content), | |||||
field_name='archive0', | |||||
name='archive0', | |||||
content_type='application/zip', | |||||
size=len(archive_content), | |||||
charset=None) | |||||
atom_entry = InMemoryUploadedFile( | |||||
BytesIO(data_atom_entry_ko), | |||||
field_name='atom0', | |||||
name='atom0', | |||||
content_type='application/atom+xml; charset="utf-8"', | |||||
size=len(data_atom_entry_ko), | |||||
charset='utf-8') | |||||
# when | |||||
response = self.client.post( | |||||
url, | |||||
format='multipart', | |||||
data={ | |||||
'archive': archive, | |||||
'atom_entry': atom_entry, | |||||
}, | |||||
# + headers | |||||
HTTP_IN_PROGRESS='false', | |||||
HTTP_SLUG='external-id', | |||||
) | |||||
self.assertIn(b'Malformed xml metadata', response.content) | |||||
self.assertEqual(response.status_code, | |||||
status.HTTP_400_BAD_REQUEST) |
We need to review the tests to follow a more restrictive grammar.