def test_applicant_and_staff_cant_edit_in_decline(self): payment_request = PaymentRequestFactory(status=DECLINED) applicant = ApplicantFactory() staff = StaffFactory() self.assertFalse(can_edit(payment_request, applicant)) self.assertFalse(can_edit(payment_request, staff))
def test_review_detail_opinion(self): staff = StaffFactory() submission = ApplicationSubmissionFactory(status='draft_proposal', workflow_stages=2) review = ReviewFactory(submission=submission, author__reviewer=self.user, recommendation_yes=True) ReviewOpinionFactory(review=review, author__reviewer=staff, opinion_disagree=True) response = self.get_page(review) self.assertContains(response, "Disagrees")
def test_user_cannot_upload_when_latest_is_approved(self): applicant = ApplicantFactory() staff = StaffFactory() project = ProjectFactory(status=CONTRACTING) ContractFactory(project=project, is_signed=True, approver=staff) self.assertFalse(user_can_upload_contract(project, applicant))
def test_applicant_and_staff_cant_edit_in_under_review(self): payment_request = PaymentRequestFactory(status=UNDER_REVIEW) applicant = ApplicantFactory() staff = StaffFactory() self.assertFalse(can_edit(payment_request, applicant)) self.assertFalse(can_edit(payment_request, staff))
def test_applicant_and_staff_can_edit_in_submitted(self): payment_request = PaymentRequestFactory(status=SUBMITTED) applicant = ApplicantFactory() staff = StaffFactory() self.assertTrue(can_edit(payment_request, applicant)) self.assertTrue(can_edit(payment_request, staff))
def test_urls_404_when_turned_off(self): self.client.force_login(StaffFactory()) response = self.client.get('/apply/projects/', follow=True) self.assertEqual(response.status_code, 404) response = self.client.get('/apply/projects/1/', follow=True) self.assertEqual(response.status_code, 404)
def dummy_request(self, path): request = RequestFactory().get(path) middleware = SessionMiddleware() middleware.process_request(request) request.session.save() request.user = StaffFactory() request._messages = FallbackStorage(request) return request
def test_review_list_opinion(self): staff = StaffFactory() submission = ApplicationSubmissionFactory(status='draft_proposal', workflow_stages=2) review = ReviewFactory(submission=submission, author__reviewer=self.user, recommendation_yes=True) ReviewOpinionFactory(review=review, author__reviewer=staff, opinion_disagree=True) response = self.get_page(review) response_opinion = response.context['review_data']['opinions']['answers'][0] self.assertIn("Disagrees", response_opinion) self.assertIn(str(staff), response_opinion)
def test_review_outcome(self): staff = StaffFactory() submission = ApplicationSubmissionFactory() ReviewFactory(submission=submission) qs = ApplicationSubmission.objects.for_table(user=staff) submission = qs[0] self.assertEqual(submission.opinion_disagree, None) self.assertEqual(submission.review_count, 1) self.assertEqual(submission.review_submitted_count, 1) self.assertEqual(submission.review_recommendation, NO)
def test_project_approver_can_see_projects_awaiting_review_stats_or_table( self): ProjectFactory(is_locked=True, status=COMMITTED) user = StaffFactory() user.groups.add(GroupFactory(name=APPROVER_GROUP_NAME)) self.client.force_login(user) response = self.get_page() self.assertContains(response, "Projects awaiting approval")
def test_can_see_opinion_buttons_on_others_review(self): staff = StaffFactory() review = ReviewFactory( submission=self.submission, author__reviewer=staff, author__staff=True, recommendation_yes=True, ) response = self.get_page(review) self.assertContains(response, 'name="agree"')
def test_disagree_opinion_redirects_to_review_form(self): staff = StaffFactory() review = ReviewFactory( submission=self.submission, author__reviewer=staff, author__staff=True, recommendation_yes=True, ) response = self.post_page(review, {'disagree': DISAGREE}) url = self.url_from_pattern('funds:submissions:reviews:form', kwargs={'submission_pk': self.submission.id}) self.assertRedirects(response, url)
def test_assigned_but_not_reviewed(self): staff = StaffFactory() submission = ApplicationSubmissionFactory() AssignedReviewersFactory(submission=submission, reviewer=staff) qs = ApplicationSubmission.objects.for_table(user=staff) submission = qs[0] self.assertEqual(submission.opinion_disagree, None) self.assertEqual(submission.review_count, 1) self.assertEqual(submission.review_submitted_count, None) self.assertEqual(submission.review_recommendation, None)
def test_disagree_review_is_maybe(self): staff = StaffFactory() submission = ApplicationSubmissionFactory() review = ReviewFactory(submission=submission) ReviewOpinionFactory(opinion_disagree=True, review=review) qs = ApplicationSubmission.objects.for_table(user=staff) submission = qs[0] self.assertEqual(submission.opinion_disagree, 1) self.assertEqual(submission.review_count, 2) # Reviewers that disagree are not counted self.assertEqual(submission.review_submitted_count, 1) self.assertEqual(submission.review_recommendation, MAYBE)
def test_project_required(self): factory = RequestFactory() submission = ApplicationSubmissionFactory() request = factory.get(f'/submission/{submission.pk}') request.user = StaffFactory() with self.assertRaises(Http404): SubmissionDetailSimplifiedView.as_view()(request, pk=submission.pk) ProjectFactory(submission=submission) response = SubmissionDetailSimplifiedView.as_view()(request, pk=submission.pk) self.assertEqual(response.status_code, 200)
def test_opinionated_slash_confused_reviewer(self): staff = StaffFactory() submission = ApplicationSubmissionFactory() review_one = ReviewFactory(submission=submission) review_two = ReviewFactory(submission=submission) ReviewOpinionFactory(opinion_disagree=True, review=review_one, author__reviewer=staff) ReviewOpinionFactory(opinion_agree=True, review=review_two, author__reviewer=staff) qs = ApplicationSubmission.objects.for_table(user=staff) submission = qs[0] self.assertEqual(submission.opinion_disagree, 1) self.assertEqual(submission.review_count, 3) # Reviewers that disagree are not counted self.assertEqual(submission.review_submitted_count, 3) self.assertEqual(submission.review_recommendation, MAYBE)
def test_can_add_opinion_to_others_review(self): staff = StaffFactory() review = ReviewFactory( submission=self.submission, author__reviewer=staff, author__staff=True, recommendation_yes=True, ) response = self.post_page(review, {'agree': AGREE}) self.assertTrue(review.opinions.first().opinion_display in Activity.objects.first().message) self.assertEqual(ReviewOpinion.objects.all().count(), 1) self.assertEqual(ReviewOpinion.objects.first().opinion, AGREE) url = self.url_from_pattern('apply:submissions:reviews:review', kwargs={'submission_pk': self.submission.pk, 'pk': review.id}) self.assertRedirects(response, url)
def test_email_staff_update_payment_request(self): project = self.source_factory() payment_request = PaymentRequestFactory(project=project) staff = StaffFactory() self.adapter_process( MESSAGES.UPDATE_PAYMENT_REQUEST, adapter=EmailAdapter(), user=staff, source=project, related=payment_request, ) self.assertEqual(len(mail.outbox), 1) self.assertEqual(mail.outbox[0].to, [project.user.email])
def test_waiting_for_review_after_agreement_is_empty(self): staff = StaffFactory() submission = ApplicationSubmissionFactory(status='external_review', workflow_stages=2, reviewers=[staff, self.user]) review = ReviewFactory(submission=submission, author__reviewer=staff, author__staff=True, recommendation_yes=True) ReviewOpinionFactory(review=review, author__reviewer=self.user, opinion_agree=True) response = self.get_page() self.assertContains(response, 'Waiting for your review') self.assertContains(response, "Nice! You're all caught up.") self.assertEquals(response.context['awaiting_reviews']['count'], 0)
def test_slack_staff_update_payment_request(self): responses.add(responses.POST, self.target_url, status=200, body='OK') project = self.source_factory() payment_request = PaymentRequestFactory(project=project) staff = StaffFactory() self.adapter_process( MESSAGES.UPDATE_PAYMENT_REQUEST, adapter=self.slack(), user=staff, source=project, related=payment_request, ) self.assertEqual(len(responses.calls), 1)
def test_dont_double_count_review_and_opinion(self): staff = StaffFactory() submission = ApplicationSubmissionFactory() review = ReviewFactory(submission=submission, author__reviewer=staff, author__staff=True) opinion = ReviewOpinionFactory(opinion_disagree=True, review=review) # Another pair of review/opinion review_two = ReviewFactory(author=opinion.author, submission=submission) ReviewOpinionFactory(opinion_disagree=True, author__reviewer=staff, author__staff=True, review=review_two) qs = ApplicationSubmission.objects.for_table(user=staff) submission = qs[0] self.assertEqual(submission.opinion_disagree, 2) self.assertEqual(submission.review_count, 2) self.assertEqual(submission.review_submitted_count, 2) self.assertEqual(submission.review_recommendation, MAYBE)
def test_staff_can_upload_after_state_leaves_committed(self): staff = StaffFactory() project = ProjectFactory(status=COMMITTED) self.assertFalse(user_can_upload_contract(project, staff)) project = ProjectFactory(status=CONTRACTING) self.assertTrue(user_can_upload_contract(project, staff)) project = ProjectFactory(status=IN_PROGRESS) self.assertTrue(user_can_upload_contract(project, staff)) project = ProjectFactory(status=COMPLETE) self.assertTrue(user_can_upload_contract(project, staff)) project = ProjectFactory(status=CLOSING) self.assertTrue(user_can_upload_contract(project, staff))
def test_queries_existing_reviews(self): user = StaffFactory() submission = InvitedToProposalFactory(lead=user) reviewers = ReviewerFactory.create_batch(4) ReviewFactory(submission=submission, author__reviewer=reviewers[0]) ReviewFactory(submission=submission, author__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 - Delete old # 1 - Cache existing # 1 - Add new with self.assertNumQueries(5): form.save()
def test_queries_init_and_render(self): user = StaffFactory() ReviewerRoleFactory.create_batch(3) StaffFactory.create_batch(3) ReviewerFactory.create_batch(3) submission = InvitedToProposalFactory(lead=user, workflow_stages=2) # Reviewers # Partners # Meta categories # Assigned Reviewers # Roles with self.assertNumQueries(5): form = UpdateReviewersForm(user=user, instance=submission) # 3 x Staff - 1 per Role # 1 x reviewers queryset # 1 x submission reviewers with self.assertNumQueries(5): form.as_p()
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_submissions_dont_conflict(self): staff = StaffFactory() submission_one = ApplicationSubmissionFactory() submission_two = ApplicationSubmissionFactory() review_one = ReviewFactory(submission=submission_one) ReviewOpinionFactory(opinion_disagree=True, review=review_one) ReviewFactory(submission=submission_two) qs = ApplicationSubmission.objects.order_by('pk').for_table(user=staff) submission = qs[0] self.assertEqual(submission, submission_one) self.assertEqual(submission.opinion_disagree, 1) self.assertEqual(submission.review_count, 2) # Reviewers that disagree are not counted self.assertEqual(submission.review_submitted_count, 1) self.assertEqual(submission.review_recommendation, MAYBE) submission = qs[1] self.assertEqual(submission, submission_two) self.assertEqual(submission.opinion_disagree, None) self.assertEqual(submission.review_count, 1) self.assertEqual(submission.review_submitted_count, 1) self.assertEqual(submission.review_recommendation, NO)
def test_queries_roles_swap(self): user = StaffFactory() submission = ApplicationSubmissionFactory() staff = StaffFactory.create_batch(4) roles = ReviewerRoleFactory.create_batch(2) form = UpdateReviewersForm(user=user, instance=submission) AssignedWithRoleReviewersFactory(role=roles[0], submission=submission, reviewer=staff[0], staff=True) AssignedWithRoleReviewersFactory(role=roles[1], submission=submission, reviewer=staff[1], staff=True) data = {} for field, user in zip(form.fields, staff): if field.startswith('role'): data[field] = user.id else: data[field] = None form = UpdateReviewersForm(data, user=user, instance=submission) self.assertTrue(form.is_valid()) # 1 - Submission # 24 - 12 per role = # 1 - delete role no review # 1 - select review # 2 - cascades # 1 - update role with review # 1 - auth group # 2 - savepoint # 1 - get # 1 - update # 2 - release savepoint with self.assertNumQueries(25): form.save()
def test_staff_can_change_status_from_changes_requested(self): payment_request = PaymentRequestFactory(status=CHANGES_REQUESTED) staff = StaffFactory() self.assertTrue(can_change_status(payment_request, staff))
def test_nonstaff_cant_post_opinion_to_review(self): staff = StaffFactory() review = ReviewFactory(submission=self.submission, author__reviewer=staff, author__staff=True, recommendation_yes=True) response = self.post_page(review, {'agree': AGREE}) self.assertEqual(response.status_code, 403)
def test_staff_can_change_status_from_under_review(self): payment_request = PaymentRequestFactory(status=UNDER_REVIEW) staff = StaffFactory() self.assertTrue(can_change_status(payment_request, staff))