def test_queries_reviewers_swap(self): user = StaffFactory() submission = InvitedToProposalFactory(lead=user) reviewers = ReviewerFactory.create_batch(4) AssignedReviewersFactory(submission=submission, reviewer=reviewers[0]) AssignedReviewersFactory(submission=submission, reviewer=reviewers[1]) data = { 'reviewer_reviewers': [reviewer.id for reviewer in reviewers[2:]] } form = UpdateReviewersForm(data, user=user, instance=submission) self.assertTrue(form.is_valid()) # 1 - Submission # 1 - Select Review # 2 - Cascase # 1 - Fetch data # 1 - Cache existing # 1 - auth group # 1 - Add new with self.assertNumQueries(8): form.save()
def test_reviewers_with_and_without_role(self): with_role = AssignedWithRoleReviewersFactory() without_role = AssignedReviewersFactory() message = self.adapter.reviewers_updated([with_role, without_role], []) self.assertTrue(str(with_role.reviewer) in message) self.assertTrue(str(with_role.role) in message) self.assertTrue(str(without_role.reviewer) in message)
def test_reviewers_message_no_added(self): assigned_reviewer = AssignedReviewersFactory() message = self.adapter.reviewers_updated([], [assigned_reviewer]) self.assertFalse('Added' in message) self.assertTrue('Removed' in message) self.assertTrue(str(assigned_reviewer.reviewer) in message)
def test_reviewers_message_both(self): added, removed = AssignedReviewersFactory.create_batch(2) message = self.adapter.reviewers_updated([added], [removed]) self.assertTrue('Added' in message) self.assertTrue('Removed' in message) self.assertTrue(str(added.reviewer) in message) self.assertTrue(str(removed.reviewer) in message)
def test_can_remove_external_reviewer_and_review_remains(self): submission = InvitedToProposalFactory(lead=self.user) reviewer = self.reviewers[0] AssignedReviewersFactory(submission=submission, reviewer=reviewer) ReviewFactory(submission=submission, author__reviewer=reviewer) self.post_form(submission, reviewers=[]) self.assertCountEqual(submission.reviewers.all(), [reviewer])
def test_reviewer_update_email(self): reviewers = ReviewerFactory.create_batch(4) submission = ApplicationSubmissionFactory(status='external_review', reviewers=reviewers, workflow_stages=2) added = [ AssignedReviewersFactory(submission=submission, reviewer=reviewers[0]) ] self.adapter_process(MESSAGES.REVIEWERS_UPDATED, source=submission, added=added) self.assertEqual(len(mail.outbox), 1) self.assertTrue(mail.outbox[0].subject, 'ready to review')