diff --git a/.gitignore b/.gitignore --- a/.gitignore +++ b/.gitignore @@ -20,3 +20,4 @@ *.tar.gz *.tar.bz2 *.tar.lzma +.tox/ diff --git a/pytest.ini b/pytest.ini --- a/pytest.ini +++ b/pytest.ini @@ -1,2 +1,3 @@ [pytest] norecursedirs = docs +DJANGO_SETTINGS_MODULE = swh.deposit.settings.testing diff --git a/requirements-test.txt b/requirements-test.txt --- a/requirements-test.txt +++ b/requirements-test.txt @@ -1,2 +1,2 @@ -nose -django_nose +pytest +pytest-django diff --git a/swh/deposit/settings/testing.py b/swh/deposit/settings/testing.py --- a/swh/deposit/settings/testing.py +++ b/swh/deposit/settings/testing.py @@ -8,13 +8,10 @@ from .development import * # noqa from .development import INSTALLED_APPS -# django-nose setup +# django setup ALLOWED_HOSTS += ['testserver'] -INSTALLED_APPS += ['django_nose'] - -TEST_RUNNER = 'django_nose.NoseTestSuiteRunner' -NOSE_ARGS = ['--verbosity=3', '-s'] # to see test pass +INSTALLED_APPS += ['pytest_django'] # https://docs.djangoproject.com/en/1.10/ref/settings/#logging LOGGING = { diff --git a/swh/deposit/tests/api/test_deposit.py b/swh/deposit/tests/api/test_deposit.py --- a/swh/deposit/tests/api/test_deposit.py +++ b/swh/deposit/tests/api/test_deposit.py @@ -95,10 +95,10 @@ HTTP_PACKAGING='http://purl.org/net/sword/package/SimpleZip', HTTP_CONTENT_DISPOSITION='attachment; filename=filename0') - self.assertEquals(response.status_code, status.HTTP_201_CREATED) + self.assertEqual(response.status_code, status.HTTP_201_CREATED) response_content = parse_xml(BytesIO(response.content)) actual_state = response_content['deposit_status'] - self.assertEquals(actual_state, DEPOSIT_STATUS_REJECTED) + self.assertEqual(actual_state, DEPOSIT_STATUS_REJECTED) def test_act_on_deposit_rejected_is_not_permitted(self): deposit_id = self.create_deposit_with_status(DEPOSIT_STATUS_REJECTED) @@ -112,7 +112,7 @@ data=self.atom_entry_data1, HTTP_SLUG='external-id') - self.assertEquals(response.status_code, status.HTTP_400_BAD_REQUEST) + self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) self.assertRegex( response.content.decode('utf-8'), "You can only act on deposit with status '%s'" % ( @@ -126,8 +126,8 @@ deposit1 = Deposit.objects.get(pk=deposit_id) self.assertIsNotNone(deposit1) - self.assertEquals(deposit1.external_id, 'some-external-id') - self.assertEquals(deposit1.status, DEPOSIT_STATUS_LOAD_SUCCESS) + self.assertEqual(deposit1.external_id, 'some-external-id') + self.assertEqual(deposit1.status, DEPOSIT_STATUS_LOAD_SUCCESS) deposit_id2 = self.create_deposit_with_status( status=DEPOSIT_STATUS_LOAD_SUCCESS, @@ -135,8 +135,8 @@ deposit2 = Deposit.objects.get(pk=deposit_id2) self.assertIsNotNone(deposit2) - self.assertEquals(deposit2.external_id, 'some-external-id') - self.assertEquals(deposit2.status, DEPOSIT_STATUS_LOAD_SUCCESS) + self.assertEqual(deposit2.external_id, 'some-external-id') + self.assertEqual(deposit2.status, DEPOSIT_STATUS_LOAD_SUCCESS) deposit_id3 = self.create_deposit_with_status( status=DEPOSIT_STATUS_LOAD_FAILURE, @@ -144,8 +144,8 @@ deposit3 = Deposit.objects.get(pk=deposit_id3) self.assertIsNotNone(deposit3) - self.assertEquals(deposit3.external_id, 'some-external-id') - self.assertEquals(deposit3.status, DEPOSIT_STATUS_LOAD_FAILURE) + self.assertEqual(deposit3.external_id, 'some-external-id') + self.assertEqual(deposit3.status, DEPOSIT_STATUS_LOAD_FAILURE) # when deposit_id3 = self.create_simple_deposit_partial( @@ -155,6 +155,6 @@ deposit4 = Deposit.objects.get(pk=deposit_id3) self.assertIsNotNone(deposit4) - self.assertEquals(deposit4.external_id, 'some-external-id') - self.assertEquals(deposit4.status, DEPOSIT_STATUS_PARTIAL) - self.assertEquals(deposit4.parent, deposit2) + self.assertEqual(deposit4.external_id, 'some-external-id') + self.assertEqual(deposit4.status, DEPOSIT_STATUS_PARTIAL) + self.assertEqual(deposit4.parent, deposit2) diff --git a/swh/deposit/tests/api/test_deposit_atom.py b/swh/deposit/tests/api/test_deposit_atom.py --- a/swh/deposit/tests/api/test_deposit_atom.py +++ b/swh/deposit/tests/api/test_deposit_atom.py @@ -274,7 +274,7 @@ self.assertIsNotNone(dr.metadata) sw_version = dr.metadata.get('codemeta:softwareVersion') - self.assertEquals(sw_version, '10.4') + self.assertEqual(sw_version, '10.4') def test_post_deposit_atom_empty_body_request(self): """Posting empty body request should return a 400 response @@ -360,7 +360,7 @@ # one associated request to a deposit deposit_request = DepositRequest.objects.get(deposit=deposit) self.assertIsNotNone(deposit_request.metadata) - self.assertEquals( + self.assertEqual( deposit_request.raw_metadata, atom_entry_data.decode('utf-8')) self.assertFalse(bool(deposit_request.archive)) @@ -401,7 +401,7 @@ # one associated request to a deposit deposit_request = DepositRequest.objects.get(deposit=deposit) self.assertIsNotNone(deposit_request.metadata) - self.assertEquals( + self.assertEqual( deposit_request.raw_metadata, atom_entry_data.decode('utf-8')) self.assertFalse(bool(deposit_request.archive)) @@ -440,7 +440,7 @@ # one associated request to a deposit deposit_request = DepositRequest.objects.get(deposit=deposit) self.assertIsNotNone(deposit_request.metadata) - self.assertEquals( + self.assertEqual( deposit_request.raw_metadata, atom_entry_data.decode('utf-8')) self.assertFalse(bool(deposit_request.archive)) @@ -521,8 +521,8 @@ for i, deposit_request in enumerate(deposit_requests): actual_metadata = deposit_request.metadata - self.assertEquals(actual_metadata, - expected_meta[i]['metadata']) - self.assertEquals(deposit_request.raw_metadata, - expected_meta[i]['raw_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)) diff --git a/swh/deposit/tests/api/test_deposit_binary.py b/swh/deposit/tests/api/test_deposit_binary.py --- a/swh/deposit/tests/api/test_deposit_binary.py +++ b/swh/deposit/tests/api/test_deposit_binary.py @@ -183,7 +183,7 @@ self.assertIsNone(deposit.swh_id) deposit_request = DepositRequest.objects.get(deposit=deposit) - self.assertEquals(deposit_request.deposit, deposit) + self.assertEqual(deposit_request.deposit, deposit) self.assertRegex(deposit_request.archive.name, self.archive['name']) self.assertIsNone(deposit_request.metadata) self.assertIsNone(deposit_request.raw_metadata) @@ -446,8 +446,8 @@ self.assertIsNone(deposit.swh_id) deposit_request = DepositRequest.objects.get(deposit=deposit) - self.assertEquals(deposit_request.deposit, deposit) - self.assertEquals(deposit_request.type.name, 'archive') + self.assertEqual(deposit_request.deposit, deposit) + self.assertEqual(deposit_request.type.name, 'archive') self.assertRegex(deposit_request.archive.name, self.archive['name']) # 2nd archive to upload @@ -484,14 +484,14 @@ order_by('id')) # 2 deposit requests for the same deposit - self.assertEquals(len(deposit_requests), 2) - self.assertEquals(deposit_requests[0].deposit, deposit) - self.assertEquals(deposit_requests[0].type.name, 'archive') + self.assertEqual(len(deposit_requests), 2) + self.assertEqual(deposit_requests[0].deposit, deposit) + self.assertEqual(deposit_requests[0].type.name, 'archive') self.assertRegex(deposit_requests[0].archive.name, self.archive['name']) - self.assertEquals(deposit_requests[1].deposit, deposit) - self.assertEquals(deposit_requests[1].type.name, 'archive') + self.assertEqual(deposit_requests[1].deposit, deposit) + self.assertEqual(deposit_requests[1].type.name, 'archive') self.assertRegex(deposit_requests[1].archive.name, archive2['name']) @@ -534,7 +534,7 @@ self.assertIsNone(deposit.swh_id) deposit_request = DepositRequest.objects.get(deposit=deposit) - self.assertEquals(deposit_request.deposit, deposit) + self.assertEqual(deposit_request.deposit, deposit) self.assertRegex(deposit_request.archive.name, 'filename0') # updating/adding is forbidden @@ -564,7 +564,7 @@ HTTP_IN_PROGRESS='false', HTTP_CONTENT_DISPOSITION='attachment; filename=filename0') - self.assertEquals(r.status_code, status.HTTP_400_BAD_REQUEST) + self.assertEqual(r.status_code, status.HTTP_400_BAD_REQUEST) # adding file is no longer possible since the deposit's status # is ready @@ -579,7 +579,7 @@ HTTP_IN_PROGRESS='false', HTTP_CONTENT_DISPOSITION='attachment; filename=filename0') - self.assertEquals(r.status_code, status.HTTP_400_BAD_REQUEST) + self.assertEqual(r.status_code, status.HTTP_400_BAD_REQUEST) # replacing metadata is no longer possible since the deposit's # status is ready @@ -590,7 +590,7 @@ CONTENT_LENGTH=len(self.data_atom_entry_ok), HTTP_SLUG=external_id) - self.assertEquals(r.status_code, status.HTTP_400_BAD_REQUEST) + self.assertEqual(r.status_code, status.HTTP_400_BAD_REQUEST) # adding new metadata is no longer possible since the # deposit's status is ready @@ -601,7 +601,7 @@ CONTENT_LENGTH=len(self.data_atom_entry_ok), HTTP_SLUG=external_id) - self.assertEquals(r.status_code, status.HTTP_400_BAD_REQUEST) + self.assertEqual(r.status_code, status.HTTP_400_BAD_REQUEST) archive_content = b'some content representing archive' archive = InMemoryUploadedFile( @@ -630,7 +630,7 @@ 'atom_entry': atom_entry, }) - self.assertEquals(r.status_code, status.HTTP_400_BAD_REQUEST) + self.assertEqual(r.status_code, status.HTTP_400_BAD_REQUEST) # adding new metadata is no longer possible since the # deposit's status is ready @@ -642,4 +642,4 @@ 'atom_entry': atom_entry, }) - self.assertEquals(r.status_code, status.HTTP_400_BAD_REQUEST) + self.assertEqual(r.status_code, status.HTTP_400_BAD_REQUEST) diff --git a/swh/deposit/tests/api/test_deposit_check.py b/swh/deposit/tests/api/test_deposit_check.py --- a/swh/deposit/tests/api/test_deposit_check.py +++ b/swh/deposit/tests/api/test_deposit_check.py @@ -6,7 +6,7 @@ import unittest from django.core.urlresolvers import reverse -from nose.plugins.attrib import attr +import pytest from rest_framework import status from rest_framework.test import APITestCase @@ -26,7 +26,7 @@ from ..common import FileSystemCreationRoutine -@attr('fs') +@pytest.mark.fs class CheckDepositTest(APITestCase, WithAuthTestCase, BasicTestCase, CommonCreationRoutine, FileSystemCreationRoutine): @@ -45,7 +45,7 @@ status_partial=False) deposit = Deposit.objects.get(pk=deposit_id) - self.assertEquals(deposit.status, DEPOSIT_STATUS_DEPOSITED) + self.assertEqual(deposit.status, DEPOSIT_STATUS_DEPOSITED) url = reverse(PRIVATE_CHECK_DEPOSIT, args=[self.collection.name, deposit.id]) @@ -56,7 +56,7 @@ data = response.json() self.assertEqual(data['status'], DEPOSIT_STATUS_VERIFIED) deposit = Deposit.objects.get(pk=deposit.id) - self.assertEquals(deposit.status, DEPOSIT_STATUS_VERIFIED) + self.assertEqual(deposit.status, DEPOSIT_STATUS_VERIFIED) def test_deposit_invalid_tarball(self): """Deposit with tarball (of 1 tarball) should fail the checks: rejected @@ -67,7 +67,7 @@ archive_extension) deposit = Deposit.objects.get(pk=deposit_id) - self.assertEquals(DEPOSIT_STATUS_DEPOSITED, deposit.status) + self.assertEqual(DEPOSIT_STATUS_DEPOSITED, deposit.status) url = reverse(PRIVATE_CHECK_DEPOSIT, args=[self.collection.name, deposit.id]) @@ -84,7 +84,7 @@ MANDATORY_ARCHIVE_INVALID) deposit = Deposit.objects.get(pk=deposit.id) - self.assertEquals(deposit.status, DEPOSIT_STATUS_REJECTED) + self.assertEqual(deposit.status, DEPOSIT_STATUS_REJECTED) def test_deposit_ko_missing_tarball(self): """Deposit without archive should fail the checks: rejected @@ -92,7 +92,7 @@ """ deposit_id = self.create_deposit_ready() # no archive, only atom deposit = Deposit.objects.get(pk=deposit_id) - self.assertEquals(DEPOSIT_STATUS_DEPOSITED, deposit.status) + self.assertEqual(DEPOSIT_STATUS_DEPOSITED, deposit.status) url = reverse(PRIVATE_CHECK_DEPOSIT, args=[self.collection.name, deposit.id]) @@ -108,7 +108,7 @@ self.assertEqual(details['archive'][0]['summary'], MANDATORY_ARCHIVE_MISSING) deposit = Deposit.objects.get(pk=deposit.id) - self.assertEquals(deposit.status, DEPOSIT_STATUS_REJECTED) + self.assertEqual(deposit.status, DEPOSIT_STATUS_REJECTED) def test_deposit_ko_unsupported_tarball(self): """Deposit with an unsupported tarball should fail the checks: rejected @@ -117,7 +117,7 @@ deposit_id = self.create_deposit_with_invalid_archive() deposit = Deposit.objects.get(pk=deposit_id) - self.assertEquals(DEPOSIT_STATUS_DEPOSITED, deposit.status) + self.assertEqual(DEPOSIT_STATUS_DEPOSITED, deposit.status) url = reverse(PRIVATE_CHECK_DEPOSIT, args=[self.collection.name, deposit.id]) @@ -145,7 +145,7 @@ self.assertEqual(details['url']['summary'], INCOMPATIBLE_URL_FIELDS) deposit = Deposit.objects.get(pk=deposit.id) - self.assertEquals(deposit.status, DEPOSIT_STATUS_REJECTED) + self.assertEqual(deposit.status, DEPOSIT_STATUS_REJECTED) def test_check_deposit_metadata_ok(self): """Proper deposit should succeed the checks (-> status ready) @@ -155,10 +155,10 @@ """ deposit_id = self.create_simple_binary_deposit(status_partial=True) deposit_id_metadata = self.add_metadata_to_deposit(deposit_id) - self.assertEquals(deposit_id, deposit_id_metadata) + self.assertEqual(deposit_id, deposit_id_metadata) deposit = Deposit.objects.get(pk=deposit_id) - self.assertEquals(deposit.status, DEPOSIT_STATUS_DEPOSITED) + self.assertEqual(deposit.status, DEPOSIT_STATUS_DEPOSITED) url = reverse(PRIVATE_CHECK_DEPOSIT, args=[self.collection.name, deposit.id]) @@ -170,7 +170,7 @@ self.assertEqual(data['status'], DEPOSIT_STATUS_VERIFIED) deposit = Deposit.objects.get(pk=deposit.id) - self.assertEquals(deposit.status, DEPOSIT_STATUS_VERIFIED) + self.assertEqual(deposit.status, DEPOSIT_STATUS_VERIFIED) class CheckMetadata(unittest.TestCase, SWHChecksDeposit): diff --git a/swh/deposit/tests/api/test_deposit_delete.py b/swh/deposit/tests/api/test_deposit_delete.py --- a/swh/deposit/tests/api/test_deposit_delete.py +++ b/swh/deposit/tests/api/test_deposit_delete.py @@ -27,7 +27,7 @@ deposit = Deposit.objects.get(pk=deposit_id) deposit_requests = DepositRequest.objects.filter(deposit=deposit) - self.assertEquals(len(deposit_requests), 2) + self.assertEqual(len(deposit_requests), 2) for dr in deposit_requests: if dr.type.name == ARCHIVE_KEY: continue @@ -46,9 +46,9 @@ deposit = Deposit.objects.get(pk=deposit_id) requests = list(DepositRequest.objects.filter(deposit=deposit)) - self.assertEquals(len(requests), 2) - self.assertEquals(requests[0].type.name, 'metadata') - self.assertEquals(requests[1].type.name, 'metadata') + self.assertEqual(len(requests), 2) + self.assertEqual(requests[0].type.name, 'metadata') + self.assertEqual(requests[1].type.name, 'metadata') def test_delete_archive_on_undefined_deposit_fails(self): """Delete undefined deposit returns a 404 response @@ -64,7 +64,7 @@ """Delete !partial status deposit should return a 400 response""" deposit_id = self.create_deposit_ready() deposit = Deposit.objects.get(pk=deposit_id) - self.assertEquals(deposit.status, DEPOSIT_STATUS_DEPOSITED) + self.assertEqual(deposit.status, DEPOSIT_STATUS_DEPOSITED) # when update_uri = reverse(EM_IRI, args=[self.collection.name, deposit_id]) @@ -90,9 +90,9 @@ self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT) deposit_requests = list(DepositRequest.objects.filter(deposit=deposit)) - self.assertEquals(deposit_requests, []) + self.assertEqual(deposit_requests, []) deposits = list(Deposit.objects.filter(pk=deposit_id)) - self.assertEquals(deposits, []) + self.assertEqual(deposits, []) def test_delete_on_edit_se_iri_cannot_delete_non_partial_deposit(self): """Delete !partial deposit should return a 400 response diff --git a/swh/deposit/tests/api/test_deposit_list.py b/swh/deposit/tests/api/test_deposit_list.py --- a/swh/deposit/tests/api/test_deposit_list.py +++ b/swh/deposit/tests/api/test_deposit_list.py @@ -4,7 +4,7 @@ # See top-level LICENSE file for more information from django.core.urlresolvers import reverse -from nose.plugins.attrib import attr +import pytest from rest_framework import status from rest_framework.test import APITestCase @@ -15,7 +15,7 @@ from ...models import Deposit -@attr('fs') +@pytest.mark.fs class CheckDepositListTest(APITestCase, WithAuthTestCase, BasicTestCase, CommonCreationRoutine): """Check deposit list endpoints. @@ -73,10 +73,10 @@ self.assertIsNone(data['previous']) self.assertEqual(len(data['results']), 1) # page of size 1 deposit = data['results'][0] - self.assertEquals(deposit['id'], deposit_id) - self.assertEquals(deposit['status'], DEPOSIT_STATUS_PARTIAL) + self.assertEqual(deposit['id'], deposit_id) + self.assertEqual(deposit['status'], DEPOSIT_STATUS_PARTIAL) expected_status_detail = convert_status_detail(status_detail) - self.assertEquals(deposit['status_detail'], expected_status_detail) + self.assertEqual(deposit['status_detail'], expected_status_detail) # then 2nd page response2 = self.client.get(expected_next) @@ -90,5 +90,5 @@ self.assertTrue(data2['previous'].endswith(expected_previous)) self.assertEqual(len(data2['results']), 1) # page of size 1 deposit2 = data2['results'][0] - self.assertEquals(deposit2['id'], deposit_id2) - self.assertEquals(deposit2['status'], DEPOSIT_STATUS_PARTIAL) + self.assertEqual(deposit2['id'], deposit_id2) + self.assertEqual(deposit2['status'], DEPOSIT_STATUS_PARTIAL) diff --git a/swh/deposit/tests/api/test_deposit_multipart.py b/swh/deposit/tests/api/test_deposit_multipart.py --- a/swh/deposit/tests/api/test_deposit_multipart.py +++ b/swh/deposit/tests/api/test_deposit_multipart.py @@ -154,20 +154,20 @@ self.assertIsNone(deposit.swh_id) deposit_requests = DepositRequest.objects.filter(deposit=deposit) - self.assertEquals(len(deposit_requests), 2) + self.assertEqual(len(deposit_requests), 2) for deposit_request in deposit_requests: - self.assertEquals(deposit_request.deposit, deposit) + self.assertEqual(deposit_request.deposit, deposit) if deposit_request.type.name == 'archive': self.assertRegex(deposit_request.archive.name, self.archive['name']) self.assertIsNone(deposit_request.metadata) self.assertIsNone(deposit_request.raw_metadata) else: - self.assertEquals( + self.assertEqual( deposit_request.metadata['id'], 'urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a') - self.assertEquals(deposit_request.raw_metadata, - data_atom_entry.decode('utf-8')) + self.assertEqual(deposit_request.raw_metadata, + data_atom_entry.decode('utf-8')) def test_post_deposit_multipart_tar(self): """one multipart deposit (tar+xml) should be accepted @@ -223,20 +223,20 @@ self.assertIsNone(deposit.swh_id) deposit_requests = DepositRequest.objects.filter(deposit=deposit) - self.assertEquals(len(deposit_requests), 2) + self.assertEqual(len(deposit_requests), 2) for deposit_request in deposit_requests: - self.assertEquals(deposit_request.deposit, deposit) + self.assertEqual(deposit_request.deposit, deposit) if deposit_request.type.name == 'archive': self.assertRegex(deposit_request.archive.name, self.archive['name']) self.assertIsNone(deposit_request.metadata) self.assertIsNone(deposit_request.raw_metadata) else: - self.assertEquals( + self.assertEqual( deposit_request.metadata['id'], 'urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a') - self.assertEquals(deposit_request.raw_metadata, - data_atom_entry.decode('utf-8')) + self.assertEqual(deposit_request.raw_metadata, + data_atom_entry.decode('utf-8')) def test_post_deposit_multipart_put_to_replace_metadata(self): """One multipart deposit followed by a metadata update should be @@ -293,18 +293,18 @@ deposit_requests = DepositRequest.objects.filter(deposit=deposit) - self.assertEquals(len(deposit_requests), 2) + self.assertEqual(len(deposit_requests), 2) for deposit_request in deposit_requests: - self.assertEquals(deposit_request.deposit, deposit) + self.assertEqual(deposit_request.deposit, deposit) if deposit_request.type.name == 'archive': self.assertRegex(deposit_request.archive.name, self.archive['name']) else: - self.assertEquals( + self.assertEqual( deposit_request.metadata['id'], 'urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a') - self.assertEquals(deposit_request.raw_metadata, - data_atom_entry.decode('utf-8')) + self.assertEqual(deposit_request.raw_metadata, + data_atom_entry.decode('utf-8')) replace_metadata_uri = response._headers['location'][1] response = self.client.put( @@ -324,17 +324,17 @@ self.assertIsNone(deposit.swh_id) deposit_requests = DepositRequest.objects.filter(deposit=deposit) - self.assertEquals(len(deposit_requests), 2) + self.assertEqual(len(deposit_requests), 2) for deposit_request in deposit_requests: - self.assertEquals(deposit_request.deposit, deposit) + self.assertEqual(deposit_request.deposit, deposit) if deposit_request.type.name == 'archive': self.assertRegex(deposit_request.archive.name, self.archive['name']) else: - self.assertEquals( + self.assertEqual( deposit_request.metadata['id'], 'urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa7b') - self.assertEquals( + self.assertEqual( deposit_request.raw_metadata, self.data_atom_entry_update_in_place) diff --git a/swh/deposit/tests/api/test_deposit_read_archive.py b/swh/deposit/tests/api/test_deposit_read_archive.py --- a/swh/deposit/tests/api/test_deposit_read_archive.py +++ b/swh/deposit/tests/api/test_deposit_read_archive.py @@ -7,7 +7,7 @@ import os from django.core.urlresolvers import reverse -from nose.plugins.attrib import attr +import pytest from rest_framework import status from rest_framework.test import APITestCase @@ -19,7 +19,7 @@ from ..common import FileSystemCreationRoutine, create_arborescence_archive -@attr('fs') +@pytest.mark.fs class DepositReadArchivesTest(APITestCase, WithAuthTestCase, BasicTestCase, CommonCreationRoutine, FileSystemCreationRoutine): @@ -41,24 +41,24 @@ r = self.client.get(url) - self.assertEquals(r.status_code, status.HTTP_200_OK) - self.assertEquals(r._headers['content-type'][1], - 'application/octet-stream') + self.assertEqual(r.status_code, status.HTTP_200_OK) + self.assertEqual(r._headers['content-type'][1], + 'application/octet-stream') # read the stream data = b''.join(r.streaming_content) actual_sha1 = hashlib.sha1(data).hexdigest() - self.assertEquals(actual_sha1, self.archive['sha1sum']) + self.assertEqual(actual_sha1, self.archive['sha1sum']) # this does not touch the extraction dir so this should stay empty - self.assertEquals(os.listdir(TEST_CONFIG['extraction_dir']), []) + self.assertEqual(os.listdir(TEST_CONFIG['extraction_dir']), []) def _check_tarball_consistency(self, actual_sha1): tarball.uncompress(self.archive['path'], self.workdir) - self.assertEquals(os.listdir(self.workdir), ['file1']) + self.assertEqual(os.listdir(self.workdir), ['file1']) tarball.uncompress(self.archive2['path'], self.workdir) lst = set(os.listdir(self.workdir)) - self.assertEquals(lst, {'file1', 'file2'}) + self.assertEqual(lst, {'file1', 'file2'}) new_path = self.workdir + '.zip' tarball.compress(new_path, 'zip', self.workdir) @@ -80,9 +80,9 @@ r = self.client.get(url) - self.assertEquals(r.status_code, status.HTTP_200_OK) - self.assertEquals(r._headers['content-type'][1], - 'application/octet-stream') + self.assertEqual(r.status_code, status.HTTP_200_OK) + self.assertEqual(r._headers['content-type'][1], + 'application/octet-stream') # read the stream data = b''.join(r.streaming_content) actual_sha1 = hashlib.sha1(data).hexdigest() @@ -90,7 +90,7 @@ # this touches the extraction directory but should clean up # after itself - self.assertEquals(os.listdir(TEST_CONFIG['extraction_dir']), []) + self.assertEqual(os.listdir(TEST_CONFIG['extraction_dir']), []) class DepositReadArchivesFailureTest(APITestCase, WithAuthTestCase, diff --git a/swh/deposit/tests/api/test_deposit_read_metadata.py b/swh/deposit/tests/api/test_deposit_read_metadata.py --- a/swh/deposit/tests/api/test_deposit_read_metadata.py +++ b/swh/deposit/tests/api/test_deposit_read_metadata.py @@ -36,8 +36,8 @@ self.assertEqual(response.status_code, status.HTTP_200_OK) - self.assertEquals(response._headers['content-type'][1], - 'application/json') + self.assertEqual(response._headers['content-type'][1], + 'application/json') data = response.json() expected_meta = { @@ -87,7 +87,7 @@ 'branch_name': 'master', } - self.assertEquals(data, expected_meta) + self.assertEqual(data, expected_meta) def test_read_metadata_revision_with_parent(self): """Private read metadata to a deposit (with parent) returns metadata @@ -101,18 +101,18 @@ swh_id=swh_persistent_id) deposit_parent = Deposit.objects.get(pk=deposit_id1) - self.assertEquals(deposit_parent.swh_id, swh_persistent_id) - self.assertEquals(deposit_parent.external_id, 'some-external-id') - self.assertEquals(deposit_parent.status, DEPOSIT_STATUS_LOAD_SUCCESS) + self.assertEqual(deposit_parent.swh_id, swh_persistent_id) + self.assertEqual(deposit_parent.external_id, 'some-external-id') + self.assertEqual(deposit_parent.status, DEPOSIT_STATUS_LOAD_SUCCESS) deposit_id = self.create_deposit_partial( external_id='some-external-id') deposit = Deposit.objects.get(pk=deposit_id) - self.assertEquals(deposit.external_id, 'some-external-id') - self.assertEquals(deposit.swh_id, None) - self.assertEquals(deposit.parent, deposit_parent) - self.assertEquals(deposit.status, DEPOSIT_STATUS_PARTIAL) + self.assertEqual(deposit.external_id, 'some-external-id') + self.assertEqual(deposit.swh_id, None) + self.assertEqual(deposit.parent, deposit_parent) + self.assertEqual(deposit.status, DEPOSIT_STATUS_PARTIAL) url = reverse(PRIVATE_GET_DEPOSIT_METADATA, args=[self.collection.name, deposit_id]) @@ -121,8 +121,8 @@ self.assertEqual(response.status_code, status.HTTP_200_OK) - self.assertEquals(response._headers['content-type'][1], - 'application/json') + self.assertEqual(response._headers['content-type'][1], + 'application/json') data = response.json() expected_meta = { diff --git a/swh/deposit/tests/api/test_deposit_update.py b/swh/deposit/tests/api/test_deposit_update.py --- a/swh/deposit/tests/api/test_deposit_update.py +++ b/swh/deposit/tests/api/test_deposit_update.py @@ -86,13 +86,13 @@ deposit=deposit, type=self.deposit_request_types['archive']) - self.assertEquals(len(list(requests)), 1) + self.assertEqual(len(list(requests)), 1) self.assertRegex(requests[0].archive.name, self.archive2['name']) # check we did not touch the other parts requests = list(DepositRequest.objects.filter( deposit=deposit, type=self.deposit_request_types['metadata'])) - self.assertEquals(len(requests), 1) + self.assertEqual(len(requests), 1) def test_replace_metadata_to_deposit_is_possible(self): """Replace all metadata with another one should return a 204 response @@ -125,14 +125,14 @@ deposit=deposit, type=self.deposit_request_types['metadata']) - self.assertEquals(len(list(requests)), 1) + self.assertEqual(len(list(requests)), 1) metadata = requests[0].metadata - self.assertEquals(metadata['foobar'], 'bar') + self.assertEqual(metadata['foobar'], 'bar') # check we did not touch the other parts requests = list(DepositRequest.objects.filter( deposit=deposit, type=self.deposit_request_types['archive'])) - self.assertEquals(len(requests), 1) + self.assertEqual(len(requests), 1) def test_add_archive_to_deposit_is_possible(self): """Add another archive to a deposit return a 201 response @@ -176,7 +176,7 @@ deposit=deposit, type=self.deposit_request_types['archive']).order_by('id')) - self.assertEquals(len(requests), 2) + self.assertEqual(len(requests), 2) # first archive still exists self.assertRegex(requests[0].archive.name, self.archive['name']) # a new one was added @@ -185,7 +185,7 @@ # check we did not touch the other parts requests = list(DepositRequest.objects.filter( deposit=deposit, type=self.deposit_request_types['metadata'])) - self.assertEquals(len(requests), 0) + self.assertEqual(len(requests), 0) def test_add_metadata_to_deposit_is_possible(self): """Add metadata with another one should return a 204 response @@ -219,14 +219,14 @@ deposit=deposit, type=self.deposit_request_types['metadata']).order_by('id') - self.assertEquals(len(list(requests)), 3) + self.assertEqual(len(list(requests)), 3) # a new one was added - self.assertEquals(requests[1].metadata['foobar'], 'bar') + self.assertEqual(requests[1].metadata['foobar'], 'bar') # check we did not touch the other parts requests = list(DepositRequest.objects.filter( deposit=deposit, type=self.deposit_request_types['archive'])) - self.assertEquals(len(requests), 0) + self.assertEqual(len(requests), 0) class DepositUpdateFailuresTest(APITestCase, WithAuthTestCase, BasicTestCase, diff --git a/swh/deposit/tests/api/test_deposit_update_status.py b/swh/deposit/tests/api/test_deposit_update_status.py --- a/swh/deposit/tests/api/test_deposit_update_status.py +++ b/swh/deposit/tests/api/test_deposit_update_status.py @@ -47,7 +47,7 @@ self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT) deposit = Deposit.objects.get(pk=self.deposit.id) - self.assertEquals(deposit.status, _status) + self.assertEqual(deposit.status, _status) def test_update_deposit_status_with_info(self): """Existing status for update with info should return a 204 response @@ -80,12 +80,12 @@ self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT) deposit = Deposit.objects.get(pk=self.deposit.id) - self.assertEquals(deposit.status, expected_status) - self.assertEquals(deposit.swh_id, expected_swh_id) - self.assertEquals(deposit.swh_id_context, expected_swh_id_context) - self.assertEquals(deposit.swh_anchor_id, expected_swh_anchor_id) - self.assertEquals(deposit.swh_anchor_id_context, - expected_swh_anchor_id_context) + self.assertEqual(deposit.status, expected_status) + self.assertEqual(deposit.swh_id, expected_swh_id) + self.assertEqual(deposit.swh_id_context, expected_swh_id_context) + self.assertEqual(deposit.swh_anchor_id, expected_swh_anchor_id) + self.assertEqual(deposit.swh_anchor_id_context, + expected_swh_anchor_id_context) def test_update_deposit_status_will_fail_with_unknown_status(self): """Unknown status for update should return a 400 response diff --git a/swh/deposit/tests/api/test_service_document.py b/swh/deposit/tests/api/test_service_document.py --- a/swh/deposit/tests/api/test_service_document.py +++ b/swh/deposit/tests/api/test_service_document.py @@ -43,7 +43,7 @@ class ServiceDocumentCase(APITestCase, WithAuthTestCase, BasicTestCase): def assertResponseOk(self, response): # noqa: N802 self.assertEqual(response.status_code, status.HTTP_200_OK) - self.assertEquals(response.content.decode('utf-8'), + self.assertEqual(response.content.decode('utf-8'), '''