From 2a545995d6459b9934a6db5a58f2df01d702daee Mon Sep 17 00:00:00 2001 From: Vlad0n20 Date: Wed, 11 Dec 2024 21:34:01 +0200 Subject: [PATCH 1/3] Fix api_3 test, without elasticsearch and share related --- api_tests/collections/test_views.py | 6 +++--- api_tests/wb/views/test_wb_hooks.py | 1 + osf/management/commands/check_crossref_dois.py | 7 +++++-- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/api_tests/collections/test_views.py b/api_tests/collections/test_views.py index 6692b8915de..cfb0cec34f3 100644 --- a/api_tests/collections/test_views.py +++ b/api_tests/collections/test_views.py @@ -16,7 +16,7 @@ AuthUserFactory, SubjectFactory, ) -from osf.models import Collection +from osf.models import Collection, VersionedGuidMixin from osf.utils.sanitize import strip_html from osf.utils.permissions import ADMIN, WRITE, READ from website.project.signals import contributor_removed @@ -3906,7 +3906,7 @@ def test_linked_preprints_returns_everything( res = app.get(url_collection_linked_preprints, auth=user_one.auth) assert res.status_code == 200 - preprints_returned = [linked_preprint['id'] + preprints_returned = [linked_preprint['id'].split(VersionedGuidMixin.GUID_VERSION_DELIMITER)[0] for linked_preprint in res.json['data']] assert len(preprints_returned) == len(id_linked_preprints) @@ -3933,7 +3933,7 @@ def test_linked_preprints_only_return_viewable_preprints( collection._id), auth=user.auth) assert res.status_code == 200 - preprints_returned = [linked_preprint['id'] + preprints_returned = [linked_preprint['id'].split(VersionedGuidMixin.GUID_VERSION_DELIMITER)[0] for linked_preprint in res.json['data']] assert len(preprints_returned) == len(id_linked_preprints) diff --git a/api_tests/wb/views/test_wb_hooks.py b/api_tests/wb/views/test_wb_hooks.py index 471af387396..20c09b14e69 100644 --- a/api_tests/wb/views/test_wb_hooks.py +++ b/api_tests/wb/views/test_wb_hooks.py @@ -813,6 +813,7 @@ def test_copy_checked_out_file_in_folder(self, app, root_node, user, folder, fol 'name': folder_two.name, } }) + res = app.post_json(copy_url, signed_payload, expect_errors=True) assert res.status_code == 201 diff --git a/osf/management/commands/check_crossref_dois.py b/osf/management/commands/check_crossref_dois.py index e4d95e3c259..82fc7b5c263 100644 --- a/osf/management/commands/check_crossref_dois.py +++ b/osf/management/commands/check_crossref_dois.py @@ -12,7 +12,7 @@ import django django.setup() -from osf.models import Preprint +from osf.models import Preprint, VersionedGuidMixin logger = logging.getLogger(__name__) logging.basicConfig(level=logging.INFO) @@ -67,7 +67,10 @@ def check_crossref_dois(dry_run=True): pending_dois = [] for preprint in preprint_batch: prefix = preprint.provider.doi_prefix - pending_dois.append(f'doi:{settings.DOI_FORMAT.format(prefix=prefix, guid=preprint._id)}') + guid = preprint._id + if VersionedGuidMixin.GUID_VERSION_DELIMITER in preprint._id: + guid = preprint._id.split(VersionedGuidMixin.GUID_VERSION_DELIMITER)[0] + pending_dois.append(f'doi:{settings.DOI_FORMAT.format(prefix=prefix, guid=guid)}') url = '{}works?filter={}'.format(settings.CROSSREF_JSON_API_URL, ','.join(pending_dois)) From eb1f141d9f0f2660d61d54c4a9ad15a88784ea57 Mon Sep 17 00:00:00 2001 From: Vlad0n20 Date: Fri, 13 Dec 2024 15:28:29 +0200 Subject: [PATCH 2/3] Update id_linked_preprints for versioned guids --- api_tests/collections/test_views.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/api_tests/collections/test_views.py b/api_tests/collections/test_views.py index cfb0cec34f3..3f7d414663f 100644 --- a/api_tests/collections/test_views.py +++ b/api_tests/collections/test_views.py @@ -3894,10 +3894,14 @@ def url_collection_linked_preprints(self, collection): @pytest.fixture() def id_linked_preprints(self, collection): - return list( - collection.guid_links.values_list( - '_id', flat=True) - ) + res = [] + for guid in collection.guid_links.all(): + if guid.is_versioned: + for through_item in guid.versions.all(): + res.append(f'{guid._id}{VersionedGuidMixin.GUID_VERSION_DELIMITER}{through_item.version}') + else: + res.append(guid._id) + return res def test_linked_preprints_returns_everything( self, app, url_collection_linked_preprints, @@ -3906,7 +3910,7 @@ def test_linked_preprints_returns_everything( res = app.get(url_collection_linked_preprints, auth=user_one.auth) assert res.status_code == 200 - preprints_returned = [linked_preprint['id'].split(VersionedGuidMixin.GUID_VERSION_DELIMITER)[0] + preprints_returned = [linked_preprint['id'] for linked_preprint in res.json['data']] assert len(preprints_returned) == len(id_linked_preprints) @@ -3933,7 +3937,7 @@ def test_linked_preprints_only_return_viewable_preprints( collection._id), auth=user.auth) assert res.status_code == 200 - preprints_returned = [linked_preprint['id'].split(VersionedGuidMixin.GUID_VERSION_DELIMITER)[0] + preprints_returned = [linked_preprint['id'] for linked_preprint in res.json['data']] assert len(preprints_returned) == len(id_linked_preprints) From ef6a82e12764187df9ca73a095b2e43a7076ac08 Mon Sep 17 00:00:00 2001 From: Vlad0n20 Date: Tue, 17 Dec 2024 16:45:54 +0200 Subject: [PATCH 3/3] Fix cressref tests --- osf/management/commands/check_crossref_dois.py | 11 ++++++----- osf_tests/factories.py | 2 +- .../fixtures/crossref_works_response.json | 4 ++-- .../management_commands/test_check_crossref_dois.py | 2 +- tests/identifiers/test_crossref.py | 6 +++--- 5 files changed, 13 insertions(+), 12 deletions(-) diff --git a/osf/management/commands/check_crossref_dois.py b/osf/management/commands/check_crossref_dois.py index 82fc7b5c263..c834cdce922 100644 --- a/osf/management/commands/check_crossref_dois.py +++ b/osf/management/commands/check_crossref_dois.py @@ -67,10 +67,7 @@ def check_crossref_dois(dry_run=True): pending_dois = [] for preprint in preprint_batch: prefix = preprint.provider.doi_prefix - guid = preprint._id - if VersionedGuidMixin.GUID_VERSION_DELIMITER in preprint._id: - guid = preprint._id.split(VersionedGuidMixin.GUID_VERSION_DELIMITER)[0] - pending_dois.append(f'doi:{settings.DOI_FORMAT.format(prefix=prefix, guid=guid)}') + pending_dois.append(f'doi:{settings.DOI_FORMAT.format(prefix=prefix, guid=preprint._id)}') url = '{}works?filter={}'.format(settings.CROSSREF_JSON_API_URL, ','.join(pending_dois)) @@ -85,7 +82,11 @@ def check_crossref_dois(dry_run=True): for preprint in preprints_response: guid = preprint['DOI'].split('/')[-1] - pending_preprint = preprints_with_pending_dois.get(guids___id=guid) + base_guid, version = guid.split(VersionedGuidMixin.GUID_VERSION_DELIMITER) + pending_preprint = preprints_with_pending_dois.get( + versioned_guids__guid___id=base_guid, + versioned_guids__version=version, + ) if not dry_run: pending_preprint.set_identifier_values(preprint['DOI'], save=True) else: diff --git a/osf_tests/factories.py b/osf_tests/factories.py index ffeb48075e9..a0e5f66ef5b 100644 --- a/osf_tests/factories.py +++ b/osf_tests/factories.py @@ -845,7 +845,7 @@ def create_version(cls, create_from, creator=None, final_machine_state='accepted auth = Auth(instance.creator) instance.set_primary_file(preprint_file, auth=auth, save=True) from addons.osfstorage import settings as osfstorage_settings - location = { + location = { 'object': '06d80e', 'service': 'cloud', osfstorage_settings.WATERBUTLER_RESOURCE: 'osf', diff --git a/osf_tests/management_commands/fixtures/crossref_works_response.json b/osf_tests/management_commands/fixtures/crossref_works_response.json index 06ac5e57c33..a2a243904b5 100644 --- a/osf_tests/management_commands/fixtures/crossref_works_response.json +++ b/osf_tests/management_commands/fixtures/crossref_works_response.json @@ -50,7 +50,7 @@ "crossmark-restriction": false }, "abstract": "

Mock Abstract

", - "DOI": "10.31236/FK2osf.io/guid0", + "DOI": "10.31236/FK2osf.io/guid0_v1", "type": "posted-content", "created": { "date-parts": [ @@ -105,7 +105,7 @@ ] }, "references-count": 0, - "URL": "http://dx.doi.org/10.31236/osf.io/guid0", + "URL": "http://dx.doi.org/10.31236/osf.io/guid0_v1", "subtype": "preprint" }], "items-per-page": 20, diff --git a/osf_tests/management_commands/test_check_crossref_dois.py b/osf_tests/management_commands/test_check_crossref_dois.py index 1722cad3892..8a1e45cc975 100644 --- a/osf_tests/management_commands/test_check_crossref_dois.py +++ b/osf_tests/management_commands/test_check_crossref_dois.py @@ -43,7 +43,7 @@ def crossref_response(self): @responses.activate @mock.patch('osf.models.preprint.update_or_enqueue_on_preprint_updated', mock.Mock()) def test_check_crossref_dois(self, crossref_response, stuck_preprint, preprint): - doi = settings.DOI_FORMAT.format(prefix=stuck_preprint.provider.doi_prefix, guid=stuck_preprint.guids.first()._id) + doi = settings.DOI_FORMAT.format(prefix=stuck_preprint.provider.doi_prefix, guid=stuck_preprint._id) responses.add( responses.Response( responses.GET, diff --git a/tests/identifiers/test_crossref.py b/tests/identifiers/test_crossref.py index 7cb5518df46..719566d3571 100644 --- a/tests/identifiers/test_crossref.py +++ b/tests/identifiers/test_crossref.py @@ -165,12 +165,12 @@ def test_crossref_build_metadata_versioned(self, crossref_client, preprint_versi description = related_item.find('.//{%s}description' % crossref.CROSSREF_RELATIONS) assert description is not None - assert description.text == "Updated version" + assert description.text == 'Updated version' intra_work_relation = related_item.find('.//{%s}intra_work_relation' % crossref.CROSSREF_RELATIONS) assert intra_work_relation is not None - assert intra_work_relation.get('relationship-type') == "isVersionOf" - assert intra_work_relation.get('identifier-type') == "doi" + assert intra_work_relation.get('relationship-type') == 'isVersionOf' + assert intra_work_relation.get('identifier-type') == 'doi' assert intra_work_relation.text == settings.DOI_FORMAT.format(prefix=preprint.provider.doi_prefix, guid=preprint._id) @responses.activate