Skip to content

Commit

Permalink
add affiliated_institutions
Browse files Browse the repository at this point in the history
  • Loading branch information
John Tordoff committed Jul 18, 2024
1 parent 29cd008 commit 14e2103
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 32 deletions.
10 changes: 10 additions & 0 deletions api/preprints/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,16 @@ class PreprintSerializer(TaxonomizableSerializerMixin, MetricsSerializerMixin, J
related_view_kwargs={'preprint_id': '<_id>'},
))

affiliated_institutions = RelationshipField(
related_view='preprints:preprints-institutions',
related_view_kwargs={'preprint_id': '<_id>'},
self_view='preprints:preprints-institutions',
self_view_kwargs={'preprint_id': '<_id>'},
read_only=False,
required=False,
allow_null=True,
)

identifiers = NoneIfWithdrawal(RelationshipField(
related_view='preprints:identifier-list',
related_view_kwargs={'preprint_id': '<_id>'},
Expand Down
3 changes: 2 additions & 1 deletion api_tests/preprints/views/test_preprint_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,6 @@ def test_return_affiliated_institutions(self):
assert_equal(len(res.json['data']), 1)
assert_equal(res.status_code, 200)
assert_equal(res.content_type, 'application/vnd.api+json')
relationship_link = res.json['data'][0]['relationships']['affiliated_institutions']['links']['href']
print(res.json)
relationship_link = res.json['data'][0]['relationships']['affiliated_institutions']['links']['related']['href']
assert f'/v2/preprints/{self.preprint._id}/institutions/' in relationship_link
31 changes: 0 additions & 31 deletions api_tests/preprints/views/test_preprint_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,29 +61,6 @@ def test_update_preprint_permission_denied(self, app, preprint, url):
res = app.patch_json_api(url, update_doi_payload, auth=read_contrib.auth, expect_errors=True)
assert res.status_code == 403

def test_update_original_publication_date_to_none(self, app, preprint, url):
write_contrib = AuthUserFactory()
preprint.add_contributor(write_contrib, WRITE, save=True)
preprint.original_publication_date = '2013-12-11 10:09:08.070605+00:00'
preprint.save()
update_payload = build_preprint_update_payload(preprint._id, attributes={'original_publication_date': None})

res = app.patch_json_api(url, update_payload, auth=write_contrib.auth)
assert res.status_code == 200
preprint.reload()
assert preprint.original_publication_date is None

def test_update_custom_publication_citation_to_none(self, app, preprint, url):
write_contrib = AuthUserFactory()
preprint.add_contributor(write_contrib, WRITE, save=True)
preprint.custom_publication_citation = 'fake citation'
preprint.save()
update_payload = build_preprint_update_payload(preprint._id, attributes={'custom_publication_citation': None})
res = app.patch_json_api(url, update_payload, auth=write_contrib.auth)
assert res.status_code == 200
preprint.reload()
assert preprint.custom_publication_citation is None

@responses.activate
@mock.patch('osf.models.preprint.update_or_enqueue_on_preprint_updated', mock.Mock())
def test_update_preprint_permission_write_contrib(self, app, preprint, url):
Expand Down Expand Up @@ -264,14 +241,6 @@ def test_update_original_publication_date(self, app, user, preprint, url):
preprint.reload()
assert preprint.original_publication_date == date

def test_update_custom_publication_citation(self, app, user, preprint, url):
citation = 'fake citation'
update_payload = build_preprint_update_payload(preprint._id, attributes={'custom_publication_citation': citation})
res = app.patch_json_api(url, update_payload, auth=user.auth)
assert res.status_code == 200
preprint.reload()
assert preprint.custom_publication_citation == citation

@responses.activate
@mock.patch('osf.models.preprint.update_or_enqueue_on_preprint_updated', mock.Mock())
def test_update_article_doi(self, app, user, preprint, url):
Expand Down

0 comments on commit 14e2103

Please sign in to comment.