diff --git a/opentech/apply/funds/models.py b/opentech/apply/funds/models.py index 993b4f8a664c07996e16dd04c472662bb106e6a4..8b43dbcf5c9169843c224794f10713b42d694ab4 100644 --- a/opentech/apply/funds/models.py +++ b/opentech/apply/funds/models.py @@ -819,4 +819,4 @@ class ApplicationSubmission(WorkflowHelpers, BaseStreamForm, AbstractFormSubmiss return f'{self.title} from {self.full_name} for {self.page.title}' def __repr__(self): - return f'<{self.__class__.__name__}: {str(self.form_data)}>' + return f'<{self.__class__.__name__}: {self.user}, {self.round}, {self.page}>' diff --git a/opentech/apply/review/templates/review/review_form.html b/opentech/apply/review/templates/review/review_form.html index e1cf3f1073b6ffd26f7f7e2402fd27c26176567f..ec8fe019ae1d2dc8b866d3c544391bd9cf58d968 100644 --- a/opentech/apply/review/templates/review/review_form.html +++ b/opentech/apply/review/templates/review/review_form.html @@ -4,7 +4,7 @@ <div class="wrapper wrapper--breakout wrapper--admin"> <div class="wrapper wrapper--medium"> <h2 class="heading heading--no-margin">{{ title|default:"Create Review" }}</h2> - <h5>For <a href="{% url "funds:reviews:detail" submission.id %}">{{ submission.title }}</a></h5> + <h5>For <a href="{% url "funds:submissions:detail" submission.id %}">{{ submission.title }}</a></h5> </div> </div> diff --git a/opentech/apply/review/tests/factories.py b/opentech/apply/review/tests/factories.py index 2a4e3908c64f974a83695c61c830eea36cf73245..520e2f4667d0c0ad2aca1883b76614b97c62ae40 100644 --- a/opentech/apply/review/tests/factories.py +++ b/opentech/apply/review/tests/factories.py @@ -27,3 +27,4 @@ class ReviewFactory(factory.DjangoModelFactory): submission = factory.SubFactory(ApplicationSubmissionFactory) author = factory.SubFactory(StaffFactory) review = factory.Dict({'submission': factory.SelfAttribute('..submission')}, dict_factory=ReviewDataFactory) + is_draft = False diff --git a/opentech/apply/review/tests/test_views.py b/opentech/apply/review/tests/test_views.py index daac64e08d8f9f6356f319dc079da48d7b2d486c..0f4d45a23049e18f65ed7e5e445938ad2024f105 100644 --- a/opentech/apply/review/tests/test_views.py +++ b/opentech/apply/review/tests/test_views.py @@ -1,7 +1,7 @@ from django.test import TestCase, RequestFactory from django.urls import reverse -from opentech.apply.users.tests.factories import StaffFactory +from opentech.apply.users.tests.factories import StaffFactory, UserFactory from .factories import ReviewFactory from opentech.apply.funds.tests.factories import ApplicationSubmissionFactory @@ -44,6 +44,7 @@ class StaffReviewsTestCase(BaseTestCase): response = self.get_page(review) self.assertContains(response, review.submission.title) self.assertContains(response, self.user.full_name) + self.assertContains(response, reverse('funds:submissions:detail', kwargs={'pk': submission.id})) def test_cant_access_other_review(self): submission = ApplicationSubmissionFactory() @@ -64,5 +65,52 @@ class StaffReviewListingTestCase(BaseTestCase): reviews = ReviewFactory.create_batch(3, submission=submission) response = self.get_page(submission, 'list') self.assertContains(response, submission.title) + self.assertContains(response, reverse('funds:submissions:detail', kwargs={'pk': submission.id})) for review in reviews: self.assertContains(response, review.author.full_name) + + +class StaffReviewFormTestCase(BaseTestCase): + user_factory = StaffFactory + url_name = 'funds:submissions:reviews:{}' + + def get_kwargs(self, instance): + return {'submission_pk': instance.id} + + def test_can_access_form(self): + submission = ApplicationSubmissionFactory(status='internal_review') + response = self.get_page(submission, 'form') + self.assertContains(response, submission.title) + self.assertContains(response, reverse('funds:submissions:detail', kwargs={'pk': submission.id})) + + def test_cant_access_wrong_status(self): + submission = ApplicationSubmissionFactory() + response = self.get_page(submission, 'form') + self.assertEqual(response.status_code, 403) + + def test_cant_resubmit_review(self): + submission = ApplicationSubmissionFactory(status='internal_review') + ReviewFactory(submission=submission, author=self.user) + response = self.post_page(submission, {'data': 'value'}, 'form') + self.assertEqual(response.context['has_submitted_review'], True) + self.assertEqual(response.context['title'], 'Update Review draft') + + def test_can_edit_draft_review(self): + submission = ApplicationSubmissionFactory(status='internal_review') + ReviewFactory(submission=submission, author=self.user, is_draft=True) + response = self.post_page(submission, {'data': 'value'}, 'form') + self.assertEqual(response.context['has_submitted_review'], False) + self.assertEqual(response.context['title'], 'Update Review draft') + + +class UserReviewFormTestCase(BaseTestCase): + user_factory = UserFactory + url_name = 'funds:submissions:reviews:{}' + + def get_kwargs(self, instance): + return {'submission_pk': instance.id} + + def test_cant_access_form(self): + submission = ApplicationSubmissionFactory(status='internal_review') + response = self.get_page(submission, 'form') + self.assertEqual(response.status_code, 403)