forked from CenterForOpenScience/osf.io
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
validate curator's non-biblio status and display details on contrbut…
…or.mako
- Loading branch information
John Tordoff
committed
Jan 7, 2025
1 parent
d34ceb8
commit 70f2629
Showing
10 changed files
with
181 additions
and
10 deletions.
There are no files selected for viewing
60 changes: 60 additions & 0 deletions
60
api_tests/nodes/views/test_node_contributor_insti_admin.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import pytest | ||
from osf.models import Contributor | ||
from osf_tests.factories import ( | ||
AuthUserFactory, | ||
ProjectFactory, | ||
InstitutionFactory, | ||
) | ||
from api.base.settings.defaults import API_BASE | ||
|
||
|
||
@pytest.mark.django_db | ||
class TestChangeInstitutionalAdminContributor: | ||
|
||
@pytest.fixture() | ||
def user(self): | ||
return AuthUserFactory() | ||
|
||
@pytest.fixture() | ||
def institution(self): | ||
return InstitutionFactory() | ||
|
||
@pytest.fixture() | ||
def institutional_admin(self, institution): | ||
admin_user = AuthUserFactory() | ||
institution.get_group('institutional_admins').user_set.add(admin_user) | ||
return admin_user | ||
|
||
@pytest.fixture() | ||
def project(self, user, institutional_admin): | ||
project = ProjectFactory(creator=user) | ||
project.add_contributor(institutional_admin, visible=False) | ||
return project | ||
|
||
@pytest.fixture() | ||
def url_contrib(self, project, user): | ||
return f'/{API_BASE}nodes/{project._id}/contributors/{user._id}/' | ||
|
||
def test_cannot_set_institutional_admin_contributor_bibliographic(self, app, user, project, institutional_admin, url_contrib): | ||
res = app.put_json_api( | ||
url_contrib, | ||
{ | ||
'data': { | ||
'id': f'{project._id}-{institutional_admin._id}', | ||
'type': 'contributors', | ||
'attributes': { | ||
'bibliographic': True, | ||
} | ||
} | ||
}, | ||
auth=user.auth, | ||
expect_errors=True | ||
) | ||
assert res.status_code == 409 | ||
project.reload() | ||
contributor = Contributor.objects.get( | ||
node=project, | ||
user=institutional_admin | ||
) | ||
# TODO: check message | ||
assert not contributor.visible |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import pytest | ||
from osf.models import Contributor | ||
from osf_tests.factories import ( | ||
AuthUserFactory, | ||
ProjectFactory, | ||
InstitutionFactory | ||
) | ||
from django.db.utils import IntegrityError | ||
|
||
@pytest.mark.django_db | ||
class TestContributorModel: | ||
|
||
@pytest.fixture() | ||
def user(self): | ||
return AuthUserFactory() | ||
|
||
@pytest.fixture() | ||
def project(self): | ||
return ProjectFactory() | ||
|
||
@pytest.fixture() | ||
def institution(self): | ||
return InstitutionFactory() | ||
|
||
@pytest.fixture() | ||
def institutional_admin(self, institution): | ||
admin_user = AuthUserFactory() | ||
institution.get_group('institutional_admins').user_set.add(admin_user) | ||
return admin_user | ||
|
||
def test_contributor_with_visible_and_institutional_admin_raises_error(self, institutional_admin, project, institution): | ||
contributor = Contributor( | ||
user=institutional_admin, | ||
node=project, | ||
visible=False, | ||
) | ||
contributor.save() | ||
|
||
contributor.visible = True | ||
|
||
with pytest.raises(IntegrityError, match='Curators can not be made bibliographic contributors'): | ||
contributor.save() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters