Skip to content

Commit

Permalink
Fix cressref tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Vlad0n20 committed Dec 17, 2024
1 parent eb1f141 commit ef6a82e
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 12 deletions.
11 changes: 6 additions & 5 deletions osf/management/commands/check_crossref_dois.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion osf_tests/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"crossmark-restriction": false
},
"abstract": "<p>Mock Abstract</p>",
"DOI": "10.31236/FK2osf.io/guid0",
"DOI": "10.31236/FK2osf.io/guid0_v1",
"type": "posted-content",
"created": {
"date-parts": [
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion osf_tests/management_commands/test_check_crossref_dois.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions tests/identifiers/test_crossref.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ef6a82e

Please sign in to comment.