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-6721] Fixed api3_and_osf tests - Part 2 #10894

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
1 change: 0 additions & 1 deletion api_tests/actions/views/test_action_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ def test_bad_requests(self, app, url, preprint, provider, moderator):
('initial', 'edit_comment'),
('initial', 'reject'),
('initial', 'withdraw'),
('pending', 'submit'),
('rejected', 'reject'),
('rejected', 'submit'),
('rejected', 'withdraw'),
Expand Down
6 changes: 3 additions & 3 deletions osf/models/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ def coerce_guid(maybe_guid, create_if_needed=False):
raise InvalidGuid(f'guid does not exist ({maybe_guid})')
return guid
if isinstance(maybe_guid, str):
try:
return Guid.objects.get(_id=maybe_guid)
except Guid.DoesNotExist:
guid = Guid.load(maybe_guid)
if not guid:
raise InvalidGuid(f'guid does not exist ({maybe_guid})')
return guid
raise InvalidGuid(f'cannot coerce {type(maybe_guid)} ({maybe_guid}) into Guid')


Expand Down
23 changes: 18 additions & 5 deletions osf_tests/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -734,11 +734,24 @@ def _create(cls, target_class, *args, **kwargs):
# Step 1: create prerpint, guid and versioned guid
instance = cls._build(target_class, *args, **kwargs)
instance.save(guid_ready=False)
guid = models.Guid.objects.create(
referent=instance,
content_type=ContentType.objects.get_for_model(instance),
object_id=instance.pk,
)
# If use_guid is passed, use that guid instead of creating a new one
if use_guid := kwargs.pop('use_guid', None):
guid = use_guid
guid.referent = instance
guid.content_type = ContentType.objects.get_for_model(instance)
guid.object_id = instance.pk
guid.save()
else:
guid = models.Guid.objects.create(
referent=instance,
content_type=ContentType.objects.get_for_model(instance),
object_id=instance.pk,
)
# If guid__id is passed, set the guid's id to that value
if guid__id := kwargs.pop('set_guid', None):
guid._id = guid__id
guid.save()
cslzchen marked this conversation as resolved.
Show resolved Hide resolved

models.GuidVersionsThrough.objects.create(
referent=instance,
content_type=ContentType.objects.get_for_model(instance),
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 @@ -22,7 +22,7 @@ def preprint(self):

@pytest.fixture()
def stuck_preprint(self):
preprint = PreprintFactory(set_doi=False)
preprint = PreprintFactory(set_doi=False, set_guid='guid0')
preprint.date_published = preprint.date_published - timedelta(days=settings.DAYS_CROSSREF_DOIS_MUST_BE_STUCK_BEFORE_EMAIL + 1)
# match guid to the fixture crossref_works_response.json
guid = preprint.guids.first()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
],
"fundingReferences": [],
"identifier": {
"identifier": "11.pp/FK2osf.io/w4ibb",
"identifier": "11.pp/FK2osf.io/w4ibb_v1",
"identifierType": "DOI"
},
"publicationYear": "2123",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version='1.0' encoding='utf-8'?>
<resource xmlns="http://datacite.org/schema/kernel-4" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://datacite.org/schema/kernel-4 http://schema.datacite.org/meta/kernel-4.5/metadata.xsd">
<identifier identifierType="DOI">11.pp/FK2osf.io/w4ibb</identifier>
<identifier identifierType="DOI">11.pp/FK2osf.io/w4ibb_v1</identifier>
<creators>
<creator>
<creatorName nameType="Personal">Person McNamington</creatorName>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
dcterms:description "this is a preprint description!" ;
dcterms:hasVersion <https://doi.org/11.111/something-or-other> ;
dcterms:identifier "http://localhost:5000/w4ibb",
"https://doi.org/11.pp/FK2osf.io/w4ibb" ;
"https://doi.org/11.pp/FK2osf.io/w4ibb_v1" ;
dcterms:modified "2123-05-04" ;
dcterms:publisher <http://localhost:5000/preprints/preprovi> ;
dcterms:subject <http://localhost:8000/v2/subjects/subjwibb>,
Expand All @@ -22,7 +22,7 @@
<http://localhost:8000/v2/subjects/subjwobbb> ;
dcterms:title "this is a preprint title!" ;
dcterms:type <https://schema.datacite.org/meta/kernel-4/#Preprint> ;
owl:sameAs <https://doi.org/11.pp/FK2osf.io/w4ibb> ;
owl:sameAs <https://doi.org/11.pp/FK2osf.io/w4ibb_v1> ;
dcat:accessService <http://localhost:5000> ;
osf:hostingInstitution <https://cos.io/> ;
osf:isSupplementedBy <http://localhost:5000/w2ibb> ;
Expand Down Expand Up @@ -94,4 +94,3 @@
<http://localhost:8000/v2/subjects/subjwibbb> a skos:Concept ;
skos:inScheme <https://bepress.com/reference_guide_dc/disciplines/> ;
skos:prefLabel "wibbble" .

Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
],
"fundingReferences": [],
"identifier": {
"identifier": "11.pp/FK2osf.io/w4ibb",
"identifier": "11.pp/FK2osf.io/w4ibb_v1",
"identifierType": "DOI"
},
"publicationYear": "2123",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version='1.0' encoding='utf-8'?>
<resource xmlns="http://datacite.org/schema/kernel-4" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://datacite.org/schema/kernel-4 http://schema.datacite.org/meta/kernel-4.5/metadata.xsd">
<identifier identifierType="DOI">11.pp/FK2osf.io/w4ibb</identifier>
<identifier identifierType="DOI">11.pp/FK2osf.io/w4ibb_v1</identifier>
<creators>
<creator>
<creatorName nameType="Personal">Person McNamington</creatorName>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
dcterms:description "this is a preprint description!" ;
dcterms:hasVersion <https://doi.org/11.111/something-or-other> ;
dcterms:identifier "http://localhost:5000/w4ibb",
"https://doi.org/11.pp/FK2osf.io/w4ibb" ;
"https://doi.org/11.pp/FK2osf.io/w4ibb_v1" ;
dcterms:modified "2123-05-04" ;
dcterms:publisher <http://localhost:5000/preprints/preprovi> ;
dcterms:subject <http://localhost:8000/v2/subjects/subjwibb>,
Expand All @@ -22,7 +22,7 @@
<http://localhost:8000/v2/subjects/subjwobbb> ;
dcterms:title "this is a preprint title!" ;
dcterms:type <https://schema.datacite.org/meta/kernel-4/#Preprint> ;
owl:sameAs <https://doi.org/11.pp/FK2osf.io/w4ibb> ;
owl:sameAs <https://doi.org/11.pp/FK2osf.io/w4ibb_v1> ;
dcat:accessService <http://localhost:5000> ;
osf:hostingInstitution <https://cos.io/> ;
osf:isSupplementedBy <http://localhost:5000/w2ibb> ;
Expand Down Expand Up @@ -124,4 +124,3 @@
<http://localhost:8000/v2/subjects/subjwibbb> a skos:Concept ;
skos:inScheme <https://bepress.com/reference_guide_dc/disciplines/> ;
skos:prefLabel "wibbble" .

Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
"relationType": "HasVersion"
},
{
"relatedIdentifier": "11.pp/FK2osf.io/w4ibb",
"relatedIdentifier": "11.pp/FK2osf.io/w4ibb_v1",
"relatedIdentifierType": "DOI",
"relationType": "IsSupplementTo"
}
Expand All @@ -85,7 +85,7 @@
"publicationYear": "2123",
"publisher": "PP the Preprint Provider",
"relatedItemIdentifier": {
"relatedItemIdentifier": "11.pp/FK2osf.io/w4ibb",
"relatedItemIdentifier": "11.pp/FK2osf.io/w4ibb_v1",
"relatedItemIdentifierType": "DOI"
},
"relatedItemType": "Preprint",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
<fundingReferences/>
<relatedIdentifiers>
<relatedIdentifier relatedIdentifierType="URL" relationType="HasVersion">http://localhost:5000/w5ibb</relatedIdentifier>
<relatedIdentifier relatedIdentifierType="DOI" relationType="IsSupplementTo">11.pp/FK2osf.io/w4ibb</relatedIdentifier>
<relatedIdentifier relatedIdentifierType="DOI" relationType="IsSupplementTo">11.pp/FK2osf.io/w4ibb_v1</relatedIdentifier>
</relatedIdentifiers>
<relatedItems>
<relatedItem relationType="HasVersion" relatedItemType="StudyRegistration">
Expand All @@ -49,7 +49,7 @@
<publisher>RegiProvi the Registration Provider</publisher>
</relatedItem>
<relatedItem relationType="IsSupplementTo" relatedItemType="Preprint">
<relatedItemIdentifier relatedItemIdentifierType="DOI">11.pp/FK2osf.io/w4ibb</relatedItemIdentifier>
<relatedItemIdentifier relatedItemIdentifierType="DOI">11.pp/FK2osf.io/w4ibb_v1</relatedItemIdentifier>
<titles>
<title>this is a preprint title!</title>
</titles>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@
dcterms:created "2123-05-04" ;
dcterms:creator <http://localhost:5000/w1ibb> ;
dcterms:identifier "http://localhost:5000/w4ibb",
"https://doi.org/11.pp/FK2osf.io/w4ibb" ;
"https://doi.org/11.pp/FK2osf.io/w4ibb_v1" ;
dcterms:publisher <http://localhost:5000/preprints/preprovi> ;
dcterms:title "this is a preprint title!" ;
dcterms:type <https://schema.datacite.org/meta/kernel-4/#Preprint> ;
owl:sameAs <https://doi.org/11.pp/FK2osf.io/w4ibb> .
owl:sameAs <https://doi.org/11.pp/FK2osf.io/w4ibb_v1> .

<http://localhost:5000/w5ibb> a osf:Registration ;
dcterms:created "2123-05-04" ;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
"relationType": "HasVersion"
},
{
"relatedIdentifier": "11.pp/FK2osf.io/w4ibb",
"relatedIdentifier": "11.pp/FK2osf.io/w4ibb_v1",
"relatedIdentifierType": "DOI",
"relationType": "IsSupplementTo"
}
Expand All @@ -119,7 +119,7 @@
"publicationYear": "2123",
"publisher": "PP the Preprint Provider",
"relatedItemIdentifier": {
"relatedItemIdentifier": "11.pp/FK2osf.io/w4ibb",
"relatedItemIdentifier": "11.pp/FK2osf.io/w4ibb_v1",
"relatedItemIdentifierType": "DOI"
},
"relatedItemType": "Preprint",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
</fundingReferences>
<relatedIdentifiers>
<relatedIdentifier relatedIdentifierType="URL" relationType="HasVersion">http://localhost:5000/w5ibb</relatedIdentifier>
<relatedIdentifier relatedIdentifierType="DOI" relationType="IsSupplementTo">11.pp/FK2osf.io/w4ibb</relatedIdentifier>
<relatedIdentifier relatedIdentifierType="DOI" relationType="IsSupplementTo">11.pp/FK2osf.io/w4ibb_v1</relatedIdentifier>
</relatedIdentifiers>
<relatedItems>
<relatedItem relationType="HasVersion" relatedItemType="StudyRegistration">
Expand All @@ -67,7 +67,7 @@
<publisher>RegiProvi the Registration Provider</publisher>
</relatedItem>
<relatedItem relationType="IsSupplementTo" relatedItemType="Preprint">
<relatedItemIdentifier relatedItemIdentifierType="DOI">11.pp/FK2osf.io/w4ibb</relatedItemIdentifier>
<relatedItemIdentifier relatedItemIdentifierType="DOI">11.pp/FK2osf.io/w4ibb_v1</relatedItemIdentifier>
<titles>
<title>this is a preprint title!</title>
</titles>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@
dcterms:created "2123-05-04" ;
dcterms:creator <http://localhost:5000/w1ibb> ;
dcterms:identifier "http://localhost:5000/w4ibb",
"https://doi.org/11.pp/FK2osf.io/w4ibb" ;
"https://doi.org/11.pp/FK2osf.io/w4ibb_v1" ;
dcterms:publisher <http://localhost:5000/preprints/preprovi> ;
dcterms:title "this is a preprint title!" ;
dcterms:type <https://schema.datacite.org/meta/kernel-4/#Preprint> ;
owl:sameAs <https://doi.org/11.pp/FK2osf.io/w4ibb> .
owl:sameAs <https://doi.org/11.pp/FK2osf.io/w4ibb_v1> .

<http://localhost:5000/w5ibb> a osf:Registration ;
dcterms:created "2123-05-04" ;
Expand Down
2 changes: 1 addition & 1 deletion osf_tests/metadata/test_osf_gathering.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def test_setupdata(self):
assert self.registrationfocus.iri == OSFIO[self.registration._id]
assert self.registrationfocus.rdftype == OSF.Registration
assert self.registrationfocus.dbmodel is self.registration
assert self.preprintfocus.iri == OSFIO[self.preprint._id]
assert self.preprintfocus.iri == OSFIO[self.preprint.get_guid()._id]
assert self.preprintfocus.rdftype == OSF.Preprint
assert self.preprintfocus.dbmodel is self.preprint
assert self.filefocus.iri == OSFIO[self.file.get_guid()._id]
Expand Down
1 change: 1 addition & 0 deletions osf_tests/metadata/test_serialized_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ def setUp(self):
subjects=[
[parent_subject._id, child_subject._id],
],
use_guid=osfguid_sequence.get_or_create(id=-1)[0]
)
self.registration = factories.RegistrationFactory(
is_public=True,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ def _patch_settings(self):

@pytest.fixture
def item0(self):
_item0 = factories.PreprintFactory(is_public=True)
_item0._id = 'item0'
_item0 = factories.PreprintFactory(is_public=True, set_guid='item0')
return _item0

@pytest.fixture
Expand Down Expand Up @@ -186,7 +185,7 @@ def test_reporter(self, ym_empty, ym_sparse, ym_busy, sparse_month_usage, busy_m
_sparse_item0, _sparse_item1, _sparse_item2 = sorted(_sparse, key=attrgetter('item_osfid'))
# sparse-month item0
assert isinstance(_sparse_item0, PublicItemUsageReport)
assert _sparse_item0.item_osfid == 'item0'
assert _sparse_item0.item_osfid == 'item0_v1'
assert _sparse_item0.provider_id == [item0.provider._id]
assert _sparse_item0.platform_iri == ['http://osf.example']
assert _sparse_item0.view_count == 3
Expand Down Expand Up @@ -217,7 +216,7 @@ def test_reporter(self, ym_empty, ym_sparse, ym_busy, sparse_month_usage, busy_m
_busy_item0, _busy_item1, _busy_item2 = sorted(_busy, key=attrgetter('item_osfid'))
# busy-month item0
assert isinstance(_busy_item0, PublicItemUsageReport)
assert _busy_item0.item_osfid == 'item0'
assert _busy_item0.item_osfid == 'item0_v1'
assert _busy_item0.provider_id == [item0.provider._id]
assert _busy_item0.platform_iri == ['http://osf.example']
assert _busy_item0.view_count == 4 * 7
Expand Down
40 changes: 21 additions & 19 deletions osf_tests/test_guid.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
from unittest import mock
import pytest
from urllib.parse import quote

from django.utils import timezone
from django.core.exceptions import MultipleObjectsReturned
from framework.auth import Auth

import pytest

from osf.models import Guid, NodeLicenseRecord, OSFUser, GuidVersionsThrough
from framework.auth import Auth
from osf.models import Guid, GuidVersionsThrough, NodeLicenseRecord, OSFUser, Preprint
from osf.models.base import VersionedGuidMixin
from osf_tests.factories import AuthUserFactory, UserFactory, NodeFactory, NodeLicenseRecordFactory, \
RegistrationFactory, PreprintFactory, PreprintProviderFactory
from osf.utils.permissions import ADMIN
from osf.models import Preprint
from osf_tests.factories import (
AuthUserFactory,
NodeFactory,
NodeLicenseRecordFactory,
PreprintFactory,
PreprintProviderFactory,
RegistrationFactory,
UserFactory,
)
from tests.base import OsfTestCase
from tests.test_websitefiles import TestFile
from website.settings import MFR_SERVER_URL, WATERBUTLER_URL
Expand Down Expand Up @@ -45,6 +50,7 @@ def test_short_guid_gets_generated_on_creation(self, Factory):
assert obj._id
assert len(obj._id) == 5


@pytest.mark.django_db
class TestReferent:

Expand Down Expand Up @@ -458,6 +464,7 @@ def test_resolve_guid_download_errors(self):
res = self.app.get(pp.url + 'download', auth=non_contrib.auth)
assert res.status_code == 410


@pytest.fixture()
def creator():
return AuthUserFactory()
Expand All @@ -470,6 +477,7 @@ def auth(creator):
def preprint_provider():
return PreprintProviderFactory()


@pytest.mark.django_db
class TestGuidVersionsThrough:
def test_creation_versioned_guid(self, creator, preprint_provider):
Expand All @@ -480,19 +488,18 @@ def test_creation_versioned_guid(self, creator, preprint_provider):
description='Abstract'
)
assert preprint.guids.count() == 1
preprint_guid = preprint.guids.first()
version_entry = preprint.versioned_guids.first()
assert preprint.creator == creator
assert preprint.provider == preprint_provider
assert preprint.title == 'Preprint'
assert preprint.description == 'Abstract'

assert preprint_guid._id == version_entry.guid._id
preprint_guid = preprint.guids.first()
assert preprint_guid.referent == preprint
assert preprint_guid.content_type.model == 'preprint'
assert preprint_guid.object_id == preprint.pk
assert preprint_guid.is_versioned is True

version_entry = preprint.versioned_guids.first()
assert version_entry.guid == preprint_guid
assert version_entry.referent == preprint
assert version_entry.content_type.model == 'preprint'
Expand All @@ -505,7 +512,7 @@ def test_create_version(self, creator, preprint_provider):
preprint_guid = preprint.guids.first()

preprint_metadata = {
'subjects': [[el] for el in preprint.subjects.all().values_list('_id', flat=True)],
'subjects': [el for el in preprint.subjects.all().values_list('_id', flat=True)],
'original_publication_date': preprint.original_publication_date,
'custom_publication_citation': preprint.custom_publication_citation,
'article_doi': preprint.article_doi,
Expand All @@ -526,12 +533,8 @@ def test_create_version(self, creator, preprint_provider):
'copyright_holders': preprint.license.copyright_holders,
'year': preprint.license.year
}

auth = Auth(user=creator)
new_preprint, data_for_update = Preprint.create_version(
create_from_guid=preprint._id,
auth=auth
)
new_preprint, data_for_update = Preprint.create_version(create_from_guid=preprint._id, auth=auth)
tags = data_for_update.pop('tags')
assert list(tags) == list(preprint.tags.all().values_list('name', flat=True))
assert preprint_metadata == data_for_update
Expand Down Expand Up @@ -560,10 +563,9 @@ def test_versioned_preprint_id_property(self, creator, preprint_provider):
description='Abstract'
)
preprint_guid = preprint.guids.first()
expected_guid = f'{preprint_guid._id}{VersionedGuidMixin.GUID_VERSION_DELIMITER}1'

expected_guid = f'{preprint_guid._id}{VersionedGuidMixin.GUID_VERSION_DELIMITER}{VersionedGuidMixin.INITIAL_VERSION_NUMBER}'
assert preprint._id == expected_guid

GuidVersionsThrough.objects.filter(guid=preprint_guid).delete()

preprint._id = None
assert preprint._id is None
Loading