From 2e1061962fe9dbad45e1c5e9bf0ff1dabf9673f9 Mon Sep 17 00:00:00 2001 From: Vlad0n20 Date: Fri, 17 Jan 2025 16:42:15 +0200 Subject: [PATCH 1/7] Add tests for PreprintVersionList view --- .../preprints/views/test_preprint_versions.py | 87 ++++++++++++++++++- 1 file changed, 84 insertions(+), 3 deletions(-) diff --git a/api_tests/preprints/views/test_preprint_versions.py b/api_tests/preprints/views/test_preprint_versions.py index d7fbe2a9170..993f243e231 100644 --- a/api_tests/preprints/views/test_preprint_versions.py +++ b/api_tests/preprints/views/test_preprint_versions.py @@ -7,15 +7,14 @@ from framework.auth.core import Auth from osf.models import Preprint from osf.utils import permissions -from osf_tests.factories import ProjectFactory, PreprintFactory, AuthUserFactory +from osf_tests.factories import ProjectFactory, PreprintFactory, AuthUserFactory, PreprintProviderFactory from tests.base import ApiTestCase # TODO: we have good coverage for `POST`; please add new tests for `GET` -class TestPreprintVersion(ApiTestCase): +class TestPreprintVersionPost(ApiTestCase): def setUp(self): - super().setUp() self.user = AuthUserFactory() self.project = ProjectFactory(creator=self.user) @@ -154,3 +153,85 @@ def test_permission_error(self): self.post_mod_preprint.add_contributor(user_write, permissions.WRITE) res = self.app.post_json_api(self.post_mod_version_create_url, auth=user_write.auth, expect_errors=True) assert res.status_code == 403 + + +class TestPreprintVersionList(ApiTestCase): + + def setUp(self): + super().setUp() + self.user = AuthUserFactory() + self.moderator = AuthUserFactory() + self.provider = PreprintProviderFactory(_id='osf', name='osfprovider') + self.post_mod_preprint = PreprintFactory( + reviews_workflow='post-moderation', + is_published=True, + creator=self.user, + provider=self.provider + ) + self.pre_mod_preprint = PreprintFactory( + reviews_workflow='pre-moderation', + is_published=False, + creator=self.user, + provider=self.provider + ) + self.pre_mod_preprint.provider.get_group('moderator').user_set.add(self.moderator) + self.post_mod_preprint.provider.get_group('moderator').user_set.add(self.moderator) + self.latest_preprint = self.post_mod_preprint + self.origin_guid = str(self.post_mod_preprint.guids.first()._id) + for _ in range(5): + new_version = PreprintFactory.create_version( + create_from=self.latest_preprint, + creator=self.user, + set_doi=False + ) + self.latest_preprint = new_version + + self.version_list_url = f"/{API_BASE}preprints/{self.origin_guid}_v1/versions/" + + def test_list_versions(self): + res = self.app.get(self.version_list_url, auth=self.user.auth) + assert res.status_code == 200 + data = res.json['data'] + assert len(data) == 6 + assert len(set([item['id'] for item in data])) == 6 + + def test_filter_by_id(self): + version = self.latest_preprint.versioned_guids.first() + res = self.app.get(f"{self.version_list_url}?filter[id]={version.referent._id}", auth=self.user.auth) + assert res.status_code == 200 + data = res.json['data'] + assert len(data) == 6 + assert data[0]['id'] == version.referent._id + + def test_public_visibility(self): + self.pre_mod_preprint.is_public = True + self.pre_mod_preprint.save() + res = self.app.get(self.version_list_url) + assert res.status_code == 200 + assert len(res.json['data']) == 6 + + def test_invalid_preprint_id(self): + res = self.app.get(f"/{API_BASE}preprints/lkziv_v1010101/versions/", auth=self.user.auth, expect_errors=True) + assert res.status_code == 404 + + def test_pagination(self): + res = self.app.get(f"{self.version_list_url}?page[size]=2", auth=self.user.auth) + assert res.status_code == 200 + data = res.json['data'] + assert len(data) == 2 + assert 'links' in res.json + assert 'next' in res.json['links'] + + def test_new_unpublished_version(self): + PreprintFactory.create_version( + self.latest_preprint, + creator=self.user, + set_doi=False, + final_machine_state='pending', + is_published=False + ) + res = self.app.get(self.version_list_url, auth=self.user.auth) + assert res.status_code == 200 + data = res.json['data'] + assert len(data) == 7 + assert len(set([item['id'] for item in data])) == 7 From 379a0bc399a6e299bb8e4d5c669c3f6c59c41109 Mon Sep 17 00:00:00 2001 From: Vlad0n20 Date: Tue, 21 Jan 2025 15:18:59 +0200 Subject: [PATCH 2/7] Add tests for various user permissions for PreprintVersionsListView --- .../preprints/views/test_preprint_versions.py | 298 +++++++++++++++++- 1 file changed, 296 insertions(+), 2 deletions(-) diff --git a/api_tests/preprints/views/test_preprint_versions.py b/api_tests/preprints/views/test_preprint_versions.py index 993f243e231..b13c531343e 100644 --- a/api_tests/preprints/views/test_preprint_versions.py +++ b/api_tests/preprints/views/test_preprint_versions.py @@ -4,15 +4,17 @@ from addons.osfstorage import settings as osfstorage_settings from addons.osfstorage.models import OsfStorageFile from api.base.settings.defaults import API_BASE + from framework.auth.core import Auth from osf.models import Preprint from osf.utils import permissions + from osf_tests.factories import ProjectFactory, PreprintFactory, AuthUserFactory, PreprintProviderFactory from tests.base import ApiTestCase # TODO: we have good coverage for `POST`; please add new tests for `GET` -class TestPreprintVersionPost(ApiTestCase): +class TestPreprintVersionsListCreate(ApiTestCase): def setUp(self): super().setUp() @@ -155,11 +157,12 @@ def test_permission_error(self): assert res.status_code == 403 -class TestPreprintVersionList(ApiTestCase): +class TestPreprintVersionsListRetrieve(ApiTestCase): def setUp(self): super().setUp() self.user = AuthUserFactory() + self.admin = AuthUserFactory() self.moderator = AuthUserFactory() self.provider = PreprintProviderFactory(_id='osf', name='osfprovider') self.post_mod_preprint = PreprintFactory( @@ -168,12 +171,20 @@ def setUp(self): creator=self.user, provider=self.provider ) + self.post_mod_preprint.add_contributor(self.admin, permissions=permissions.ADMIN) + self.post_mod_preprint.add_contributor(self.user, permissions=permissions.WRITE) + self.post_mod_preprint.add_contributor(self.user, permissions=permissions.READ) + self.pre_mod_preprint = PreprintFactory( reviews_workflow='pre-moderation', is_published=False, creator=self.user, provider=self.provider ) + self.pre_mod_preprint.add_contributor(self.admin, permissions=permissions.ADMIN) + self.pre_mod_preprint.add_contributor(self.user, permissions=permissions.WRITE) + self.pre_mod_preprint.add_contributor(self.user, permissions=permissions.READ) + self.pre_mod_preprint.provider.get_group('moderator').user_set.add(self.moderator) self.post_mod_preprint.provider.get_group('moderator').user_set.add(self.moderator) self.latest_preprint = self.post_mod_preprint @@ -185,6 +196,9 @@ def setUp(self): set_doi=False ) self.latest_preprint = new_version + new_version.add_contributor(self.admin, permissions=permissions.ADMIN) + new_version.add_contributor(self.user, permissions=permissions.WRITE) + new_version.add_contributor(self.user, permissions=permissions.READ) self.version_list_url = f"/{API_BASE}preprints/{self.origin_guid}_v1/versions/" @@ -235,3 +249,283 @@ def test_new_unpublished_version(self): data = res.json['data'] assert len(data) == 7 assert len(set([item['id'] for item in data])) == 7 + + def test_preprints_version_permissions_for_admin(self): + res = self.app.get(self.version_list_url, auth=self.admin.auth) + assert res.status_code == 200 + assert len(res.json['data']) == 6 + + unpublished_preprint_version = PreprintFactory.create_version( + create_from=self.latest_preprint, + creator=self.user, + final_machine_state='initial', + is_published=False, + set_doi=False + ) + self.latest_preprint = unpublished_preprint_version + unpublished_preprint_version.add_contributor(self.admin, permissions=permissions.ADMIN) + res = self.app.get(self.version_list_url, auth=self.admin.auth) + assert res.status_code == 200 + assert len(res.json['data']) == 6 + + unpublished_preprint_version.run_submit(user=self.admin) + res = self.app.get(self.version_list_url, auth=self.admin.auth) + assert res.status_code == 200 + assert len(res.json['data']) == 7 + + unpublished_preprint_version.run_accept(user=self.admin, comment='Text') + + res = self.app.get(self.version_list_url, auth=self.admin.auth) + assert res.status_code == 200 + assert len(res.json['data']) == 7 + + unpublished_version = PreprintFactory.create_version( + create_from=self.latest_preprint, + creator=self.user, + final_machine_state='initial', + is_published=False, + set_doi=False + ) + unpublished_version.add_contributor(self.admin, permissions=permissions.ADMIN) + + unpublished_version.run_submit(user=self.admin) + + res = self.app.get(self.version_list_url, auth=self.admin.auth) + assert res.status_code == 200 + assert len(res.json['data']) == 8 + + unpublished_version.run_reject(user=self.admin, comment='Test') + res = self.app.get(self.version_list_url, auth=self.admin.auth) + assert res.status_code == 200 + assert len(res.json['data']) == 8 + + def test_preprints_version_permissions_for_write_user(self): + new_user = AuthUserFactory() + res = self.app.get(self.version_list_url, auth=new_user.auth) + assert res.status_code == 200 + assert len(res.json['data']) == 6 + + unpublished_preprint_version = PreprintFactory.create_version( + create_from=self.latest_preprint, + creator=self.user, + final_machine_state='initial', + is_published=False, + set_doi=False + ) + self.latest_preprint = unpublished_preprint_version + unpublished_preprint_version.add_contributor(self.admin, permissions=permissions.ADMIN) + unpublished_preprint_version.add_contributor(new_user, permissions=permissions.WRITE) + res = self.app.get(self.version_list_url, auth=new_user.auth) + assert res.status_code == 200 + assert len(res.json['data']) == 6 + + unpublished_preprint_version.run_submit(user=self.admin) + res = self.app.get(self.version_list_url, auth=new_user.auth) + assert res.status_code == 200 + assert len(res.json['data']) == 6 + + unpublished_preprint_version.run_accept(user=self.admin, comment='Text') + + res = self.app.get(self.version_list_url, auth=new_user.auth) + assert res.status_code == 200 + assert len(res.json['data']) == 7 + + unpublished_version = PreprintFactory.create_version( + create_from=self.latest_preprint, + creator=self.user, + final_machine_state='initial', + is_published=False, + set_doi=False + ) + unpublished_version.add_contributor(self.admin, permissions=permissions.ADMIN) + unpublished_version.add_contributor(new_user, permissions=permissions.WRITE) + + unpublished_version.run_submit(user=self.admin) + + res = self.app.get(self.version_list_url, auth=new_user.auth) + assert res.status_code == 200 + assert len(res.json['data']) == 7 + + unpublished_version.run_reject(user=self.admin, comment='Test') + res = self.app.get(self.version_list_url, auth=new_user.auth) + assert res.status_code == 200 + assert len(res.json['data']) == 7 + + def test_pre_mod_preprints_version_permissions_for_read_user(self): + new_user = AuthUserFactory() + res = self.app.get(self.version_list_url, auth=new_user.auth) + assert res.status_code == 200 + assert len(res.json['data']) == 6 + + unpublished_preprint_version = PreprintFactory.create_version( + create_from=self.latest_preprint, + creator=self.user, + final_machine_state='initial', + is_published=False, + set_doi=False + ) + self.latest_preprint = unpublished_preprint_version + unpublished_preprint_version.add_contributor(self.admin, permissions=permissions.ADMIN) + unpublished_preprint_version.add_contributor(new_user, permissions=permissions.READ) + res = self.app.get(self.version_list_url, auth=new_user.auth) + assert res.status_code == 200 + assert len(res.json['data']) == 6 + + unpublished_preprint_version.run_submit(user=self.admin) + res = self.app.get(self.version_list_url, auth=new_user.auth) + assert res.status_code == 200 + assert len(res.json['data']) == 6 + + unpublished_preprint_version.run_accept(user=self.admin, comment='Text') + + res = self.app.get(self.version_list_url, auth=new_user.auth) + assert res.status_code == 200 + assert len(res.json['data']) == 7 + + unpublished_version = PreprintFactory.create_version( + create_from=self.latest_preprint, + creator=self.user, + final_machine_state='initial', + is_published=False, + set_doi=False + ) + unpublished_version.add_contributor(self.admin, permissions=permissions.ADMIN) + unpublished_version.add_contributor(new_user, permissions=permissions.READ) + + unpublished_version.run_submit(user=self.admin) + + res = self.app.get(self.version_list_url, auth=new_user.auth) + assert res.status_code == 200 + assert len(res.json['data']) == 7 + + unpublished_version.run_reject(user=self.admin, comment='Test') + res = self.app.get(self.version_list_url, auth=new_user.auth) + assert res.status_code == 200 + assert len(res.json['data']) == 7 + + def test_pre_mod_preprints_version_permissions_for_other_user(self): + new_user = AuthUserFactory() + res = self.app.get(self.version_list_url, auth=new_user.auth) + assert res.status_code == 200 + assert len(res.json['data']) == 6 + + unpublished_preprint_version = PreprintFactory.create_version( + create_from=self.latest_preprint, + creator=self.user, + final_machine_state='initial', + is_published=False, + set_doi=False + ) + self.latest_preprint = unpublished_preprint_version + unpublished_preprint_version.add_contributor(self.admin, permissions=permissions.ADMIN) + res = self.app.get(self.version_list_url, auth=new_user.auth) + assert res.status_code == 200 + assert len(res.json['data']) == 6 + + unpublished_preprint_version.run_submit(user=self.admin) + res = self.app.get(self.version_list_url, auth=new_user.auth) + assert res.status_code == 200 + assert len(res.json['data']) == 6 + + unpublished_preprint_version.run_accept(user=self.admin, comment='Text') + + res = self.app.get(self.version_list_url, auth=new_user.auth) + assert res.status_code == 200 + assert len(res.json['data']) == 7 + + unpublished_version = PreprintFactory.create_version( + create_from=self.latest_preprint, + creator=self.user, + final_machine_state='initial', + is_published=False, + set_doi=False + ) + unpublished_version.add_contributor(self.admin, permissions=permissions.ADMIN) + + unpublished_version.run_submit(user=self.admin) + + res = self.app.get(self.version_list_url, auth=new_user.auth) + assert res.status_code == 200 + assert len(res.json['data']) == 7 + + unpublished_version.run_reject(user=self.admin, comment='Test') + res = self.app.get(self.version_list_url, auth=new_user.auth) + assert res.status_code == 200 + assert len(res.json['data']) == 7 + + def test_post_mod_preprints_version_permissions_for_admin_user(self): + res = self.app.get(self.version_list_url, auth=self.admin.auth) + assert res.status_code == 200 + assert len(res.json['data']) == 6 + + new_preprint_version = PreprintFactory.create_version( + create_from=self.latest_preprint, + creator=self.user, + final_machine_state='accepted', + is_published=True, + set_doi=False + ) + new_preprint_version.add_contributor(self.admin, permissions=permissions.ADMIN) + + res = self.app.get(self.version_list_url, auth=self.admin.auth) + assert res.status_code == 200 + assert len(res.json['data']) == 7 + + def test_post_mod_preprints_version_permissions_for_write_user(self): + new_user = AuthUserFactory() + res = self.app.get(self.version_list_url, auth=new_user.auth) + assert res.status_code == 200 + assert len(res.json['data']) == 6 + + new_preprint_version = PreprintFactory.create_version( + create_from=self.latest_preprint, + creator=self.user, + final_machine_state='accepted', + is_published=True, + set_doi=False + ) + new_preprint_version.add_contributor(self.admin, permissions=permissions.ADMIN) + new_preprint_version.add_contributor(new_user, permissions=permissions.WRITE) + + res = self.app.get(self.version_list_url, auth=new_user.auth) + assert res.status_code == 200 + assert len(res.json['data']) == 7 + + def test_post_mod_preprints_version_permissions_for_read_user(self): + new_user = AuthUserFactory() + res = self.app.get(self.version_list_url, auth=new_user.auth) + assert res.status_code == 200 + assert len(res.json['data']) == 6 + + new_preprint_version = PreprintFactory.create_version( + create_from=self.latest_preprint, + creator=self.user, + final_machine_state='accepted', + is_published=True, + set_doi=False + ) + new_preprint_version.add_contributor(self.admin, permissions=permissions.ADMIN) + new_preprint_version.add_contributor(new_user, permissions=permissions.READ) + + res = self.app.get(self.version_list_url, auth=new_user.auth) + assert res.status_code == 200 + assert len(res.json['data']) == 7 + + def test_post_mod_preprints_version_permissions_for_other_user(self): + new_user = AuthUserFactory() + res = self.app.get(self.version_list_url, auth=new_user.auth) + assert res.status_code == 200 + assert len(res.json['data']) == 6 + + new_preprint_version = PreprintFactory.create_version( + create_from=self.latest_preprint, + creator=self.user, + final_machine_state='accepted', + is_published=True, + set_doi=False + ) + new_preprint_version.add_contributor(new_user, permissions=permissions.ADMIN) + + res = self.app.get(self.version_list_url, auth=new_user.auth) + assert res.status_code == 200 + assert len(res.json['data']) == 7 From 8134daf19974381c10ae204513240f12d239f7fb Mon Sep 17 00:00:00 2001 From: Vlad0n20 Date: Tue, 21 Jan 2025 15:52:43 +0200 Subject: [PATCH 3/7] Fix test_preprints_version_permissions_for_admin --- api_tests/preprints/views/test_preprint_versions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api_tests/preprints/views/test_preprint_versions.py b/api_tests/preprints/views/test_preprint_versions.py index b13c531343e..2940197de22 100644 --- a/api_tests/preprints/views/test_preprint_versions.py +++ b/api_tests/preprints/views/test_preprint_versions.py @@ -266,7 +266,7 @@ def test_preprints_version_permissions_for_admin(self): unpublished_preprint_version.add_contributor(self.admin, permissions=permissions.ADMIN) res = self.app.get(self.version_list_url, auth=self.admin.auth) assert res.status_code == 200 - assert len(res.json['data']) == 6 + assert len(res.json['data']) == 7 unpublished_preprint_version.run_submit(user=self.admin) res = self.app.get(self.version_list_url, auth=self.admin.auth) From 8f64fd53b3822bbefe95055a51c55e79ca0d828a Mon Sep 17 00:00:00 2001 From: Vlad0n20 Date: Fri, 24 Jan 2025 17:09:15 +0200 Subject: [PATCH 4/7] Fix comments for pull request --- .../preprints/views/test_preprint_versions.py | 64 ++++++++----------- 1 file changed, 25 insertions(+), 39 deletions(-) diff --git a/api_tests/preprints/views/test_preprint_versions.py b/api_tests/preprints/views/test_preprint_versions.py index 2940197de22..7c3f3aacf19 100644 --- a/api_tests/preprints/views/test_preprint_versions.py +++ b/api_tests/preprints/views/test_preprint_versions.py @@ -1,5 +1,6 @@ from django.contrib.contenttypes.models import ContentType from django.db.models.fields import Field +from django.contrib.auth.models import Group from addons.osfstorage import settings as osfstorage_settings from addons.osfstorage.models import OsfStorageFile @@ -13,7 +14,6 @@ from tests.base import ApiTestCase -# TODO: we have good coverage for `POST`; please add new tests for `GET` class TestPreprintVersionsListCreate(ApiTestCase): def setUp(self): @@ -159,10 +159,20 @@ def test_permission_error(self): class TestPreprintVersionsListRetrieve(ApiTestCase): + def add_contributors_for_preprint(self, preprint): + preprint.add_contributor(self.admin, permissions=permissions.ADMIN) + preprint.add_contributor(self.write_user, permissions=permissions.WRITE) + preprint.add_contributor(self.read_user, permissions=permissions.READ) + def setUp(self): super().setUp() self.user = AuthUserFactory() + self.read_user = AuthUserFactory() + self.write_user = AuthUserFactory() self.admin = AuthUserFactory() + osf_admin = Group.objects.get(name='osf_admin') + self.admin.groups.add(osf_admin) + self.moderator = AuthUserFactory() self.provider = PreprintProviderFactory(_id='osf', name='osfprovider') self.post_mod_preprint = PreprintFactory( @@ -171,9 +181,6 @@ def setUp(self): creator=self.user, provider=self.provider ) - self.post_mod_preprint.add_contributor(self.admin, permissions=permissions.ADMIN) - self.post_mod_preprint.add_contributor(self.user, permissions=permissions.WRITE) - self.post_mod_preprint.add_contributor(self.user, permissions=permissions.READ) self.pre_mod_preprint = PreprintFactory( reviews_workflow='pre-moderation', @@ -181,10 +188,16 @@ def setUp(self): creator=self.user, provider=self.provider ) - self.pre_mod_preprint.add_contributor(self.admin, permissions=permissions.ADMIN) - self.pre_mod_preprint.add_contributor(self.user, permissions=permissions.WRITE) - self.pre_mod_preprint.add_contributor(self.user, permissions=permissions.READ) + self.add_contributors_for_preprint(self.pre_mod_preprint) + self.pre_mod_preprint_pending = PreprintFactory( + reviews_workflow='pre-moderation', + is_published=False, + creator=self.user, + provider=self.provider + ) + self.add_contributors_for_preprint(self.pre_mod_preprint_pending) + self.pre_mod_preprint_pending.run_submit(user=self.admin) self.pre_mod_preprint.provider.get_group('moderator').user_set.add(self.moderator) self.post_mod_preprint.provider.get_group('moderator').user_set.add(self.moderator) self.latest_preprint = self.post_mod_preprint @@ -196,9 +209,6 @@ def setUp(self): set_doi=False ) self.latest_preprint = new_version - new_version.add_contributor(self.admin, permissions=permissions.ADMIN) - new_version.add_contributor(self.user, permissions=permissions.WRITE) - new_version.add_contributor(self.user, permissions=permissions.READ) self.version_list_url = f"/{API_BASE}preprints/{self.origin_guid}_v1/versions/" @@ -209,14 +219,6 @@ def test_list_versions(self): assert len(data) == 6 assert len(set([item['id'] for item in data])) == 6 - def test_filter_by_id(self): - version = self.latest_preprint.versioned_guids.first() - res = self.app.get(f"{self.version_list_url}?filter[id]={version.referent._id}", auth=self.user.auth) - assert res.status_code == 200 - data = res.json['data'] - assert len(data) == 6 - assert data[0]['id'] == version.referent._id - def test_public_visibility(self): self.pre_mod_preprint.is_public = True self.pre_mod_preprint.save() @@ -264,6 +266,7 @@ def test_preprints_version_permissions_for_admin(self): ) self.latest_preprint = unpublished_preprint_version unpublished_preprint_version.add_contributor(self.admin, permissions=permissions.ADMIN) + res = self.app.get(self.version_list_url, auth=self.admin.auth) assert res.status_code == 200 assert len(res.json['data']) == 7 @@ -313,8 +316,6 @@ def test_preprints_version_permissions_for_write_user(self): set_doi=False ) self.latest_preprint = unpublished_preprint_version - unpublished_preprint_version.add_contributor(self.admin, permissions=permissions.ADMIN) - unpublished_preprint_version.add_contributor(new_user, permissions=permissions.WRITE) res = self.app.get(self.version_list_url, auth=new_user.auth) assert res.status_code == 200 assert len(res.json['data']) == 6 @@ -337,8 +338,6 @@ def test_preprints_version_permissions_for_write_user(self): is_published=False, set_doi=False ) - unpublished_version.add_contributor(self.admin, permissions=permissions.ADMIN) - unpublished_version.add_contributor(new_user, permissions=permissions.WRITE) unpublished_version.run_submit(user=self.admin) @@ -365,8 +364,6 @@ def test_pre_mod_preprints_version_permissions_for_read_user(self): set_doi=False ) self.latest_preprint = unpublished_preprint_version - unpublished_preprint_version.add_contributor(self.admin, permissions=permissions.ADMIN) - unpublished_preprint_version.add_contributor(new_user, permissions=permissions.READ) res = self.app.get(self.version_list_url, auth=new_user.auth) assert res.status_code == 200 assert len(res.json['data']) == 6 @@ -389,8 +386,6 @@ def test_pre_mod_preprints_version_permissions_for_read_user(self): is_published=False, set_doi=False ) - unpublished_version.add_contributor(self.admin, permissions=permissions.ADMIN) - unpublished_version.add_contributor(new_user, permissions=permissions.READ) unpublished_version.run_submit(user=self.admin) @@ -417,7 +412,6 @@ def test_pre_mod_preprints_version_permissions_for_other_user(self): set_doi=False ) self.latest_preprint = unpublished_preprint_version - unpublished_preprint_version.add_contributor(self.admin, permissions=permissions.ADMIN) res = self.app.get(self.version_list_url, auth=new_user.auth) assert res.status_code == 200 assert len(res.json['data']) == 6 @@ -440,7 +434,6 @@ def test_pre_mod_preprints_version_permissions_for_other_user(self): is_published=False, set_doi=False ) - unpublished_version.add_contributor(self.admin, permissions=permissions.ADMIN) unpublished_version.run_submit(user=self.admin) @@ -458,15 +451,13 @@ def test_post_mod_preprints_version_permissions_for_admin_user(self): assert res.status_code == 200 assert len(res.json['data']) == 6 - new_preprint_version = PreprintFactory.create_version( + PreprintFactory.create_version( create_from=self.latest_preprint, creator=self.user, final_machine_state='accepted', is_published=True, set_doi=False ) - new_preprint_version.add_contributor(self.admin, permissions=permissions.ADMIN) - res = self.app.get(self.version_list_url, auth=self.admin.auth) assert res.status_code == 200 assert len(res.json['data']) == 7 @@ -477,15 +468,13 @@ def test_post_mod_preprints_version_permissions_for_write_user(self): assert res.status_code == 200 assert len(res.json['data']) == 6 - new_preprint_version = PreprintFactory.create_version( + PreprintFactory.create_version( create_from=self.latest_preprint, creator=self.user, final_machine_state='accepted', is_published=True, set_doi=False ) - new_preprint_version.add_contributor(self.admin, permissions=permissions.ADMIN) - new_preprint_version.add_contributor(new_user, permissions=permissions.WRITE) res = self.app.get(self.version_list_url, auth=new_user.auth) assert res.status_code == 200 @@ -497,15 +486,13 @@ def test_post_mod_preprints_version_permissions_for_read_user(self): assert res.status_code == 200 assert len(res.json['data']) == 6 - new_preprint_version = PreprintFactory.create_version( + PreprintFactory.create_version( create_from=self.latest_preprint, creator=self.user, final_machine_state='accepted', is_published=True, set_doi=False ) - new_preprint_version.add_contributor(self.admin, permissions=permissions.ADMIN) - new_preprint_version.add_contributor(new_user, permissions=permissions.READ) res = self.app.get(self.version_list_url, auth=new_user.auth) assert res.status_code == 200 @@ -517,14 +504,13 @@ def test_post_mod_preprints_version_permissions_for_other_user(self): assert res.status_code == 200 assert len(res.json['data']) == 6 - new_preprint_version = PreprintFactory.create_version( + PreprintFactory.create_version( create_from=self.latest_preprint, creator=self.user, final_machine_state='accepted', is_published=True, set_doi=False ) - new_preprint_version.add_contributor(new_user, permissions=permissions.ADMIN) res = self.app.get(self.version_list_url, auth=new_user.auth) assert res.status_code == 200 From 6a501e61336689c0794bebc1f91ea74796bf3a0b Mon Sep 17 00:00:00 2001 From: Vlad0n20 Date: Fri, 24 Jan 2025 17:51:02 +0200 Subject: [PATCH 5/7] Fix failed test --- api_tests/preprints/views/test_preprint_versions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api_tests/preprints/views/test_preprint_versions.py b/api_tests/preprints/views/test_preprint_versions.py index 7c3f3aacf19..56b7ef029cc 100644 --- a/api_tests/preprints/views/test_preprint_versions.py +++ b/api_tests/preprints/views/test_preprint_versions.py @@ -269,7 +269,7 @@ def test_preprints_version_permissions_for_admin(self): res = self.app.get(self.version_list_url, auth=self.admin.auth) assert res.status_code == 200 - assert len(res.json['data']) == 7 + assert len(res.json['data']) == 6 unpublished_preprint_version.run_submit(user=self.admin) res = self.app.get(self.version_list_url, auth=self.admin.auth) From c16ae63d6c4232cd36713766567e63f237d01cb0 Mon Sep 17 00:00:00 2001 From: Longze Chen Date: Fri, 24 Jan 2025 18:26:03 -0500 Subject: [PATCH 6/7] Fix contributor copy during version creation in preprint factory --- osf_tests/factories.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/osf_tests/factories.py b/osf_tests/factories.py index d08f559a478..2011c6d2b56 100644 --- a/osf_tests/factories.py +++ b/osf_tests/factories.py @@ -37,6 +37,8 @@ SchemaResponseTriggers ) from addons.osfstorage.models import OsfStorageFile, Region +from osf.exceptions import UserStateError, ValidationValueError + fake = Factory.create() faker = Faker() # If tests are run on really old processors without high precision this might fail. Unlikely to occur. @@ -875,11 +877,16 @@ def create_version(cls, create_from, creator=None, final_machine_state='accepted preprint_file.create_version(creator, location, metadata=metadata).save() # Set relationships - contributor_list = latest_version.contributor_set.exclude( - user=latest_version.creator - ).values('visible', 'user_id', '_order') - for contributor in contributor_list: - instance.contributor_set.create(**{**contributor, 'preprint_id': instance.id}) + for contributor in latest_version.contributor_set.exclude(user=instance.creator): + try: + instance.add_contributor( + contributor.user, + permissions=contributor.permission, + visible=contributor.visible, + save=True + ) + except (ValidationValueError, UserStateError): + pass for institution in latest_version.affiliated_institutions.all(): instance.add_affiliated_institution(institution, auth.user, ignore_user_affiliation=True) From 07e4e2c08d76c14e886a816bcc15ce91e925c34d Mon Sep 17 00:00:00 2001 From: Longze Chen Date: Fri, 24 Jan 2025 18:39:29 -0500 Subject: [PATCH 7/7] Rework preprint versions list retrieve tests --- .../preprints/views/test_preprint_versions.py | 473 ++++++------------ 1 file changed, 153 insertions(+), 320 deletions(-) diff --git a/api_tests/preprints/views/test_preprint_versions.py b/api_tests/preprints/views/test_preprint_versions.py index 56b7ef029cc..add369f82d5 100644 --- a/api_tests/preprints/views/test_preprint_versions.py +++ b/api_tests/preprints/views/test_preprint_versions.py @@ -1,16 +1,14 @@ from django.contrib.contenttypes.models import ContentType from django.db.models.fields import Field -from django.contrib.auth.models import Group from addons.osfstorage import settings as osfstorage_settings from addons.osfstorage.models import OsfStorageFile from api.base.settings.defaults import API_BASE - from framework.auth.core import Auth from osf.models import Preprint from osf.utils import permissions - -from osf_tests.factories import ProjectFactory, PreprintFactory, AuthUserFactory, PreprintProviderFactory +from osf.utils.workflows import DefaultStates, RequestTypes +from osf_tests.factories import ProjectFactory, PreprintFactory, AuthUserFactory, PreprintRequestFactory from tests.base import ApiTestCase @@ -159,359 +157,194 @@ def test_permission_error(self): class TestPreprintVersionsListRetrieve(ApiTestCase): - def add_contributors_for_preprint(self, preprint): - preprint.add_contributor(self.admin, permissions=permissions.ADMIN) - preprint.add_contributor(self.write_user, permissions=permissions.WRITE) - preprint.add_contributor(self.read_user, permissions=permissions.READ) - def setUp(self): + super().setUp() - self.user = AuthUserFactory() - self.read_user = AuthUserFactory() - self.write_user = AuthUserFactory() - self.admin = AuthUserFactory() - osf_admin = Group.objects.get(name='osf_admin') - self.admin.groups.add(osf_admin) + self.creator = AuthUserFactory() + self.read_contrib = AuthUserFactory() + self.write_contrib = AuthUserFactory() + self.admin_contrib = AuthUserFactory() self.moderator = AuthUserFactory() - self.provider = PreprintProviderFactory(_id='osf', name='osfprovider') - self.post_mod_preprint = PreprintFactory( - reviews_workflow='post-moderation', - is_published=True, - creator=self.user, - provider=self.provider - ) - - self.pre_mod_preprint = PreprintFactory( - reviews_workflow='pre-moderation', - is_published=False, - creator=self.user, - provider=self.provider - ) - self.add_contributors_for_preprint(self.pre_mod_preprint) - - self.pre_mod_preprint_pending = PreprintFactory( - reviews_workflow='pre-moderation', - is_published=False, - creator=self.user, - provider=self.provider - ) - self.add_contributors_for_preprint(self.pre_mod_preprint_pending) - self.pre_mod_preprint_pending.run_submit(user=self.admin) - self.pre_mod_preprint.provider.get_group('moderator').user_set.add(self.moderator) - self.post_mod_preprint.provider.get_group('moderator').user_set.add(self.moderator) - self.latest_preprint = self.post_mod_preprint - self.origin_guid = str(self.post_mod_preprint.guids.first()._id) - for _ in range(5): - new_version = PreprintFactory.create_version( - create_from=self.latest_preprint, - creator=self.user, - set_doi=False - ) - self.latest_preprint = new_version - - self.version_list_url = f"/{API_BASE}preprints/{self.origin_guid}_v1/versions/" - - def test_list_versions(self): - res = self.app.get(self.version_list_url, auth=self.user.auth) - assert res.status_code == 200 - data = res.json['data'] - assert len(data) == 6 - assert len(set([item['id'] for item in data])) == 6 - - def test_public_visibility(self): - self.pre_mod_preprint.is_public = True - self.pre_mod_preprint.save() - res = self.app.get(self.version_list_url) - assert res.status_code == 200 - assert len(res.json['data']) == 6 - - def test_invalid_preprint_id(self): - res = self.app.get(f"/{API_BASE}preprints/lkziv_v1010101/versions/", auth=self.user.auth, expect_errors=True) - assert res.status_code == 404 - - def test_pagination(self): - res = self.app.get(f"{self.version_list_url}?page[size]=2", auth=self.user.auth) - assert res.status_code == 200 - data = res.json['data'] - assert len(data) == 2 - assert 'links' in res.json - assert 'next' in res.json['links'] - - def test_new_unpublished_version(self): - PreprintFactory.create_version( - self.latest_preprint, - creator=self.user, - set_doi=False, - final_machine_state='pending', - is_published=False - ) - res = self.app.get(self.version_list_url, auth=self.user.auth) - assert res.status_code == 200 - data = res.json['data'] - assert len(data) == 7 - assert len(set([item['id'] for item in data])) == 7 - - def test_preprints_version_permissions_for_admin(self): - res = self.app.get(self.version_list_url, auth=self.admin.auth) - assert res.status_code == 200 - assert len(res.json['data']) == 6 + self.non_contrib = AuthUserFactory() - unpublished_preprint_version = PreprintFactory.create_version( - create_from=self.latest_preprint, - creator=self.user, - final_machine_state='initial', - is_published=False, - set_doi=False + def test_list_versions_post_mod(self): + # Post moderation V1 (Accepted) + post_mod_preprint = PreprintFactory( + reviews_workflow='post-moderation', + creator=self.creator, + is_published=True ) - self.latest_preprint = unpublished_preprint_version - unpublished_preprint_version.add_contributor(self.admin, permissions=permissions.ADMIN) - - res = self.app.get(self.version_list_url, auth=self.admin.auth) - assert res.status_code == 200 - assert len(res.json['data']) == 6 - - unpublished_preprint_version.run_submit(user=self.admin) - res = self.app.get(self.version_list_url, auth=self.admin.auth) - assert res.status_code == 200 - assert len(res.json['data']) == 7 - - unpublished_preprint_version.run_accept(user=self.admin, comment='Text') - - res = self.app.get(self.version_list_url, auth=self.admin.auth) - assert res.status_code == 200 - assert len(res.json['data']) == 7 - - unpublished_version = PreprintFactory.create_version( - create_from=self.latest_preprint, - creator=self.user, + post_mod_preprint.add_contributor(self.admin_contrib, permissions=permissions.ADMIN) + post_mod_preprint.add_contributor(self.write_contrib, permissions=permissions.WRITE) + post_mod_preprint.add_contributor(self.read_contrib, permissions=permissions.READ) + post_mod_preprint.provider.get_group('moderator').user_set.add(self.moderator) + post_mod_versions_list_url = f"/{API_BASE}preprints/{post_mod_preprint.get_guid()._id}/versions/" + + # Post moderation V2 (Withdrawn) + post_mod_preprint_v2 = PreprintFactory.create_version( + create_from=post_mod_preprint, + creator=self.creator, final_machine_state='initial', - is_published=False, set_doi=False ) - unpublished_version.add_contributor(self.admin, permissions=permissions.ADMIN) - - unpublished_version.run_submit(user=self.admin) - - res = self.app.get(self.version_list_url, auth=self.admin.auth) - assert res.status_code == 200 - assert len(res.json['data']) == 8 - - unpublished_version.run_reject(user=self.admin, comment='Test') - res = self.app.get(self.version_list_url, auth=self.admin.auth) - assert res.status_code == 200 - assert len(res.json['data']) == 8 - - def test_preprints_version_permissions_for_write_user(self): - new_user = AuthUserFactory() - res = self.app.get(self.version_list_url, auth=new_user.auth) - assert res.status_code == 200 - assert len(res.json['data']) == 6 - - unpublished_preprint_version = PreprintFactory.create_version( - create_from=self.latest_preprint, - creator=self.user, + post_mod_preprint_v2.run_submit(self.creator) + post_mod_preprint_v2.run_accept(self.moderator, 'comment') + withdrawal_request = PreprintRequestFactory( + creator=self.creator, + target=post_mod_preprint_v2, + request_type=RequestTypes.WITHDRAWAL.value, + machine_state=DefaultStates.INITIAL.value) + withdrawal_request.run_submit(self.creator) + withdrawal_request.run_accept(self.moderator, withdrawal_request.comment) + + # Post moderation V3 (Pending) + post_mod_preprint_v3 = PreprintFactory.create_version( + create_from=post_mod_preprint_v2, + creator=self.creator, final_machine_state='initial', - is_published=False, set_doi=False ) - self.latest_preprint = unpublished_preprint_version - res = self.app.get(self.version_list_url, auth=new_user.auth) + post_mod_preprint_v3.run_submit(self.creator) + id_set = {post_mod_preprint._id, post_mod_preprint_v2._id, post_mod_preprint_v3._id} + res = self.app.get(post_mod_versions_list_url, auth=self.admin_contrib.auth) assert res.status_code == 200 - assert len(res.json['data']) == 6 - - unpublished_preprint_version.run_submit(user=self.admin) - res = self.app.get(self.version_list_url, auth=new_user.auth) - assert res.status_code == 200 - assert len(res.json['data']) == 6 - - unpublished_preprint_version.run_accept(user=self.admin, comment='Text') - - res = self.app.get(self.version_list_url, auth=new_user.auth) + data = res.json['data'] + assert len(data) == 3 + assert set([item['id'] for item in data]) == id_set + res = self.app.get(post_mod_versions_list_url, auth=self.write_contrib.auth) assert res.status_code == 200 - assert len(res.json['data']) == 7 - - unpublished_version = PreprintFactory.create_version( - create_from=self.latest_preprint, - creator=self.user, - final_machine_state='initial', - is_published=False, - set_doi=False - ) - - unpublished_version.run_submit(user=self.admin) - - res = self.app.get(self.version_list_url, auth=new_user.auth) + data = res.json['data'] + assert len(data) == 3 + assert set([item['id'] for item in data]) == id_set + res = self.app.get(post_mod_versions_list_url, auth=self.read_contrib.auth) assert res.status_code == 200 - assert len(res.json['data']) == 7 - - unpublished_version.run_reject(user=self.admin, comment='Test') - res = self.app.get(self.version_list_url, auth=new_user.auth) + data = res.json['data'] + assert len(data) == 3 + assert set([item['id'] for item in data]) == id_set + res = self.app.get(post_mod_versions_list_url, auth=self.non_contrib.auth) assert res.status_code == 200 - assert len(res.json['data']) == 7 - - def test_pre_mod_preprints_version_permissions_for_read_user(self): - new_user = AuthUserFactory() - res = self.app.get(self.version_list_url, auth=new_user.auth) + data = res.json['data'] + assert len(data) == 3 + assert set([item['id'] for item in data]) == id_set + res = self.app.get(post_mod_versions_list_url, auth=None) assert res.status_code == 200 - assert len(res.json['data']) == 6 + data = res.json['data'] + assert len(data) == 3 + assert set([item['id'] for item in data]) == id_set - unpublished_preprint_version = PreprintFactory.create_version( - create_from=self.latest_preprint, - creator=self.user, - final_machine_state='initial', - is_published=False, - set_doi=False + def test_list_versions_pre_mod(self): + # Pre moderation V1 (Accepted) + pre_mod_preprint = PreprintFactory( + reviews_workflow='pre-moderation', + creator=self.creator, + is_published=True ) - self.latest_preprint = unpublished_preprint_version - res = self.app.get(self.version_list_url, auth=new_user.auth) - assert res.status_code == 200 - assert len(res.json['data']) == 6 - - unpublished_preprint_version.run_submit(user=self.admin) - res = self.app.get(self.version_list_url, auth=new_user.auth) - assert res.status_code == 200 - assert len(res.json['data']) == 6 - - unpublished_preprint_version.run_accept(user=self.admin, comment='Text') - - res = self.app.get(self.version_list_url, auth=new_user.auth) - assert res.status_code == 200 - assert len(res.json['data']) == 7 - - unpublished_version = PreprintFactory.create_version( - create_from=self.latest_preprint, - creator=self.user, + pre_mod_preprint.provider.get_group('moderator').user_set.add(self.moderator) + pre_mod_preprint.add_contributor(self.admin_contrib, permissions=permissions.ADMIN) + pre_mod_preprint.add_contributor(self.write_contrib, permissions=permissions.WRITE) + pre_mod_preprint.add_contributor(self.read_contrib, permissions=permissions.READ) + pre_mod_versions_list_url = f"/{API_BASE}preprints/{pre_mod_preprint.get_guid()._id}/versions/" + + for contrib in pre_mod_preprint.contributor_set.all(): + print(f'>>>> {contrib}:{contrib.permission}') + + # Pre moderation V2 (Withdrawn) + pre_mod_preprint_v2 = PreprintFactory.create_version( + create_from=pre_mod_preprint, + creator=self.creator, final_machine_state='initial', - is_published=False, set_doi=False ) - - unpublished_version.run_submit(user=self.admin) - - res = self.app.get(self.version_list_url, auth=new_user.auth) - assert res.status_code == 200 - assert len(res.json['data']) == 7 - - unpublished_version.run_reject(user=self.admin, comment='Test') - res = self.app.get(self.version_list_url, auth=new_user.auth) - assert res.status_code == 200 - assert len(res.json['data']) == 7 - - def test_pre_mod_preprints_version_permissions_for_other_user(self): - new_user = AuthUserFactory() - res = self.app.get(self.version_list_url, auth=new_user.auth) - assert res.status_code == 200 - assert len(res.json['data']) == 6 - - unpublished_preprint_version = PreprintFactory.create_version( - create_from=self.latest_preprint, - creator=self.user, + pre_mod_preprint_v2.run_submit(self.creator) + pre_mod_preprint_v2.run_accept(self.moderator, 'comment') + withdrawal_request = PreprintRequestFactory( + creator=self.creator, + target=pre_mod_preprint_v2, + request_type=RequestTypes.WITHDRAWAL.value, + machine_state=DefaultStates.INITIAL.value) + withdrawal_request.run_submit(self.creator) + withdrawal_request.run_accept(self.moderator, withdrawal_request.comment) + + # Pre moderation V3 (Rejected) + pre_mod_preprint_v3 = PreprintFactory.create_version( + create_from=pre_mod_preprint_v2, + creator=self.creator, final_machine_state='initial', is_published=False, - set_doi=False + set_doi=False, ) - self.latest_preprint = unpublished_preprint_version - res = self.app.get(self.version_list_url, auth=new_user.auth) - assert res.status_code == 200 - assert len(res.json['data']) == 6 + pre_mod_preprint_v3.run_submit(self.creator) + pre_mod_preprint_v3.run_reject(self.moderator, 'comment') - unpublished_preprint_version.run_submit(user=self.admin) - res = self.app.get(self.version_list_url, auth=new_user.auth) - assert res.status_code == 200 - assert len(res.json['data']) == 6 - - unpublished_preprint_version.run_accept(user=self.admin, comment='Text') - - res = self.app.get(self.version_list_url, auth=new_user.auth) - assert res.status_code == 200 - assert len(res.json['data']) == 7 - - unpublished_version = PreprintFactory.create_version( - create_from=self.latest_preprint, - creator=self.user, + # Pre moderation V4 (Pending) + pre_mod_preprint_v4 = PreprintFactory.create_version( + create_from=pre_mod_preprint_v2, + creator=self.creator, final_machine_state='initial', is_published=False, set_doi=False ) + pre_mod_preprint_v4.run_submit(self.creator) - unpublished_version.run_submit(user=self.admin) - - res = self.app.get(self.version_list_url, auth=new_user.auth) - assert res.status_code == 200 - assert len(res.json['data']) == 7 - - unpublished_version.run_reject(user=self.admin, comment='Test') - res = self.app.get(self.version_list_url, auth=new_user.auth) - assert res.status_code == 200 - assert len(res.json['data']) == 7 - - def test_post_mod_preprints_version_permissions_for_admin_user(self): - res = self.app.get(self.version_list_url, auth=self.admin.auth) + admin_id_set = {pre_mod_preprint._id, pre_mod_preprint_v2._id, pre_mod_preprint_v3._id, pre_mod_preprint_v4._id} + non_admin_id_set = {pre_mod_preprint._id, pre_mod_preprint_v2._id} + res = self.app.get(pre_mod_versions_list_url, auth=self.admin_contrib.auth) assert res.status_code == 200 - assert len(res.json['data']) == 6 - - PreprintFactory.create_version( - create_from=self.latest_preprint, - creator=self.user, - final_machine_state='accepted', - is_published=True, - set_doi=False - ) - res = self.app.get(self.version_list_url, auth=self.admin.auth) + data = res.json['data'] + assert len(data) == 4 + assert set([item['id'] for item in data]) == admin_id_set + res = self.app.get(pre_mod_versions_list_url, auth=self.write_contrib.auth) assert res.status_code == 200 - assert len(res.json['data']) == 7 - - def test_post_mod_preprints_version_permissions_for_write_user(self): - new_user = AuthUserFactory() - res = self.app.get(self.version_list_url, auth=new_user.auth) + data = res.json['data'] + assert len(data) == 2 + assert set([item['id'] for item in data]) == non_admin_id_set + res = self.app.get(pre_mod_versions_list_url, auth=self.read_contrib.auth) assert res.status_code == 200 - assert len(res.json['data']) == 6 - - PreprintFactory.create_version( - create_from=self.latest_preprint, - creator=self.user, - final_machine_state='accepted', - is_published=True, - set_doi=False - ) - - res = self.app.get(self.version_list_url, auth=new_user.auth) + data = res.json['data'] + assert len(data) == 2 + assert set([item['id'] for item in data]) == non_admin_id_set + res = self.app.get(pre_mod_versions_list_url, auth=self.non_contrib.auth) assert res.status_code == 200 - assert len(res.json['data']) == 7 - - def test_post_mod_preprints_version_permissions_for_read_user(self): - new_user = AuthUserFactory() - res = self.app.get(self.version_list_url, auth=new_user.auth) + data = res.json['data'] + assert len(data) == 2 + assert set([item['id'] for item in data]) == non_admin_id_set + res = self.app.get(pre_mod_versions_list_url, auth=None) assert res.status_code == 200 - assert len(res.json['data']) == 6 + data = res.json['data'] + assert len(data) == 2 + assert set([item['id'] for item in data]) == non_admin_id_set - PreprintFactory.create_version( - create_from=self.latest_preprint, - creator=self.user, - final_machine_state='accepted', - is_published=True, - set_doi=False + def test_invalid_preprint_id(self): + versions_url_invalid_guid = f'/{API_BASE}preprints/abcde/versions/' + res = self.app.get(versions_url_invalid_guid, auth=None, expect_errors=True) + assert res.status_code == 404 + preprint = PreprintFactory( + reviews_workflow='post-moderation', + creator=self.creator, + is_published=True ) + versions_url_invalid_version = f'/{API_BASE}preprints/{preprint.get_guid()._id}_v2/versions/' + res = self.app.get(versions_url_invalid_version, auth=None, expect_errors=True) + assert res.status_code == 404 - res = self.app.get(self.version_list_url, auth=new_user.auth) - assert res.status_code == 200 - assert len(res.json['data']) == 7 - - def test_post_mod_preprints_version_permissions_for_other_user(self): - new_user = AuthUserFactory() - res = self.app.get(self.version_list_url, auth=new_user.auth) - assert res.status_code == 200 - assert len(res.json['data']) == 6 - - PreprintFactory.create_version( - create_from=self.latest_preprint, - creator=self.user, - final_machine_state='accepted', - is_published=True, - set_doi=False + def test_version_indifference(self): + latest_version = PreprintFactory( + reviews_workflow='post-moderation', + creator=self.creator, + is_published=True ) - - res = self.app.get(self.version_list_url, auth=new_user.auth) - assert res.status_code == 200 - assert len(res.json['data']) == 7 + for _ in range(5): + new_version = PreprintFactory.create_version( + create_from=latest_version, + creator=self.creator, + set_doi=False + ) + latest_version = new_version + versions_url_base_guid = f'/{API_BASE}preprints/{latest_version.get_guid()._id}/versions/' + res_1 = self.app.get(versions_url_base_guid, auth=self.creator.auth) + assert res_1.status_code == 200 + versions_url_valid_version = f'/{API_BASE}preprints/{latest_version._id}/versions/' + res_2 = self.app.get(versions_url_valid_version, auth=self.creator.auth) + assert res_2.status_code == 200 + assert len(res_1.json['data']) == len(res_2.json['data'])