diff --git a/opentech/apply/funds/migrations/0041_roundbasereviewform.py b/opentech/apply/funds/migrations/0041_roundbasereviewform.py new file mode 100644 index 0000000000000000000000000000000000000000..3e8f52c0aa19194612ad09494a365c77047a4e00 --- /dev/null +++ b/opentech/apply/funds/migrations/0041_roundbasereviewform.py @@ -0,0 +1,29 @@ +# Generated by Django 2.0.2 on 2018-08-10 08:54 + +from django.db import migrations, models +import django.db.models.deletion +import modelcluster.fields + + +class Migration(migrations.Migration): + + dependencies = [ + ('review', '0006_remove_review_review'), + ('funds', '0040_add_duration_stream_to_streamfield_definition'), + ] + + operations = [ + migrations.CreateModel( + name='RoundBaseReviewForm', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('sort_order', models.IntegerField(blank=True, editable=False, null=True)), + ('form', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='review.ReviewForm')), + ('round', modelcluster.fields.ParentalKey(on_delete=django.db.models.deletion.CASCADE, related_name='review_forms', to='funds.RoundBase')), + ], + options={ + 'ordering': ['sort_order'], + 'abstract': False, + }, + ), + ] diff --git a/opentech/apply/funds/models/applications.py b/opentech/apply/funds/models/applications.py index ffccab07721daae95a51c00cd87f30f666b43473..e9aa7fe05c85db10f40eb0255d6b946cf4c690ff 100644 --- a/opentech/apply/funds/models/applications.py +++ b/opentech/apply/funds/models/applications.py @@ -21,7 +21,6 @@ from ..admin_forms import WorkflowFormAdminForm from ..edit_handlers import ReadOnlyPanel, ReadOnlyInlinePanel from .submissions import ApplicationSubmission -from .forms import RoundBaseForm from .utils import admin_url, EmailForm, SubmittableStreamForm, WorkflowStreamForm, LIMIT_TO_REVIEWERS, LIMIT_TO_STAFF @@ -115,7 +114,9 @@ class RoundBase(WorkflowStreamForm, SubmittableStreamForm): # type: ignore ], heading="Dates"), FieldPanel('reviewers'), ReadOnlyPanel('get_workflow_name_display', heading="Workflow"), + # Forms comes from parental key in models/forms.py ReadOnlyInlinePanel('forms', help_text="Are copied from the parent fund."), + ReadOnlyInlinePanel('review_forms', help_text="Are copied from the parent fund."), ] edit_handler = TabbedInterface([ @@ -156,13 +157,21 @@ class RoundBase(WorkflowStreamForm, SubmittableStreamForm): # type: ignore if is_new and hasattr(self, 'parent_page'): # Would be nice to do this using model clusters as part of the __init__ - for form in self.parent_page.forms.all(): - # Create a copy of the existing form object - new_form = form.form - new_form.id = None - new_form.name = '{} for {} ({})'.format(new_form.name, self.title, self.get_parent().title) - new_form.save() - RoundBaseForm.objects.create(round=self, form=new_form) + self._copy_forms('forms') + self._copy_forms('review_forms') + + def _copy_forms(self, field): + for form in getattr(self.parent_page, field).all(): + new_form = self._meta.get_field(field).related_model + self._copy_form(form, new_form) + + def _copy_form(self, form, new_class): + # Create a copy of the existing form object + new_form = form.form + new_form.id = None + new_form.name = '{} for {} ({})'.format(new_form.name, self.title, self.get_parent().title) + new_form.save() + new_class.objects.create(round=self, form=new_form) def get_submit_meta_data(self, **kwargs): return super().get_submit_meta_data( diff --git a/opentech/apply/funds/models/forms.py b/opentech/apply/funds/models/forms.py index 41f6fb32b7b3b6fda87ff360e036401ace77eebd..84154539fb4ecafa7a0d54132b65a1233abd47b0 100644 --- a/opentech/apply/funds/models/forms.py +++ b/opentech/apply/funds/models/forms.py @@ -63,6 +63,9 @@ class LabBaseForm(AbstractRelatedForm): class AbstractRelatedReviewForm(Orderable): + class Meta(Orderable.Meta): + abstract = True + form = models.ForeignKey('review.ReviewForm', on_delete=models.PROTECT) panels = [ @@ -73,9 +76,6 @@ class AbstractRelatedReviewForm(Orderable): def fields(self): return self.form.form_fields - class Meta(Orderable.Meta): - abstract = True - def __eq__(self, other): try: return self.fields == other.fields @@ -90,5 +90,9 @@ class ApplicationBaseReviewForm(AbstractRelatedReviewForm): application = ParentalKey('ApplicationBase', related_name='review_forms') +class RoundBaseReviewForm(AbstractRelatedReviewForm): + round = ParentalKey('RoundBase', related_name='review_forms') + + class LabBaseReviewForm(AbstractRelatedReviewForm): lab = ParentalKey('LabBase', related_name='review_forms') diff --git a/opentech/apply/funds/tests/factories/blocks.py b/opentech/apply/funds/tests/factories/blocks.py index 77cc38d4c0f70518bdb3cb58e07eacdf48835dbc..f562cf496aeb64a5b32635d0cb54ea1b39879816 100644 --- a/opentech/apply/funds/tests/factories/blocks.py +++ b/opentech/apply/funds/tests/factories/blocks.py @@ -1,3 +1,4 @@ +import json import random import factory @@ -54,15 +55,58 @@ class ValueFieldBlockFactory(FormFieldBlockFactory): model = blocks.ValueBlock @classmethod - def make_answer(cls, params=dict()): + def make_answer(cls, params=dict(), form=False): return random.randint(0, 1_000_000) +class AddressFieldBlockFactory(FormFieldBlockFactory): + class Meta: + model = blocks.AddressFieldBlock + + @classmethod + def an_adress(cls): + return { + 'country': 'GB', + 'thoroughfare': 'bah', + 'premise': 'baz', + 'locality': { + 'locality_name': 'bish', + 'administrative_area': 'bosh', + 'postal_code': 'SW1 4AQ', + } + } + + @classmethod + def make_answer(cls, params=dict()): + return json.dumps({ + 'country': 'GB', + 'thoroughfare': 'bah', + 'premise': 'baz', + 'localityname': 'bish', + 'administrativearea': 'bosh', + 'postalcode': 'SW1 4AQ', + }) + + @classmethod + def make_form_answer(cls, params=dict()): + return { + 'country': 'GB', + 'thoroughfare': 'bah', + 'premise': 'baz', + 'locality': { + 'locality_name': 'bish', + 'administrative_area': 'bosh', + 'postal_code': 'SW1 4AQ', + } + } + + CustomFormFieldsFactory = StreamFieldUUIDFactory({ 'duration': DurationBlockFactory, 'title': TitleBlockFactory, 'value': ValueFieldBlockFactory, 'email': EmailBlockFactory, + 'address': AddressFieldBlockFactory, 'full_name': FullNameBlockFactory, 'char': CharFieldBlockFactory, 'number': NumberFieldBlockFactory, diff --git a/opentech/apply/funds/tests/factories/models.py b/opentech/apply/funds/tests/factories/models.py index cffdc36f173ab0db015ca56f1b1d5ebc88774158..591854e893a1154f4ea875c92297eef859825c3f 100644 --- a/opentech/apply/funds/tests/factories/models.py +++ b/opentech/apply/funds/tests/factories/models.py @@ -15,8 +15,11 @@ from opentech.apply.funds.models import ( from opentech.apply.funds.models.forms import ( ApplicationForm, ApplicationBaseForm, + ApplicationBaseReviewForm, LabBaseForm, + LabBaseReviewForm, RoundBaseForm, + RoundBaseReviewForm, ) from opentech.apply.users.tests.factories import StaffFactory, UserFactory from opentech.apply.stream_forms.testing.factories import FormDataFactory @@ -69,14 +72,16 @@ class FundTypeFactory(wagtail_factories.PageFactory): @factory.post_generation def forms(self, create, extracted, **kwargs): if create: - from opentech.apply.review.tests.factories.models import ReviewFormFactory for _ in self.workflow.stages: # Generate a form based on all defined fields on the model ApplicationBaseFormFactory( application=self, **kwargs, ) - ReviewFormFactory(**kwargs) + ApplicationBaseReviewForm( + application=self, + **kwargs, + ) class RequestForPartnersFactory(FundTypeFactory): @@ -128,6 +133,10 @@ class RoundFactory(wagtail_factories.PageFactory): round=self, **kwargs, ) + RoundBaseReviewFormFactory( + round=self, + **kwargs, + ) class SealedRoundFactory(RoundFactory): @@ -167,6 +176,10 @@ class LabFactory(wagtail_factories.PageFactory): lab=self, **kwargs, ) + LabBaseReviewFormFactory( + lab=self, + **kwargs, + ) class LabBaseFormFactory(AbstractRelatedFormFactory): @@ -239,3 +252,30 @@ class ApplicationRevisionFactory(factory.DjangoModelFactory): for_factory=ApplicationSubmissionFactory, clean=True, ) + + +class AbstractReviewFormFactory(factory.DjangoModelFactory): + class Meta: + abstract = True + form = factory.SubFactory('opentech.apply.review.tests.factories.ReviewFormFactory') + + +class ApplicationBaseReviewFormFactory(AbstractReviewFormFactory): + class Meta: + model = ApplicationBaseReviewForm + + application = factory.SubFactory(FundTypeFactory) + + +class RoundBaseReviewFormFactory(AbstractReviewFormFactory): + class Meta: + model = RoundBaseReviewForm + + round = factory.SubFactory(RoundFactory) + + +class LabBaseReviewFormFactory(AbstractReviewFormFactory): + class Meta: + model = LabBaseReviewForm + + lab = factory.SubFactory(LabFactory) diff --git a/opentech/apply/funds/tests/test_models.py b/opentech/apply/funds/tests/test_models.py index 9b21854c42f8127783fd6889788ba0b09b6a4293..b3b79b32fa5b8051ad222217f92a7042d192ba06 100644 --- a/opentech/apply/funds/tests/test_models.py +++ b/opentech/apply/funds/tests/test_models.py @@ -12,6 +12,7 @@ from django.test import TestCase, override_settings from wagtail.core.models import Site from opentech.apply.funds.models import ApplicationSubmission +from opentech.apply.funds.blocks import EmailBlock, FullNameBlock from opentech.apply.funds.workflow import Request from opentech.apply.utils.testing import make_request @@ -28,6 +29,18 @@ def days_from_today(days): return date.today() + timedelta(days=days) +def flatten_for_form(data, field_name='', number=False): + result = {} + for i, (field, value) in enumerate(data.items()): + if number: + field = f'{field_name}_{i}' + if isinstance(value, dict): + result.update(**flatten_for_form(value, field_name=field, number=True)) + else: + result[field] = value + return result + + class TestFundModel(TestCase): def setUp(self): self.fund = FundTypeFactory(parent=None) @@ -196,16 +209,24 @@ class TestFormSubmission(TestCase): self.round_page = RoundFactory(parent=fund, now=True) self.lab_page = LabFactory(lead=self.round_page.lead) - def submit_form(self, page=None, email=None, name=None, user=AnonymousUser()): - if email is None: - email = self.email - if name is None: - name = self.name - + def submit_form(self, page=None, email=None, name=None, user=AnonymousUser(), ignore_errors=False): page = page or self.round_page fields = page.get_form_fields() - # This needs to match the order of the fields defined on the form factory - data = {k: v for k, v in zip(fields, [1, 'project', 0, email, name])} + + data = { + field: factory.make_form_answer() + for field, factory in zip(fields, CustomFormFieldsFactory.factories.values()) + if hasattr(factory, 'make_form_answer') + } + + data = flatten_for_form(data) + + for field in page.forms.first().fields: + if isinstance(field.block, EmailBlock): + data[field.id] = self.email if email is None else email + if isinstance(field.block, FullNameBlock): + data[field.id] = self.name if name is None else name + request = make_request(user, data, method='post', site=self.site) try: @@ -213,7 +234,9 @@ class TestFormSubmission(TestCase): except AttributeError: response = page.serve(request) - self.assertNotContains(response, 'There where some errors with your form') + if not ignore_errors: + # Check the data we submit is correct + self.assertNotContains(response, 'errors') return response def test_workflow_and_status_assigned(self): @@ -287,7 +310,7 @@ class TestFormSubmission(TestCase): # Lead + applicant self.assertEqual(self.User.objects.count(), 2) - response = self.submit_form(email='', name='', user=user) + response = self.submit_form(email='', name='', user=user, ignore_errors=True) self.assertContains(response, 'This field is required') # Lead + applicant diff --git a/opentech/apply/funds/tests/test_views.py b/opentech/apply/funds/tests/test_views.py index ebacea7f3a05e1f73ab122cf40782c50fc7ca73d..46184012f3f14b50a9531a88f9d6207551fa8859 100644 --- a/opentech/apply/funds/tests/test_views.py +++ b/opentech/apply/funds/tests/test_views.py @@ -1,4 +1,5 @@ from datetime import datetime, timedelta +import json from opentech.apply.activity.models import Activity from opentech.apply.funds.tests.factories import ( @@ -12,6 +13,7 @@ from opentech.apply.users.tests.factories import UserFactory, StaffFactory, Supe from opentech.apply.utils.testing.tests import BaseViewTestCase from ..models import ApplicationRevision +from .test_models import flatten_for_form class BaseSubmissionViewTestCase(BaseViewTestCase): @@ -130,6 +132,16 @@ class TestApplicantSubmissionView(BaseSubmissionViewTestCase): class TestRevisionsView(BaseSubmissionViewTestCase): user_factory = UserFactory + def prepare_address(self, address, field): + address = json.loads(address) + address['locality'] = { + 'localityname': address.pop('localityname'), + 'administrativearea': address.pop('administrativearea'), + 'postalcode': address.pop('postalcode'), + } + address = flatten_for_form(address, field, number=True) + return address + def test_create_revisions_on_submit(self): submission = ApplicationSubmissionFactory(status='draft_proposal', workflow_stages=2, user=self.user) old_data = submission.form_data.copy() @@ -137,6 +149,13 @@ class TestRevisionsView(BaseSubmissionViewTestCase): new_title = 'New title' new_data[submission.must_include['title']] = new_title + address_id = submission.must_include['address'] + + new_data.update(**self.prepare_address( + new_data[submission.must_include['address']], + address_id, + )) + self.post_page(submission, {'submit': True, **new_data}, 'edit') submission = self.refresh(submission) @@ -151,7 +170,16 @@ class TestRevisionsView(BaseSubmissionViewTestCase): def test_dont_update_live_revision_on_save(self): submission = ApplicationSubmissionFactory(status='draft_proposal', workflow_stages=2, user=self.user) old_data = submission.form_data.copy() + new_data = submission.raw_data + + address_id = submission.must_include['address'] + + new_data.update(**self.prepare_address( + new_data[submission.must_include['address']], + address_id, + )) + new_data[submission.must_include['title']] = 'New title' self.post_page(submission, {'save': True, **new_data}, 'edit') @@ -166,7 +194,16 @@ class TestRevisionsView(BaseSubmissionViewTestCase): def test_existing_draft_edit_and_submit(self): submission = ApplicationSubmissionFactory(status='draft_proposal', workflow_stages=2, user=self.user) draft_data = submission.raw_data.copy() + + address_id = submission.must_include['address'] + + draft_data.update(**self.prepare_address( + draft_data[submission.must_include['address']], + address_id, + )) + draft_data[submission.must_include['title']] = 'New title' + self.post_page(submission, {'save': True, **draft_data}, 'edit') submission = self.refresh(submission) diff --git a/opentech/apply/review/tests/factories/blocks.py b/opentech/apply/review/tests/factories/blocks.py index 77c8a161205c929ff5d39179d814d7b3f08a5964..600291d33423712a1daca8884756e507457651a3 100644 --- a/opentech/apply/review/tests/factories/blocks.py +++ b/opentech/apply/review/tests/factories/blocks.py @@ -37,7 +37,7 @@ class ScoreFieldBlockFactory(FormFieldBlockFactory): ReviewFormFieldsFactory = StreamFieldUUIDFactory({ 'char': CharFieldBlockFactory, 'rich_text': RichTextFieldBlockFactory, - 'scored_answer': ScoreFieldBlockFactory, + 'score': ScoreFieldBlockFactory, 'recommendation': RecommendationBlockFactory, 'recommendation_comments': RecommendationCommentsBlockFactory, }) diff --git a/opentech/apply/review/tests/factories/models.py b/opentech/apply/review/tests/factories/models.py index 79a82eb4b6b3052a4a02bb00dde3aff66d3600b4..8110443c9ff94ad4c9dd990478fc2d31ad1c69af 100644 --- a/opentech/apply/review/tests/factories/models.py +++ b/opentech/apply/review/tests/factories/models.py @@ -1,36 +1,20 @@ import factory -from opentech.apply.funds.models.forms import ApplicationBaseReviewForm -from opentech.apply.funds.tests.factories import ApplicationSubmissionFactory, FundTypeFactory +from opentech.apply.funds.tests.factories import ApplicationSubmissionFactory from opentech.apply.stream_forms.testing.factories import AddFormFieldsMetaclass from opentech.apply.users.tests.factories import StaffFactory from ...options import YES, NO, MAYBE from ...models import Review, ReviewForm -from ...views import get_fields_for_stage from . import blocks -__all__ = ['ReviewFactory', 'ReviewFormFactory', - 'ApplicationBaseReviewFormFactory', 'ReviewFundTypeFactory', - 'ReviewApplicationSubmissionFactory'] +__all__ = ['ReviewFactory', 'ReviewFormFactory'] class ReviewFormDataFactory(factory.DictFactory, metaclass=AddFormFieldsMetaclass): field_factory = blocks.ReviewFormFieldsFactory - @classmethod - def _build(cls, model_class, *args, **kwargs): - submission = kwargs.pop('submission') - - form_fields = { - field.id: 0 - for field in get_fields_for_stage(submission) - } - - form_fields.update(**kwargs) - return super()._build(model_class, *args, **form_fields) - class ReviewFactory(factory.DjangoModelFactory): class Meta: @@ -47,7 +31,6 @@ class ReviewFactory(factory.DjangoModelFactory): form_data = factory.SubFactory( ReviewFormDataFactory, form_fields=factory.SelfAttribute('..form_fields'), - submission=factory.SelfAttribute('..submission'), ) is_draft = False recommendation = NO @@ -60,32 +43,3 @@ class ReviewFormFactory(factory.DjangoModelFactory): name = factory.Faker('word') form_fields = blocks.ReviewFormFieldsFactory - - -class AbstractRelatedReviewFormFactory(factory.DjangoModelFactory): - class Meta: - abstract = True - form = factory.SubFactory(ReviewFormFactory) - - -class ReviewFundTypeFactory(FundTypeFactory): - - @factory.post_generation - def review_forms(self, create, extracted, **kwargs): - if create: - for _ in self.workflow.stages: - # Generate a form based on all defined fields on the model - ApplicationBaseReviewFormFactory( - application=self, - **kwargs - ) - - -class ApplicationBaseReviewFormFactory(AbstractRelatedReviewFormFactory): - class Meta: - model = ApplicationBaseReviewForm - application = factory.SubFactory(ReviewFundTypeFactory, parent=None) - - -class ReviewApplicationSubmissionFactory(ApplicationSubmissionFactory): - page = factory.SubFactory(ReviewFundTypeFactory) diff --git a/opentech/apply/review/tests/test_views.py b/opentech/apply/review/tests/test_views.py index d1b1da318f49bf578b77d16a5cc2d600d95a89df..3ac1e6ab244cbc935459a6afccb74eff8b6f13f8 100644 --- a/opentech/apply/review/tests/test_views.py +++ b/opentech/apply/review/tests/test_views.py @@ -1,6 +1,6 @@ from django.urls import reverse -from opentech.apply.review.tests.factories.models import ReviewApplicationSubmissionFactory +from opentech.apply.funds.tests.factories.models import ApplicationSubmissionFactory from opentech.apply.users.tests.factories import StaffFactory, UserFactory from opentech.apply.utils.testing.tests import BaseViewTestCase from .factories import ReviewFactory @@ -15,15 +15,14 @@ class StaffReviewsTestCase(BaseViewTestCase): return {'pk': instance.id, 'submission_pk': instance.submission.id} def test_can_access_review(self): - submission = ReviewApplicationSubmissionFactory() - review = ReviewFactory(submission=submission, author=self.user) + review = ReviewFactory(author=self.user) 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})) + self.assertContains(response, reverse('funds:submissions:detail', kwargs={'pk': review.submission.id})) def test_cant_access_other_review(self): - submission = ReviewApplicationSubmissionFactory() + submission = ApplicationSubmissionFactory() review = ReviewFactory(submission=submission) response = self.get_page(review) self.assertEqual(response.status_code, 403) @@ -38,7 +37,7 @@ class StaffReviewListingTestCase(BaseViewTestCase): return {'submission_pk': instance.id} def test_can_access_review_listing(self): - submission = ReviewApplicationSubmissionFactory() + submission = ApplicationSubmissionFactory() reviews = ReviewFactory.create_batch(3, submission=submission) response = self.get_page(submission, 'list') self.assertContains(response, submission.title) @@ -56,18 +55,18 @@ class StaffReviewFormTestCase(BaseViewTestCase): return {'submission_pk': instance.id} def test_can_access_form(self): - submission = ReviewApplicationSubmissionFactory(status='internal_review') + 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 = ReviewApplicationSubmissionFactory() + submission = ApplicationSubmissionFactory() response = self.get_page(submission, 'form') self.assertEqual(response.status_code, 403) def test_cant_resubmit_review(self): - submission = ReviewApplicationSubmissionFactory(status='internal_review') + 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) @@ -76,7 +75,7 @@ class StaffReviewFormTestCase(BaseViewTestCase): def test_can_edit_draft_review(self): # FIXME fix form generation issue in ReviewFundTypeFactory review_forms() return - submission = ReviewApplicationSubmissionFactory(status='internal_review') + 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) @@ -92,7 +91,7 @@ class UserReviewFormTestCase(BaseViewTestCase): return {'submission_pk': instance.id} def test_cant_access_form(self): - submission = ReviewApplicationSubmissionFactory(status='internal_review') + submission = ApplicationSubmissionFactory(status='internal_review') response = self.get_page(submission, 'form') self.assertEqual(response.status_code, 403) @@ -106,7 +105,7 @@ class ReviewDetailTestCase(BaseViewTestCase): return {'pk': instance.id, 'submission_pk': instance.submission.id} def test_review_detail_recommendation(self): - submission = ReviewApplicationSubmissionFactory(status='draft_proposal', workflow_stages=2) + submission = ApplicationSubmissionFactory(status='draft_proposal', workflow_stages=2) review = ReviewFactory(submission=submission, author=self.user, recommendation_yes=True) response = self.get_page(review) self.assertContains(response, submission.title) diff --git a/opentech/apply/review/views.py b/opentech/apply/review/views.py index 588c896b34c65cdf2b4c4a0785a48ee1c85d29d3..21412e27a5c024acc3eb434c070cae1fd499a04b 100644 --- a/opentech/apply/review/views.py +++ b/opentech/apply/review/views.py @@ -31,7 +31,7 @@ class ReviewContextMixin: def get_fields_for_stage(submission): - forms = submission.page.specific.review_forms.all() + forms = submission.get_from_parent('review_forms').all() index = submission.workflow.stages.index(submission.stage) try: return forms[index].form.form_fields diff --git a/opentech/apply/stream_forms/blocks.py b/opentech/apply/stream_forms/blocks.py index 77692d430db347d4f637f0761c874160f43d6726..b0c450dc5d56e3faf1d8c23c0f1f78725fa87a29 100644 --- a/opentech/apply/stream_forms/blocks.py +++ b/opentech/apply/stream_forms/blocks.py @@ -61,7 +61,7 @@ class FormFieldBlock(StructBlock): def format_data(self, data): return data - def no_responose(self): + def no_response(self): return "No response" diff --git a/opentech/apply/stream_forms/testing/factories.py b/opentech/apply/stream_forms/testing/factories.py index dfccb6bf957c067335c2f011f7f7d4a29025e96c..a7a12f3feb1a72840e9fa2e1effa207cd0d01160 100644 --- a/opentech/apply/stream_forms/testing/factories.py +++ b/opentech/apply/stream_forms/testing/factories.py @@ -88,6 +88,10 @@ class FormFieldBlockFactory(wagtail_factories.StructBlockFactory): def make_answer(cls, params=dict()): return cls.default_value.generate(params) + @classmethod + def make_form_answer(cls, params=dict()): + return cls.make_answer(params) + class CharFieldBlockFactory(FormFieldBlockFactory): default_value = factory.Faker('sentence') @@ -123,11 +127,15 @@ class UploadableMediaFactory(FormFieldBlockFactory): @classmethod def make_answer(cls, params=dict()): + params = params.copy() + params.setdefault('data', b'this is some content') file_name, file = cls.default_value()._make_content(params) return InMemoryUploadedFile(file, 'file', file_name, None, file.tell(), None) class ImageFieldBlockFactory(UploadableMediaFactory): + default_value = factory.django.ImageField + class Meta: model = stream_blocks.ImageFieldBlock