From f38d11cff42739f2e33bd0982ce9b5a50b28a70f Mon Sep 17 00:00:00 2001 From: Tom Pollard Date: Wed, 15 Nov 2023 12:26:08 -0500 Subject: [PATCH] Add test case for transferring submitting author. --- physionet-django/project/test_views.py | 39 ++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/physionet-django/project/test_views.py b/physionet-django/project/test_views.py index 97393f01ca..5f6a862570 100644 --- a/physionet-django/project/test_views.py +++ b/physionet-django/project/test_views.py @@ -553,6 +553,45 @@ def test_content(self): self.assertFalse(project.is_submittable()) +class TestProjectTransfer(TestCase): + """ + Tests that submitting author status can be transferred to a co-author + """ + AUTHOR_EMAIL = 'rgmark@mit.edu' + COAUTHOR_EMAIL = 'aewj@mit.edu' + PASSWORD = 'Tester11!' + PROJECT_SLUG = 'T108xFtYkRAxiRiuOLEJ' + + def setUp(self): + self.client.login(username=self.AUTHOR_EMAIL, password=self.PASSWORD) + self.project = ActiveProject.objects.get(slug=self.PROJECT_SLUG) + self.submitting_author = self.project.authors.filter(is_submitting=True).first() + self.coauthor = self.project.authors.filter(is_submitting=False).first() + + def test_transfer_author(self): + """ + Test that an activate project can be transferred to a co-author. + """ + self.assertTrue(self.submitting_author.user.email, self.AUTHOR_EMAIL) + self.assertTrue(self.coauthor.user.email, self.COAUTHOR_EMAIL) + + response = self.client.post( + reverse('project_authors', args=(self.project.slug,)), + data={ + 'transfer_author': self.coauthor.user.id, + }) + + # Check if redirect happens, implying successful transfer + self.assertEqual(response.status_code, 302) + + # Fetch the updated project data + updated_project = ActiveProject.objects.get(slug=self.PROJECT_SLUG) + + # Verify that the author has been transferred + self.assertFalse(updated_project.authors.get(user=self.submitting_author.user).is_submitting) + self.assertTrue(updated_project.authors.get(user=self.coauthor.user).is_submitting) + + class TestAccessPublished(TestMixin): """ Test that certain views or content in their various states can only