Skip to content

Commit

Permalink
add test_gather_cedar_templates
Browse files Browse the repository at this point in the history
  • Loading branch information
adlius committed Jan 31, 2024
1 parent 002ab3b commit 64cbda4
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
2 changes: 1 addition & 1 deletion osf/models/cedar_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def __unicode__(self):
return f'(name=[{self.schema_name}], version=[{self.template_version}], id=[{self.cedar_id}])'

def get_semantic_iri(self):
return self.template['@id']
return self.cedar_id


class CedarMetadataRecord(ObjectIDMixin, BaseModel):
Expand Down
8 changes: 8 additions & 0 deletions osf_tests/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -1207,3 +1207,11 @@ class Meta:
class RegistrationBulkUploadRowFactory(DjangoModelFactory):
class Meta:
model = models.RegistrationBulkUploadRow

class CedarMetadataRecordFactory(DjangoModelFactory):
class Meta:
model = models.CedarMetadataRecord

class CedarMetadataTemplateFactory(DjangoModelFactory):
class Meta:
model = models.CedarMetadataTemplate
37 changes: 37 additions & 0 deletions osf_tests/metadata/test_osf_gathering.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,25 @@ def setUpTestData(cls):
'baiduScholar': 'blarg',
},
)
# cedar metadata template
cls.cedar_template = factories.CedarMetadataTemplateFactory(
cedar_id='https://repo.metadatacenter.org/templates/this-is-a-cedar-id',
schema_name='Hype Boy',
active=True,
template_version=1,
)
# project (with components):
cls.project = factories.ProjectFactory(creator=cls.user__admin, is_public=True)
cls.project.add_contributor(cls.user__readwrite, permissions=permissions.WRITE)
cls.project.add_contributor(cls.user__readonly, permissions=permissions.READ, visible=False)
cls.component = factories.ProjectFactory(parent=cls.project, creator=cls.user__admin, is_public=True)
cls.sibcomponent = factories.ProjectFactory(parent=cls.project, creator=cls.user__admin, is_public=True)
cls.subcomponent = factories.ProjectFactory(parent=cls.component, creator=cls.user__admin, is_public=True)
cls.project_cedar_record = factories.CedarMetadataRecordFactory(
template=cls.cedar_template,
is_published=True,
guid=cls.project.guids.first()
)
# file:
cls.file_sha256 = '876b99ba1225de6b7f55ef52b068d0da3aa2ec4271875954c3b87b6659ae3823'
cls.file = create_test_file(
Expand All @@ -58,6 +70,11 @@ def setUpTestData(cls):
filename='blarg.txt',
sha256=cls.file_sha256,
)
cls.file_cedar_reford = factories.CedarMetadataRecordFactory(
template=cls.cedar_template,
is_published=True,
guid=cls.file.get_guid()
)
# registration:
cls.registration = factories.RegistrationFactory(
project=cls.project,
Expand All @@ -73,6 +90,11 @@ def setUpTestData(cls):
)
cls.preprint.add_contributor(cls.user__readwrite, permissions=permissions.WRITE)
cls.preprint.add_contributor(cls.user__readonly, permissions=permissions.READ, visible=False)
cls.registration_cedar_record = factories.CedarMetadataRecordFactory(
template=cls.cedar_template,
is_published=True,
guid=cls.registration.guids.first()
)
# "focus" objects:
cls.projectfocus = osf_gathering.OsfFocus(cls.project)
cls.componentfocus = osf_gathering.OsfFocus(cls.component)
Expand Down Expand Up @@ -701,3 +723,18 @@ def test_gather_preprint_withdrawal(self):
(_withdrawal_bnode, DCTERMS.dateAccepted, Literal(str(_withdrawal_request.date_last_transitioned.date()))),
(_withdrawal_bnode, DCTERMS.creator, osf_gathering.OsfFocus(_withdrawal_request.creator)),
})

def test_gather_cedar_templates(self):
cedar_template_iri = rdflib.URIRef(self.cedar_template.cedar_id)
assert_triples(osf_gathering.gather_cedar_templates(self.projectfocus), {
(self.projectfocus.iri, OSF.hasCedarTemplate, cedar_template_iri),
(cedar_template_iri, DCTERMS.title, Literal(self.cedar_template.schema_name))
})
assert_triples(osf_gathering.gather_cedar_templates(self.registrationfocus), {
(self.registrationfocus.iri, OSF.hasCedarTemplate, cedar_template_iri),
(cedar_template_iri, DCTERMS.title, Literal(self.cedar_template.schema_name))
})
assert_triples(osf_gathering.gather_cedar_templates(self.filefocus), {
(self.filefocus.iri, OSF.hasCedarTemplate, cedar_template_iri),
(cedar_template_iri, DCTERMS.title, Literal(self.cedar_template.schema_name))
})

0 comments on commit 64cbda4

Please sign in to comment.