Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ENG-6673] Check and fix api3_and_osf tests, excluding ElasticSearch and SHARE related failures #10844

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions api_tests/collections/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Comment on lines -3897 to +3904
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fix looks good!

TODO for myself: check with Product & QA on collections


def test_linked_preprints_returns_everything(
self, app, url_collection_linked_preprints,
Expand Down
1 change: 1 addition & 0 deletions api_tests/wb/views/test_wb_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 6 additions & 2 deletions osf/management/commands/check_crossref_dois.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -82,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,
)
Comment on lines -85 to +89
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Future: let's use .load_referent()

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
Loading