Skip to content

Commit

Permalink
fix: Subject.get_semantic_iri
Browse files Browse the repository at this point in the history
should use the iri for a subject's bepress synonym only when it has the
exact same text -- it was instead doing the opposite
  • Loading branch information
aaxelb committed Dec 8, 2023
1 parent c41bb4f commit 965302e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
1 change: 1 addition & 0 deletions api_tests/subjects/views/test_subject_detail.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def test_get_subject_detail(self, app, url_subject_detail, subject, subject_chil
assert 'parent' in data['relationships']
assert data['relationships']['parent']['data'] is None
assert data['relationships']['children']['links']['related']['meta']['count'] == 2
assert data['links']['iri'] == subject.get_semantic_iri()

# Follow children link
children_link = data['relationships']['children']['links']['related']['href']
Expand Down
2 changes: 1 addition & 1 deletion osf/models/subject.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def get_absolute_url(self):
def get_semantic_iri(self) -> str:
_identified_subject = (
self.bepress_subject
if self.bepress_subject and (self.text != self.bepress_subject.text)
if self.bepress_subject and (self.text == self.bepress_subject.text)
else self
)
return _identified_subject.absolute_api_v2_subject_url.rstrip('/')
Expand Down
16 changes: 16 additions & 0 deletions tests/test_subjects.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,3 +175,19 @@ def test_path(self):
assert self.bepress_child.path == 'bepress|BePress Text|BePress Child'
assert self.other_subj.path == 'asdf|Other Text'
assert self.other_child.path == 'asdf|Other Text|Other Child'

def test_get_semantic_iri(self):
_bepress_iri = self.bepress_subj.get_semantic_iri()
_other_iri = self.other_subj.get_semantic_iri()
assert _bepress_iri != _other_iri
assert _bepress_iri.endswith(self.bepress_subj._id)
assert _other_iri.endswith(self.other_subj._id)

# if a subject has the exact same text as its bepress synonym, expect the bepress subject iri
_sametext_subj = SubjectFactory(
text=self.bepress_subj.text,
bepress_subject=self.bepress_subj,
provider=self.asdf_provider,
)
_sametext_iri = _sametext_subj.get_semantic_iri()
assert _bepress_iri == _sametext_iri

0 comments on commit 965302e

Please sign in to comment.