Пример #1
0
class TestDeclarationLetterForm(TestCase):

    base_form = DeclarationLetterFormSpec().build_form_class()

    def test_records_all_fields(self):
        data = mock.fake.declaration_letter_answers()
        input_form = self.base_form(data)
        self.assertTrue(input_form.is_valid())
        submission = models.FormSubmission(answers=input_form.cleaned_data)
        submission.save()
        output_form = self.base_form(submission.answers)
        self.assertTrue(output_form.is_valid())
        for key in data:
            field = output_form.get_field_by_input_name(key)
            self.assertFalse(field.is_empty(),
                             "couldn't find" + field.context_key)

    def test_displays_all_fields(self):
        data = mock.fake.declaration_letter_answers()
        input_form = self.base_form(data)
        self.assertTrue(input_form.is_valid())
        submission = models.FormSubmission(answers=input_form.cleaned_data)
        submission.save()
        output_form = self.base_form(submission.answers)
        self.assertTrue(output_form.is_valid())
        page_data = output_form.display()
        for key in data:
            field = output_form.get_field_by_input_name(key)
            self.assertIn(field.get_html_class_name(), page_data,
                          "couldn't find " + field.get_html_class_name())
Пример #2
0
def populate_answer_lookup():
    from user_accounts.models import Organization
    from formation.forms import county_form_selector, DeclarationLetterFormSpec
    letter_form_class = DeclarationLetterFormSpec().build_form_class()
    for org in Organization.objects.filter(is_receiving_agency=True):
        answer_mock_method_name = org.slug + '_answers'
        if not hasattr(fake, answer_mock_method_name):
            raise AttributeError(
                'There is no mock form answers method for {}'.format(org.slug))
        form_class = county_form_selector.get_combined_form_class(
            counties=[org.county.slug])
        mock_method_form_pairs = {}
        mock_method_form_pairs[answer_mock_method_name] = form_class
        if org.requires_declaration_letter:
            mock_method_form_pairs.update(
                declaration_letter_answers=letter_form_class)
        answer_lookup[org.slug] = AnswerGenerator(mock_method_form_pairs)
Пример #3
0
from .applicant_form_view_base import ApplicantFormViewBase
from django.shortcuts import redirect
from django.core.urlresolvers import reverse_lazy, reverse
from formation.forms import (DeclarationLetterFormSpec,
                             DeclarationLetterDisplay,
                             DeclarationLetterReviewForm, county_form_selector)
from django.utils import timezone
from intake.constants import (APPROVE_LETTER, EDIT_LETTER)

letter_form_spec = DeclarationLetterFormSpec()


class WriteDeclarationLetterView(ApplicantFormViewBase):
    template_name = "forms/declaration_letter_form.jinja"
    success_url = reverse_lazy('intake-review_letter')
    form_class = letter_form_spec.build_form_class()


class ReviewDeclarationLetterView(ApplicantFormViewBase):
    template_name = "forms/declaration_letter_review.jinja"
    success_url = reverse_lazy('intake-thanks')

    def get_form(self):
        if self.request.method == 'GET':
            display_data = self.session_data.copy()
            display_data['date_received'] = timezone.now()
            return DeclarationLetterDisplay(display_data, validate=True)
        elif self.request.method in ('POST', 'PUT'):
            return DeclarationLetterReviewForm(data=self.request.POST)

    def form_valid(self, form):