Skip to content
Snippets Groups Projects
Commit 6677daba authored by Todd Dembrey's avatar Todd Dembrey
Browse files

Create basic tests for the reviews

parent 37d1e7c9
No related branches found
No related tags found
No related merge requests found
...@@ -819,4 +819,4 @@ class ApplicationSubmission(WorkflowHelpers, BaseStreamForm, AbstractFormSubmiss ...@@ -819,4 +819,4 @@ class ApplicationSubmission(WorkflowHelpers, BaseStreamForm, AbstractFormSubmiss
return f'{self.title} from {self.full_name} for {self.page.title}' return f'{self.title} from {self.full_name} for {self.page.title}'
def __repr__(self): def __repr__(self):
return f'<{self.__class__.__name__}: {str(self.form_data)}>' return f'<{self.__class__.__name__}: {self.user}, {self.round}, {self.page}>'
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
<div class="wrapper wrapper--breakout wrapper--admin"> <div class="wrapper wrapper--breakout wrapper--admin">
<div class="wrapper wrapper--medium"> <div class="wrapper wrapper--medium">
<h2 class="heading heading--no-margin">{{ title|default:"Create Review" }}</h2> <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>
</div> </div>
......
...@@ -27,3 +27,4 @@ class ReviewFactory(factory.DjangoModelFactory): ...@@ -27,3 +27,4 @@ class ReviewFactory(factory.DjangoModelFactory):
submission = factory.SubFactory(ApplicationSubmissionFactory) submission = factory.SubFactory(ApplicationSubmissionFactory)
author = factory.SubFactory(StaffFactory) author = factory.SubFactory(StaffFactory)
review = factory.Dict({'submission': factory.SelfAttribute('..submission')}, dict_factory=ReviewDataFactory) review = factory.Dict({'submission': factory.SelfAttribute('..submission')}, dict_factory=ReviewDataFactory)
is_draft = False
from django.test import TestCase, RequestFactory from django.test import TestCase, RequestFactory
from django.urls import reverse 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 .factories import ReviewFactory
from opentech.apply.funds.tests.factories import ApplicationSubmissionFactory from opentech.apply.funds.tests.factories import ApplicationSubmissionFactory
...@@ -44,6 +44,7 @@ class StaffReviewsTestCase(BaseTestCase): ...@@ -44,6 +44,7 @@ class StaffReviewsTestCase(BaseTestCase):
response = self.get_page(review) response = self.get_page(review)
self.assertContains(response, review.submission.title) self.assertContains(response, review.submission.title)
self.assertContains(response, self.user.full_name) 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): def test_cant_access_other_review(self):
submission = ApplicationSubmissionFactory() submission = ApplicationSubmissionFactory()
...@@ -64,5 +65,52 @@ class StaffReviewListingTestCase(BaseTestCase): ...@@ -64,5 +65,52 @@ class StaffReviewListingTestCase(BaseTestCase):
reviews = ReviewFactory.create_batch(3, submission=submission) reviews = ReviewFactory.create_batch(3, submission=submission)
response = self.get_page(submission, 'list') response = self.get_page(submission, 'list')
self.assertContains(response, submission.title) self.assertContains(response, submission.title)
self.assertContains(response, reverse('funds:submissions:detail', kwargs={'pk': submission.id}))
for review in reviews: for review in reviews:
self.assertContains(response, review.author.full_name) 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)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment