Beispiel #1
0
 def setUp(self):
     self.gal = GrantApplicationLinkFactory()
     self.url = reverse('grant-applications:application-review',
                        args=(self.gal.pk, ))
class TestCompanyDetailsView(BaseTestCase):
    def setUp(self):
        super().setUp()
        self.gal = GrantApplicationLinkFactory()
        self.url = reverse('grant-applications:company-details',
                           args=(self.gal.pk, ))

    def test_get_template(self, *mocks):
        response = self.client.get(self.url)
        self.assertEqual(response.status_code, 200)
        self.assertTemplateUsed(response, CompanyDetailsView.template_name)

    def test_back_url_select_company(self, *mocks):
        response = self.client.get(self.url)
        self.assertEqual(response.status_code, 200)
        back_html = BeautifulSoup(response.content,
                                  'html.parser').find(id='id_back_link')
        self.assertEqual(
            back_html.attrs['href'],
            reverse('grant-applications:select-company', args=(self.gal.pk, )))

    def test_back_url_manual_company_details(self, *mocks):
        fake_grant_application = FAKE_GRANT_APPLICATION.copy()
        fake_grant_application['company'] = None
        mocks[1].return_value = fake_grant_application

        response = self.client.get(self.url)

        self.assertEqual(response.status_code, 200)
        back_html = BeautifulSoup(response.content,
                                  'html.parser').find(id='id_back_link')
        self.assertEqual(
            back_html.attrs['href'],
            reverse('grant-applications:manual-company-details',
                    args=(self.gal.pk, )))

    def test_post(self, *mocks):
        response = self.client.post(
            self.url,
            data={
                'number_of_employees':
                CompanyDetailsForm.NumberOfEmployees.HAS_FEWER_THAN_10,
                'is_turnover_greater_than': True
            })
        self.assertEqual(response.status_code, 302)
        mocks[0].assert_called_once_with(
            grant_application_id=str(self.gal.backoffice_grant_application_id),
            number_of_employees=CompanyDetailsForm.NumberOfEmployees.
            HAS_FEWER_THAN_10.value,
            is_turnover_greater_than=True)

    def test_post_form_redirect_path(self, *mocks):
        response = self.client.post(
            self.url,
            data={
                'number_of_employees':
                CompanyDetailsForm.NumberOfEmployees.HAS_FEWER_THAN_10,
                'is_turnover_greater_than': True
            })
        self.assertEqual(response.status_code, 302)
        self.assertRedirects(response=response,
                             expected_url=reverse(
                                 'grant-applications:contact-details',
                                 args=(self.gal.pk, )))

    def test_post_cannot_set_random_field(self, *mocks):
        response = self.client.post(
            self.url,
            data={
                'number_of_employees':
                CompanyDetailsForm.NumberOfEmployees.HAS_FEWER_THAN_10,
                'is_turnover_greater_than': True,
                'is_already_committed_to_event': True
            })
        self.assertEqual(response.status_code, 302)
        mocks[0].assert_called_once_with(
            grant_application_id=str(self.gal.backoffice_grant_application_id),
            number_of_employees=CompanyDetailsForm.NumberOfEmployees.
            HAS_FEWER_THAN_10.value,
            is_turnover_greater_than=True)

    def test_required_fields(self, *mocks):
        response = self.client.post(self.url)
        self.assertFormError(response, 'form', 'number_of_employees',
                             self.form_msgs['required'])
        self.assertFormError(response, 'form', 'is_turnover_greater_than',
                             self.form_msgs['required'])

    def test_get_redirects_to_confirmation_if_application_already_sent_for_review(
            self, *mocks):
        fake_grant_application = FAKE_GRANT_APPLICATION.copy()
        fake_grant_application['sent_for_review'] = True
        mocks[1].return_value = fake_grant_application
        response = self.client.get(self.url)
        self.assertRedirects(
            response,
            reverse('grant-applications:confirmation', args=(self.gal.pk, )))

    def test_get_redirects_to_ineligible_if_application_is_not_active(
            self, *mocks):
        fake_grant_application = FAKE_GRANT_APPLICATION.copy()
        fake_grant_application['is_eligible'] = False
        mocks[1].return_value = fake_grant_application
        response = self.client.get(self.url)
        self.assertRedirects(response,
                             reverse('grant-applications:ineligible'))

    def test_post_redirects_to_ineligible_if_application_is_not_active(
            self, *mocks):
        fake_grant_application = FAKE_GRANT_APPLICATION.copy()
        fake_grant_application['is_eligible'] = False
        mocks[1].return_value = fake_grant_application
        response = self.client.post(self.url)
        self.assertRedirects(response,
                             reverse('grant-applications:ineligible'))

    def test_get_does_not_redirect_to_ineligible_if_review_page_has_been_viewed(
            self, *mocks):
        fake_grant_application = FAKE_GRANT_APPLICATION.copy()
        fake_grant_application['is_eligible'] = False
        mocks[1].return_value = fake_grant_application

        self.gal.has_viewed_review_page = True
        self.gal.save()

        response = self.client.get(self.url)
        self.assertEqual(response.status_code, 200)
        self.assertTemplateUsed(response, CompanyDetailsView.template_name)

    def test_post_redirects_to_review_page_if_application_review_page_has_been_viewed(
            self, *mocks):
        self.gal.has_viewed_review_page = True
        self.gal.save()
        response = self.client.post(
            self.url,
            data={
                'number_of_employees':
                CompanyDetailsForm.NumberOfEmployees.HAS_FEWER_THAN_10,
                'is_turnover_greater_than': True,
                'is_already_committed_to_event': True
            })
        self.assertRedirects(response,
                             reverse('grant-applications:application-review',
                                     args=(self.gal.pk, )),
                             fetch_redirect_response=False)
Beispiel #3
0
class TestPreviousApplicationsView(BaseTestCase):

    def setUp(self):
        self.gal = GrantApplicationLinkFactory(
            backoffice_grant_application_id=FAKE_GRANT_APPLICATION['id']
        )
        self.url = reverse('grant-applications:previous-applications', args=(self.gal.pk,))

    def test_get(self, *mocks):
        response = self.client.get(self.url)
        self.assertEqual(response.status_code, 200)
        self.assertTemplateUsed(response, PreviousApplicationsView.template_name)

    def test_back_url(self, *mocks):
        response = self.client.get(self.url)
        self.assertEqual(response.status_code, 200)
        back_html = BeautifulSoup(response.content, 'html.parser').find(id='id_back_link')
        self.assertEqual(back_html.attrs['href'], reverse("grant-applications:before-you-start"))

    def test_heading(self, *mocks):
        response = self.client.get(self.url)
        self.assertEqual(response.status_code, 200)
        html = BeautifulSoup(response.content, 'html.parser').find(id='id_page_heading')
        self.assertEqual(html.text, PreviousApplicationsView.extra_context['page']['heading'])

    def test_get_on_get_ga_backoffice_exception(self, *mocks):
        mocks[1].side_effect = BackofficeServiceException
        response = self.client.get(self.url)
        self.assertEqual(response.status_code, 200)
        self.assertTemplateUsed(response, PreviousApplicationsView.template_name)

    def test_get_redirects_to_confirmation_if_application_already_sent_for_review(self, *mocks):
        fake_grant_application = FAKE_GRANT_APPLICATION.copy()
        fake_grant_application['sent_for_review'] = True
        mocks[1].return_value = fake_grant_application
        response = self.client.get(self.url)
        self.assertRedirects(
            response, reverse('grant-applications:confirmation', args=(self.gal.pk,))
        )

    def test_get_redirects_to_ineligible_if_application_is_not_active(self, *mocks):
        fake_grant_application = FAKE_GRANT_APPLICATION.copy()
        fake_grant_application['is_eligible'] = False
        mocks[1].return_value = fake_grant_application
        response = self.client.get(self.url)
        self.assertRedirects(response, reverse('grant-applications:ineligible'))

    def test_post_redirects_to_ineligible_if_application_is_not_active(self, *mocks):
        fake_grant_application = FAKE_GRANT_APPLICATION.copy()
        fake_grant_application['is_eligible'] = False
        mocks[1].return_value = fake_grant_application
        response = self.client.post(self.url)
        self.assertRedirects(response, reverse('grant-applications:ineligible'))

    def test_get_does_not_redirect_to_ineligible_if_review_page_has_been_viewed(self, *mocks):
        fake_grant_application = FAKE_GRANT_APPLICATION.copy()
        fake_grant_application['is_eligible'] = False
        mocks[1].return_value = fake_grant_application

        self.gal.has_viewed_review_page = True
        self.gal.save()

        response = self.client.get(self.url)
        self.assertEqual(response.status_code, 200)
        self.assertTemplateUsed(response, PreviousApplicationsView.template_name)

    def test_post_redirects_to_review_page_if_application_review_page_has_been_viewed(self, *mocks):
        self.gal.has_viewed_review_page = True
        self.gal.save()
        response = self.client.post(
            self.url,
            data={'previous_applications': FAKE_GRANT_APPLICATION['previous_applications']}
        )
        self.assertRedirects(
            response,
            reverse('grant-applications:application-review', args=(self.gal.pk,)),
            fetch_redirect_response=False
        )

    def test_post_updates_backoffice_grant_application(self, *mocks):
        response = self.client.post(
            self.url,
            data={'previous_applications': FAKE_GRANT_APPLICATION['previous_applications']}
        )
        self.assertRedirects(
            response,
            expected_url=reverse('grant-applications:find-an-event', args=(self.gal.pk,)),
            fetch_redirect_response=False
        )
        mocks[0].assert_called_once_with(
            grant_application_id=self.gal.backoffice_grant_application_id,
            previous_applications=FAKE_GRANT_APPLICATION['previous_applications']
        )

    def test_initial_data_populated_from_grant_application_object(self, *mocks):
        response = self.client.get(self.url)
        self.assertEqual(response.status_code, 200)

        soup = BeautifulSoup(response.content, 'html.parser')
        selected_radio = soup.find('input', checked=True)
        self.assertEqual(
            selected_radio.attrs['value'],
            str(FAKE_GRANT_APPLICATION['previous_applications'])
        )

    def test_previous_applications_required(self, *mocks):
        response = self.client.post(self.url)
        self.assertFormError(response, 'form', 'previous_applications', self.form_msgs['required'])

    def test_previous_applications_cannot_be_blank(self, *mocks):
        response = self.client.post(self.url, data={'previous_applications': ''})
        self.assertFormError(response, 'form', 'previous_applications', self.form_msgs['required'])

    def test_form_error_on_update_ga_backoffice_exception(self, *mocks):
        mocks[0].side_effect = BackofficeServiceException
        response = self.client.post(
            self.url,
            data={'previous_applications': FAKE_GRANT_APPLICATION['previous_applications']}
        )
        self.assertEqual(response.status_code, 200)
        mocks[0].assert_called_once_with(
            grant_application_id=FAKE_GRANT_APPLICATION['id'],
            previous_applications=FAKE_GRANT_APPLICATION['previous_applications']
        )
        self.assertFormError(response, 'form', None, self.form_msgs['resubmit'])

    def test_post_form_error_if_get_ga_backoffice_exception(self, *mocks):
        mocks[1].side_effect = BackofficeServiceException
        response = self.client.post(
            self.url,
            data={'previous_applications': FAKE_GRANT_APPLICATION['previous_applications']}
        )
        self.assertRedirects(
            response,
            reverse('grant-applications:find-an-event', args=(self.gal.pk,)),
            fetch_redirect_response=False
        )
        mocks[0].assert_called_once_with(
            grant_application_id=self.gal.backoffice_grant_application_id,
            previous_applications=FAKE_GRANT_APPLICATION['previous_applications']
        )
Beispiel #4
0
class TestExportExperienceView(BaseTestCase):
    def setUp(self):
        self.gal = GrantApplicationLinkFactory()
        self.url = reverse('grant-applications:export-experience',
                           kwargs={'pk': self.gal.pk})

    def test_get(self, *mocks):
        response = self.client.get(self.url)
        self.assertEqual(response.status_code, 200)
        self.assertTemplateUsed(response, ExportExperienceView.template_name)

    def test_post(self, *mocks):
        response = self.client.post(self.url,
                                    data={
                                        'has_exported_before': False,
                                        'has_product_or_service_for_export':
                                        True,
                                    })
        self.assertEqual(response.status_code, 302)
        mocks[0].assert_called_once_with(
            grant_application_id=str(self.gal.backoffice_grant_application_id),
            has_exported_before=False,
            has_product_or_service_for_export=True,
            # we expect this screen to clear the export details if has_exported_before is False
            has_exported_in_last_12_months=None,
            export_regions=None,
            markets_intending_on_exporting_to=None,
            is_in_contact_with_dit_trade_advisor=None,
            ita_name=None,
            ita_email=None,
            ita_mobile_number=None,
            export_experience_description=None,
            export_strategy=None,
        )

    def test_post_redirect_to_export_details_on_true(self, *mocks):
        fake_grant_application = FAKE_GRANT_APPLICATION.copy()
        fake_grant_application['has_exported_before'] = True
        mocks[0].return_value = fake_grant_application
        response = self.client.post(self.url,
                                    data={'has_exported_before': True})
        self.assertRedirects(response,
                             reverse('grant-applications:export-details',
                                     args=(self.gal.pk, )),
                             fetch_redirect_response=False)

    def test_post_redirect_to_trade_event_details_on_false(self, *mocks):
        response = self.client.post(self.url,
                                    data={
                                        'has_exported_before': False,
                                        'has_product_or_service_for_export':
                                        True,
                                    })
        self.assertRedirects(response,
                             reverse('grant-applications:trade-event-details',
                                     args=(self.gal.pk, )),
                             fetch_redirect_response=False)

    def test_2nd_question_not_required_if_has_exported_before_is_true(
            self, *mocks):
        response = self.client.post(self.url,
                                    data={'has_exported_before': True})
        self.assertEqual(response.status_code, 302)
        mocks[0].assert_called_once_with(
            grant_application_id=str(self.gal.backoffice_grant_application_id),
            has_exported_before=True,
            has_product_or_service_for_export=None)

    def test_has_exported_before_is_true_has_product_or_service_for_export_is_unset_1(
            self, *mocks):
        response = self.client.post(self.url,
                                    data={
                                        'has_exported_before': True,
                                        'has_product_or_service_for_export':
                                        True
                                    })
        self.assertEqual(response.status_code, 302)
        mocks[0].assert_called_once_with(
            grant_application_id=str(self.gal.backoffice_grant_application_id),
            has_exported_before=True,
            has_product_or_service_for_export=None)

    def test_has_exported_before_is_true_has_product_or_service_for_export_is_unset_2(
            self, *mocks):
        response = self.client.post(self.url,
                                    data={
                                        'has_exported_before': True,
                                        'has_product_or_service_for_export':
                                        False
                                    })
        self.assertEqual(response.status_code, 302)
        mocks[0].assert_called_once_with(
            grant_application_id=str(self.gal.backoffice_grant_application_id),
            has_exported_before=True,
            has_product_or_service_for_export=None)

    def test_2nd_question_required_if_has_exported_before_is_false(
            self, *mocks):
        response = self.client.post(self.url,
                                    data={'has_exported_before': False})
        self.assertEqual(response.status_code, 200)
        self.assertFormError(response, 'form',
                             'has_product_or_service_for_export',
                             self.form_msgs['required'])

    def test_get_redirects_to_confirmation_if_application_already_sent_for_review(
            self, *mocks):
        fake_grant_application = FAKE_GRANT_APPLICATION.copy()
        fake_grant_application['sent_for_review'] = True
        mocks[1].return_value = fake_grant_application
        response = self.client.get(self.url)
        self.assertRedirects(
            response,
            reverse('grant-applications:confirmation', args=(self.gal.pk, )))

    def test_get_redirects_to_ineligible_if_application_is_not_active(
            self, *mocks):
        fake_grant_application = FAKE_GRANT_APPLICATION.copy()
        fake_grant_application['is_eligible'] = False
        mocks[1].return_value = fake_grant_application
        response = self.client.get(self.url)
        self.assertRedirects(response,
                             reverse('grant-applications:ineligible'))

    def test_post_redirects_to_ineligible_if_application_is_not_active(
            self, *mocks):
        fake_grant_application = FAKE_GRANT_APPLICATION.copy()
        fake_grant_application['is_eligible'] = False
        mocks[1].return_value = fake_grant_application
        response = self.client.post(self.url)
        self.assertRedirects(response,
                             reverse('grant-applications:ineligible'))

    def test_get_does_not_redirect_to_ineligible_if_review_page_has_been_viewed(
            self, *mocks):
        fake_grant_application = FAKE_GRANT_APPLICATION.copy()
        fake_grant_application['is_eligible'] = False
        mocks[1].return_value = fake_grant_application

        self.gal.has_viewed_review_page = True
        self.gal.save()

        response = self.client.get(self.url)
        self.assertEqual(response.status_code, 200)
        self.assertTemplateUsed(response, ExportExperienceView.template_name)

    def test_post_redirects_to_review_page_if_application_review_page_has_been_viewed(
            self, *mocks):
        fake_grant_application = FAKE_GRANT_APPLICATION.copy()
        fake_grant_application['has_exported_before'] = False
        mocks[0].return_value = fake_grant_application
        mocks[1].return_value = fake_grant_application

        self.gal.has_viewed_review_page = True
        self.gal.save()

        response = self.client.post(self.url,
                                    data={
                                        'has_exported_before': False,
                                        'has_product_or_service_for_export':
                                        True,
                                    })
        self.assertRedirects(response,
                             reverse('grant-applications:application-review',
                                     args=(self.gal.pk, )),
                             fetch_redirect_response=False)

    def test_post_redirects_to_export_page_if_application_review_page_has_been_viewed(
            self, *mocks):
        fake_grant_application = FAKE_GRANT_APPLICATION.copy()
        fake_grant_application['has_exported_before'] = True
        mocks[0].return_value = fake_grant_application
        mocks[1].return_value = fake_grant_application

        self.gal.has_viewed_review_page = True
        self.gal.save()

        response = self.client.post(self.url,
                                    data={
                                        'has_exported_before': True,
                                    })
        self.assertRedirects(response,
                             reverse('grant-applications:export-details',
                                     args=(self.gal.pk, )),
                             fetch_redirect_response=False)
Beispiel #5
0
 def setUp(self):
     super().setUp()
     self.gal = GrantApplicationLinkFactory()
     self.url = reverse('grant-applications:manual-company-details',
                        args=(self.gal.pk, ))
class TestEventCommitmentView(BaseTestCase):
    def setUp(self):
        self.gal = GrantApplicationLinkFactory()
        self.url = reverse('grant-applications:event-commitment',
                           args=(self.gal.pk, ))

    def test_get_template(self, *mocks):
        response = self.client.get(self.url)
        self.assertEqual(response.status_code, 200)
        self.assertTemplateUsed(response, EventCommitmentView.template_name)

    def test_post_redirects(self, *mocks):
        response = self.client.post(
            self.url, data={'is_already_committed_to_event': True})
        self.assertEqual(response.status_code, 302)
        self.assertRedirects(response=response,
                             expected_url=reverse(
                                 EventCommitmentView.success_url_name,
                                 args=(self.gal.pk, )))

    def test_get_redirects_to_confirmation_if_application_already_sent_for_review(
            self, *mocks):
        fake_grant_application = FAKE_GRANT_APPLICATION.copy()
        fake_grant_application['sent_for_review'] = True
        mocks[1].return_value = fake_grant_application
        response = self.client.get(self.url)
        self.assertRedirects(
            response,
            reverse('grant-applications:confirmation', args=(self.gal.pk, )))

    def test_get_redirects_to_ineligible_if_application_is_not_active(
            self, *mocks):
        fake_grant_application = FAKE_GRANT_APPLICATION.copy()
        fake_grant_application['is_eligible'] = False
        mocks[1].return_value = fake_grant_application
        response = self.client.get(self.url)
        self.assertRedirects(response,
                             reverse('grant-applications:ineligible'))

    def test_post_redirects_to_ineligible_if_application_is_not_active(
            self, *mocks):
        fake_grant_application = FAKE_GRANT_APPLICATION.copy()
        fake_grant_application['is_eligible'] = False
        mocks[1].return_value = fake_grant_application
        response = self.client.post(self.url)
        self.assertRedirects(response,
                             reverse('grant-applications:ineligible'))

    def test_get_does_not_redirect_to_ineligible_if_review_page_has_been_viewed(
            self, *mocks):
        fake_grant_application = FAKE_GRANT_APPLICATION.copy()
        fake_grant_application['is_eligible'] = False
        mocks[1].return_value = fake_grant_application

        self.gal.has_viewed_review_page = True
        self.gal.save()

        response = self.client.get(self.url)
        self.assertEqual(response.status_code, 200)
        self.assertTemplateUsed(response, EventCommitmentView.template_name)

    def test_post_redirects_to_review_page_if_application_review_page_has_been_viewed(
            self, *mocks):
        self.gal.has_viewed_review_page = True
        self.gal.save()
        response = self.client.post(
            self.url, data={'is_already_committed_to_event': True})
        self.assertRedirects(response,
                             reverse('grant-applications:application-review',
                                     args=(self.gal.pk, )),
                             fetch_redirect_response=False)

    def test_post_data_is_saved(self, *mocks):
        self.client.post(self.url,
                         data={'is_already_committed_to_event': True})
        mocks[0].assert_called_once_with(grant_application_id=str(
            self.gal.backoffice_grant_application_id),
                                         is_already_committed_to_event=True)

    def test_boolean_fields_must_be_present(self, *mocks):
        response = self.client.post(self.url)
        self.assertFormError(response, 'form', 'is_already_committed_to_event',
                             self.form_msgs['required'])
 def setUp(self):
     self.gal = GrantApplicationLinkFactory()
     self.url = reverse('grant-applications:state-aid-summary', args=(self.gal.pk,))
 def setUp(self):
     self.gal = GrantApplicationLinkFactory()
     self.url = reverse('grant-applications:company-trading-details',
                        kwargs={'pk': self.gal.pk})
class TestAddStateAidView(BaseTestCase):

    def setUp(self):
        self.gal = GrantApplicationLinkFactory()
        self.url = reverse('grant-applications:add-state-aid', args=(self.gal.pk,))

    def test_get(self, *mocks):
        response = self.client.get(self.url)
        self.assertEqual(response.status_code, 200)
        self.assertTemplateUsed(response, AddStateAidView.template_name)

    def test_post_creates_state_aid_item(self, *mocks):
        response = self.client.post(
            self.url,
            data={
                'authority': 'An authority',
                'date_received_0': '01',
                'date_received_1': '05',
                'date_received_2': '2020',
                'amount': 2000,
                'description': 'A description',
            }
        )
        self.assertEqual(response.status_code, 302)
        mocks[2].assert_called_once_with(
            grant_application=str(self.gal.backoffice_grant_application_id),
            authority='An authority',
            date_received=datetime.date(year=2020, month=5, day=1),
            amount=2000,
            description='A description',
        )

    def test_create_state_aid_backoffice_exception(self, *mocks):
        mocks[2].side_effect = BackofficeServiceException
        response = self.client.post(
            self.url,
            data={
                'authority': 'An authority',
                'date_received_0': '01',
                'date_received_1': '05',
                'date_received_2': '2020',
                'amount': 2000,
                'description': 'A description',
            }
        )
        self.assertEqual(response.status_code, 200)
        self.assertFormError(response, 'form', None, self.form_msgs['resubmit'])
        mocks[2].assert_called_once_with(
            grant_application=str(self.gal.backoffice_grant_application_id),
            authority='An authority',
            date_received=datetime.date(year=2020, month=5, day=1),
            amount=2000,
            description='A description',
        )

    def test_required_fields(self, *mocks):
        response = self.client.post(self.url)
        self.assertEqual(response.status_code, 200)
        self.assertFormError(response, 'form', 'authority', self.form_msgs['required'])
        self.assertFormError(response, 'form', 'date_received', self.form_msgs['required'])
        self.assertFormError(response, 'form', 'amount', self.form_msgs['required'])
        self.assertFormError(response, 'form', 'description', self.form_msgs['required'])

    def test_aid_amount_is_a_number(self, *mocks):
        response = self.client.post(self.url, data={'amount': 'bad-value'})
        self.assertFormError(response, 'form', 'amount', self.form_msgs['number'])

    def test_invalid_date_received(self, *mocks):
        response = self.client.post(
            self.url,
            data={
                'date_received_0': 'bad',
                'date_received_1': 'bad',
                'date_received_2': 'bad',
            }
        )
        self.assertFormError(response, 'form', 'date_received', self.form_msgs['invalid-date'])

    def test_missing_date_received_year(self, *mocks):
        response = self.client.post(
            self.url, data={'date_received_0': '01', 'date_received_1': '05'}
        )
        self.assertFormError(response, 'form', 'date_received', self.form_msgs['required'])

    def test_get_redirects_to_confirmation_if_application_already_sent_for_review(self, *mocks):
        fake_grant_application = FAKE_GRANT_APPLICATION.copy()
        fake_grant_application['sent_for_review'] = True
        mocks[1].return_value = fake_grant_application
        response = self.client.get(self.url)
        self.assertRedirects(
            response, reverse('grant-applications:confirmation', args=(self.gal.pk,))
        )

    def test_get_redirects_to_ineligible_if_application_is_not_active(self, *mocks):
        fake_grant_application = FAKE_GRANT_APPLICATION.copy()
        fake_grant_application['is_eligible'] = False
        mocks[1].return_value = fake_grant_application
        response = self.client.get(self.url)
        self.assertRedirects(response, reverse('grant-applications:ineligible'))

    def test_post_redirects_to_ineligible_if_application_is_not_active(self, *mocks):
        fake_grant_application = FAKE_GRANT_APPLICATION.copy()
        fake_grant_application['is_eligible'] = False
        mocks[1].return_value = fake_grant_application
        response = self.client.post(self.url)
        self.assertRedirects(response, reverse('grant-applications:ineligible'))

    def test_get_does_not_redirect_to_ineligible_if_review_page_has_been_viewed(self, *mocks):
        fake_grant_application = FAKE_GRANT_APPLICATION.copy()
        fake_grant_application['is_eligible'] = False
        mocks[1].return_value = fake_grant_application

        self.gal.has_viewed_review_page = True
        self.gal.save()

        response = self.client.get(self.url)
        self.assertEqual(response.status_code, 200)
        self.assertTemplateUsed(response, AddStateAidView.template_name)

    def test_post_redirects_to_state_aid_summary_page_if_review_page_has_been_viewed(self, *mocks):
        self.gal.has_viewed_review_page = True
        self.gal.save()
        response = self.client.post(
            self.url,
            data={
                'authority': 'An authority',
                'date_received_0': '01',
                'date_received_1': '05',
                'date_received_2': '2020',
                'amount': 2000,
                'description': 'A description',
            }
        )
        self.assertRedirects(
            response,
            reverse('grant-applications:state-aid-summary', args=(self.gal.pk,)),
            fetch_redirect_response=False
        )
class TestStateAidSummaryView(BaseTestCase):

    def setUp(self):
        self.gal = GrantApplicationLinkFactory()
        self.url = reverse('grant-applications:state-aid-summary', args=(self.gal.pk,))

    def test_get(self, *mocks):
        response = self.client.get(self.url)
        self.assertEqual(response.status_code, 200)
        self.assertTemplateUsed(response, StateAidSummaryView.template_name)

    def test_get_with_no_state_aid_items_gives_default_table(self, *mocks):
        mocks[5].return_value = []
        response = self.client.get(self.url)
        self.assertEqual(response.status_code, 200)
        html = BeautifulSoup(response.content, 'html.parser').find(id='id_table')

        all_table_cells = html.find_all('td')
        self.assertEqual(len(all_table_cells), 4)
        for cell in all_table_cells:
            self.assertEqual(cell.text, '\n        -\n      ')

    def test_back_url(self, *mocks):
        response = self.client.get(self.url)
        self.assertEqual(response.status_code, 200)
        back_html = BeautifulSoup(response.content, 'html.parser').find(id='id_back_link')
        self.assertEqual(
            back_html.attrs['href'],
            reverse('grant-applications:export-experience', args=(self.gal.pk,))
        )

    def test_add_state_aid_link(self, *mocks):
        response = self.client.get(self.url)
        soup = BeautifulSoup(response.content, 'html.parser')
        self.assertEqual(
            soup.find(id='id_link_button').attrs['href'],
            reverse('grant-applications:add-state-aid', args=(self.gal.pk,))
        )

    def test_post(self, *mocks):
        response = self.client.post(self.url)
        mocks[0].assert_not_called()
        self.assertRedirects(
            response,
            reverse('grant-applications:application-review', args=(self.gal.pk,)),
            fetch_redirect_response=False
        )

    def test_get_redirects_to_confirmation_if_application_already_sent_for_review(self, *mocks):
        fake_grant_application = FAKE_GRANT_APPLICATION.copy()
        fake_grant_application['sent_for_review'] = True
        mocks[1].return_value = fake_grant_application
        response = self.client.get(self.url)
        self.assertRedirects(
            response, reverse('grant-applications:confirmation', args=(self.gal.pk,))
        )

    def test_get_redirects_to_ineligible_if_application_is_not_active(self, *mocks):
        fake_grant_application = FAKE_GRANT_APPLICATION.copy()
        fake_grant_application['is_eligible'] = False
        mocks[1].return_value = fake_grant_application
        response = self.client.get(self.url)
        self.assertRedirects(response, reverse('grant-applications:ineligible'))

    def test_post_redirects_to_ineligible_if_application_is_not_active(self, *mocks):
        fake_grant_application = FAKE_GRANT_APPLICATION.copy()
        fake_grant_application['is_eligible'] = False
        mocks[1].return_value = fake_grant_application
        response = self.client.post(self.url)
        self.assertRedirects(response, reverse('grant-applications:ineligible'))

    def test_get_does_not_redirect_to_ineligible_if_review_page_has_been_viewed(self, *mocks):
        fake_grant_application = FAKE_GRANT_APPLICATION.copy()
        fake_grant_application['is_eligible'] = False
        mocks[1].return_value = fake_grant_application

        self.gal.has_viewed_review_page = True
        self.gal.save()

        response = self.client.get(self.url)
        self.assertEqual(response.status_code, 200)
        self.assertTemplateUsed(response, StateAidSummaryView.template_name)

    def test_post_redirects_to_review_page_if_application_review_page_has_been_viewed(self, *mocks):
        self.gal.has_viewed_review_page = True
        self.gal.save()
        response = self.client.post(self.url)
        self.assertRedirects(
            response,
            reverse('grant-applications:application-review', args=(self.gal.pk,)),
            fetch_redirect_response=False
        )
class TestContactDetailsView(BaseTestCase):

    def setUp(self):
        self.gal = GrantApplicationLinkFactory()
        self.url = reverse('grant-applications:contact-details', kwargs={'pk': self.gal.pk})

    def test_get(self, *mocks):
        response = self.client.get(self.url)
        self.assertEqual(response.status_code, 200)
        self.assertTemplateUsed(response, ContactDetailsView.template_name)

    def test_post_redirects(self, *mocks):
        response = self.client.post(
            self.url,
            data={
                'applicant_full_name': 'A Name',
                'applicant_email': '*****@*****.**',
                'applicant_mobile_number': '+447777777777',
                'job_title': 'director'
            }
        )
        self.assertEqual(response.status_code, 302)
        self.assertRedirects(
            response=response,
            expected_url=reverse(ContactDetailsView.success_url_name, kwargs={'pk': self.gal.pk})
        )

    def test_required_fields(self, *mocks):
        response = self.client.post(self.url)
        self.assertEqual(response.status_code, 200)
        msg = 'This field is required.'
        self.assertFormError(response, 'form', 'applicant_full_name', msg)
        self.assertFormError(response, 'form', 'applicant_email', msg)
        self.assertFormError(response, 'form', 'applicant_mobile_number', msg)
        self.assertFormError(response, 'form', 'job_title', msg)

    def test_post_data_is_saved(self, *mocks):
        self.client.post(
            self.url,
            data={
                'applicant_full_name': 'A Name',
                'applicant_email': '*****@*****.**',
                'applicant_mobile_number': '07777777777',
                'job_title': 'director'
            }
        )
        mocks[0].assert_called_once_with(
            grant_application_id=str(self.gal.backoffice_grant_application_id),
            applicant_full_name='A Name',
            applicant_email='*****@*****.**',
            applicant_mobile_number='+447777777777',
            job_title='director'
        )

    def test_mobile_must_be_gb_number_international(self, *mocks):
        response = self.client.post(self.url, data={'applicant_mobile_number': '+457777777777'})
        self.assertFormError(
            response, 'form', 'applicant_mobile_number',
            "Enter a valid phone number (e.g. 0121 234 5678) or a number with an international "
            "call prefix."
        )

    def test_mobile_must_be_gb_number_national(self, *mocks):
        response = self.client.post(self.url, data={'applicant_mobile_number': '2025550154'})
        self.assertFormError(
            response, 'form', 'applicant_mobile_number',
            "Enter a valid phone number (e.g. 0121 234 5678) or a number with an international "
            "call prefix."
        )

    def test_get_redirects_to_confirmation_if_application_already_sent_for_review(self, *mocks):
        fake_grant_application = FAKE_GRANT_APPLICATION.copy()
        fake_grant_application['sent_for_review'] = True
        mocks[2].return_value = fake_grant_application
        response = self.client.get(self.url)
        self.assertRedirects(
            response, reverse('grant-applications:confirmation', args=(self.gal.pk,))
        )

    def test_get_redirects_to_ineligible_if_application_is_not_active(self, *mocks):
        fake_grant_application = FAKE_GRANT_APPLICATION.copy()
        fake_grant_application['is_eligible'] = False
        mocks[2].return_value = fake_grant_application
        response = self.client.get(self.url)
        self.assertRedirects(response, reverse('grant-applications:ineligible'))

    def test_post_redirects_to_ineligible_if_application_is_not_active(self, *mocks):
        fake_grant_application = FAKE_GRANT_APPLICATION.copy()
        fake_grant_application['is_eligible'] = False
        mocks[2].return_value = fake_grant_application
        response = self.client.post(self.url)
        self.assertRedirects(response, reverse('grant-applications:ineligible'))

    def test_get_does_not_redirect_to_ineligible_if_review_page_has_been_viewed(self, *mocks):
        fake_grant_application = FAKE_GRANT_APPLICATION.copy()
        fake_grant_application['is_eligible'] = False
        mocks[2].return_value = fake_grant_application

        self.gal.has_viewed_review_page = True
        self.gal.save()

        response = self.client.get(self.url)
        self.assertEqual(response.status_code, 200)
        self.assertTemplateUsed(response, ContactDetailsView.template_name)

    def test_post_redirects_to_review_page_if_application_review_page_has_been_viewed(self, *mocks):
        self.gal.has_viewed_review_page = True
        self.gal.save()
        response = self.client.post(
            self.url,
            data={
                'applicant_full_name': 'A Name',
                'applicant_email': '*****@*****.**',
                'applicant_mobile_number': '+447777777777',
                'job_title': 'director'
            }
        )
        self.assertRedirects(
            response,
            reverse('grant-applications:application-review', args=(self.gal.pk,)),
            fetch_redirect_response=False
        )
 def setUp(self):
     super().setUp()
     self.gal = GrantApplicationLinkFactory()
     self.url = reverse('grant-applications:select-company',
                        args=(self.gal.pk, ))
class TestSelectCompanyView(LogCaptureMixin, BaseTestCase):
    def setUp(self):
        super().setUp()
        self.gal = GrantApplicationLinkFactory()
        self.url = reverse('grant-applications:select-company',
                           args=(self.gal.pk, ))

    def test_get_with_no_search_term_redirects_to_search_company_page(
            self, *mocks):
        response = self.client.get(self.url)
        self.assertEqual(response.status_code, 302)
        self.assertRedirects(
            response,
            reverse('grant-applications:search-company', args=(self.gal.pk, )))

    def test_get_with_empty_search_term_redirects_to_search_company_page(
            self, *mocks):
        response = self.client.get(self.url, data={'search_term': ''})
        self.assertEqual(response.status_code, 302)
        self.assertRedirects(
            response,
            reverse('grant-applications:search-company', args=(self.gal.pk, )))

    def test_get_response_content(self, *mocks):
        response = self.client.get(self.url, data={'search_term': 'company-1'})
        self.assertEqual(response.status_code, 200)
        self.assertTemplateUsed(response, SelectCompanyView.template_name)
        self.assertIn(FAKE_GRANT_APPLICATION['company']['name'],
                      response.content.decode())

    def test_html_number_of_matches(self, *mocks):
        response = self.client.get(self.url, data={'search_term': 'company-1'})
        self.assertEqual(response.status_code, 200)
        html = BeautifulSoup(response.content,
                             'html.parser').find(id='id_matches_text')
        self.assertEqual(html.text, 'We found 1 match')

    def test_html_number_of_matches_pluralised(self, *mocks):
        mocks[0].return_value = [FAKE_SEARCH_COMPANIES[0] for _ in range(3)]
        response = self.client.get(self.url, data={'search_term': 'company-1'})
        self.assertEqual(response.status_code, 200)
        html = BeautifulSoup(response.content,
                             'html.parser').find(id='id_matches_text')
        self.assertEqual(html.text, 'We found 3 matches')

    def test_get_with_primary_name_style_search_term(self, *mocks):
        self.client.get(self.url, data={'search_term': 'company-1'})
        mocks[0].assert_called_once_with(primary_name='company-1')

    def test_get_with_registration_number_style_search_term(self, *mocks):
        self.client.get(self.url, data={'search_term': '01234567'})
        mocks[0].assert_called_once_with(registration_numbers=['01234567'])

    def test_details_not_listed(self, *mocks):
        response = self.client.get(self.url, data={'search_term': 'company-1'})
        self.assertEqual(response.status_code, 200)
        link_html = BeautifulSoup(
            response.content, 'html.parser').find(id='id_details_not_listed')
        self.assertEqual(
            link_html.attrs['href'],
            reverse('grant-applications:manual-company-details',
                    args=(self.gal.pk, )))

    def test_html_when_no_company_found(self, *mocks):
        mocks[0].return_value = []
        response = self.client.get(self.url, data={'search_term': 'company-1'})
        self.assertEqual(response.status_code, 200)
        html = BeautifulSoup(response.content,
                             'html.parser').find(id='id_matches_text')
        self.assertEqual(html.text, 'We found no matching businesses')

    def test_get_on_search_companies_backoffice_service_exception(
            self, *mocks):
        mocks[0].side_effect = BackofficeServiceException
        response = self.client.get(self.url, data={'search_term': 'company-1'})
        self.assertEqual(response.status_code, 200)
        self.assertNotIn(FAKE_GRANT_APPLICATION['company']['name'],
                         response.content.decode())

    def test_post_required_fields(self, *mocks):
        response = self.client.post(self.url)
        self.assertFormError(response, 'form', 'duns_number',
                             self.form_msgs['required'])

    def test_post_form_redirect_path(self, *mocks):
        response = self.client.post(
            self.url,
            data={
                'duns_number': FAKE_GRANT_APPLICATION['company']['duns_number']
            })
        self.assertEqual(response.status_code, 302)
        self.assertRedirects(response=response,
                             expected_url=reverse(
                                 'grant-applications:company-details',
                                 args=(self.gal.pk, )))

    def test_post_creates_backoffice_company(self, m_search_companies,
                                             m_update_grant_application,
                                             m_list_companies,
                                             m_get_grant_application,
                                             m_create_company):
        # mock out that list_companies returns nothing
        # so that create_company gets called to create the company
        m_list_companies.return_value = []
        response = self.client.post(
            self.url,
            data={
                'duns_number': FAKE_GRANT_APPLICATION['company']['duns_number']
            })
        self.assertEqual(response.status_code, 302)
        m_create_company.assert_called_once_with(
            duns_number=str(FAKE_GRANT_APPLICATION['company']['duns_number']),
            registration_number=FAKE_GRANT_APPLICATION['company']
            ['registration_number'],
            name=FAKE_GRANT_APPLICATION['company']['name'])

    def test_post_list_companies_finds_too_many_backoffice_companies(
            self, m_search_companies, m_update_grant_application,
            m_list_companies, m_get_grant_application, m_create_company):
        # mock out that list_companies returns more than 1 companies
        m_list_companies.return_value = [FAKE_COMPANY, FAKE_COMPANY]

        response = self.client.post(
            self.url,
            data={
                'duns_number': FAKE_GRANT_APPLICATION['company']['duns_number']
            })

        # This means there is a problem in the backoffice api
        self.assertFormError(response, 'form', None,
                             self.form_msgs['resubmit'])

        m_create_company.assert_not_called()
        self.log_capture.check_present(('web.grant_applications.services',
                                        'ERROR', 'Too many companies'), )

    def test_post_list_companies_causes_backoffice_service_exception(
            self, *mocks):
        mocks[2].side_effect = BackofficeServiceException
        response = self.client.post(
            self.url,
            data={
                'duns_number': FAKE_GRANT_APPLICATION['company']['duns_number']
            },
            follow=True)
        self.assertFormError(response, 'form', None,
                             self.form_msgs['resubmit'])

    def test_post_updates_backoffice_grant_application_company(
            self, m_search_companies, m_update_grant_application,
            m_list_companies, m_get_grant_application, m_create_company):
        response = self.client.post(
            self.url,
            data={
                'duns_number': FAKE_GRANT_APPLICATION['company']['duns_number']
            })
        self.assertEqual(response.status_code, 302)
        m_search_companies.assert_called_with(
            duns_number=FAKE_GRANT_APPLICATION['company']['duns_number'])
        m_update_grant_application.assert_called_once_with(
            grant_application_id=str(self.gal.backoffice_grant_application_id),
            company=FAKE_COMPANY['id'],
            # Set manual company details to None in case they have previously been set
            manual_company_type=None,
            manual_company_name=None,
            manual_company_address_line_1=None,
            manual_company_address_line_2=None,
            manual_company_address_town=None,
            manual_company_address_county=None,
            manual_company_address_postcode=None,
            manual_time_trading_in_uk=None,
            manual_registration_number=None,
            manual_vat_number=None,
            manual_website=None)

    def test_get_redirects_to_confirmation_if_application_already_sent_for_review(
            self, *mocks):
        fake_grant_application = FAKE_GRANT_APPLICATION.copy()
        fake_grant_application['sent_for_review'] = True
        mocks[3].return_value = fake_grant_application
        response = self.client.get(self.url, data={'search_term': 'hello'})
        self.assertRedirects(
            response,
            reverse('grant-applications:confirmation', args=(self.gal.pk, )))

    def test_get_redirects_to_ineligible_if_application_is_not_active(
            self, *mocks):
        fake_grant_application = FAKE_GRANT_APPLICATION.copy()
        fake_grant_application['is_eligible'] = False
        mocks[3].return_value = fake_grant_application
        response = self.client.get(self.url, data={'search_term': 'hello'})
        self.assertRedirects(response,
                             reverse('grant-applications:ineligible'))

    def test_post_redirects_to_ineligible_if_application_is_not_active(
            self, *mocks):
        fake_grant_application = FAKE_GRANT_APPLICATION.copy()
        fake_grant_application['is_eligible'] = False
        mocks[3].return_value = fake_grant_application
        response = self.client.post(self.url)
        self.assertRedirects(response,
                             reverse('grant-applications:ineligible'))

    def test_get_does_not_redirect_to_ineligible_if_review_page_has_been_viewed(
            self, *mocks):
        fake_grant_application = FAKE_GRANT_APPLICATION.copy()
        fake_grant_application['is_eligible'] = False
        mocks[1].return_value = fake_grant_application

        self.gal.has_viewed_review_page = True
        self.gal.save()

        response = self.client.get(self.url, data={'search_term': 'company-1'})
        self.assertEqual(response.status_code, 200)
        self.assertTemplateUsed(response, SelectCompanyView.template_name)

    def test_post_redirects_to_review_page_if_application_review_page_has_been_viewed(
            self, *mocks):
        self.gal.has_viewed_review_page = True
        self.gal.save()
        response = self.client.post(
            self.url,
            data={
                'duns_number': FAKE_GRANT_APPLICATION['company']['duns_number']
            })
        self.assertRedirects(response,
                             reverse('grant-applications:application-review',
                                     args=(self.gal.pk, )),
                             fetch_redirect_response=False)
Beispiel #14
0
class TestSelectAnEventView(BaseTestCase):
    page_size = SelectAnEventView.events_page_size

    def setUp(self):
        self.gal = GrantApplicationLinkFactory()
        self.url = reverse('grant-applications:select-an-event',
                           args=(self.gal.pk, ))

    def test_get(self, *mocks):
        response = self.client.get(self.url)
        self.assertEqual(response.status_code, 200)
        self.assertTemplateUsed(response, SelectAnEventView.template_name)

    def test_back_url(self, *mocks):
        response = self.client.get(self.url)
        self.assertEqual(response.status_code, 200)
        back_html = BeautifulSoup(response.content,
                                  'html.parser').find(id='id_back_link')
        self.assertEqual(
            back_html.attrs['href'],
            reverse('grant-applications:find-an-event', args=(self.gal.pk, )))

    def test_initial_filters_are_set_to_all(self, *mocks):
        response = self.client.get(self.url)
        soup = BeautifulSoup(response.content, 'html.parser')
        self.assertEqual(response.status_code, 200)
        # Filter by name
        self.assertNotIn('value', soup.find(id='id_filter_by_name').attrs)
        # Filter by start date
        self.assertEqual(
            soup.find(id='id_filter_by_month').find('option',
                                                    selected=True).text, 'All')
        # Filter by country
        self.assertEqual(
            soup.find(id='id_filter_by_country').find('option',
                                                      selected=True).text,
            'All')
        # Filter by sector
        self.assertEqual(
            soup.find(id='id_filter_by_sector').find('option',
                                                     selected=True).text,
            'All')

    def test_get_defaults_to_event_page_1(self, *mocks):
        response = self.client.get(self.url)
        self.assertEqual(response.status_code, 200)
        mocks[0].assert_any_call(page=1, page_size=self.page_size)

    def test_get_with_event_page(self, *mocks):
        response = self.client.get(self.url, data={'page': 2})
        self.assertEqual(response.status_code, 200)
        mocks[0].assert_any_call(page=2, page_size=self.page_size)

    def test_get_request_event_initial_is_backoffice_event_if_exists(
            self, *mocks):
        response = self.client.get(self.url)
        self.assertEqual(response.status_code, 200)
        soup = BeautifulSoup(response.content, 'html.parser')
        selected_event = soup.find(attrs={'class': 'govuk-radios__input'},
                                   checked=True)
        self.assertEqual(selected_event.attrs['value'],
                         FAKE_GRANT_APPLICATION['event']['id'])

    def test_get_on_list_events_backoffice_exception(self, *mocks):
        mocks[0].side_effect = BackofficeServiceException
        response = self.client.get(self.url)
        self.assertEqual(response.status_code, 200)

        soup = BeautifulSoup(response.content, 'html.parser')
        html_elements = soup.find_all(
            id=re.compile(r'^id_no_matching_events_\d'))
        self.assertEqual(len(html_elements), 3)

    @patch.object(BackofficeService, 'get_grant_application')
    def test_initial_when_no_event_is_set(self, *mocks):
        mocks[3].return_value = FAKE_GRANT_APPLICATION.copy()
        mocks[3].return_value['event'] = None

        response = self.client.get(self.url)
        self.assertEqual(response.status_code, 200)

        soup = BeautifulSoup(response.content, 'html.parser')
        all_event_radios = soup.find_all(
            attrs={'class': 'govuk-radios__input'})
        for event_radio in all_event_radios:
            self.assertNotIn('checked', event_radio.attrs)

    def test_post_redirects(self, *mocks):
        response = self.client.post(self.url, data={'event': FAKE_EVENT['id']})
        self.assertEqual(response.status_code, 302)
        self.assertRedirects(response=response,
                             expected_url=reverse(
                                 SelectAnEventView.success_url_name,
                                 args=(self.gal.pk, )))

    def test_get_redirects_to_confirmation_if_application_already_sent_for_review(
            self, *mocks):
        fake_grant_application = FAKE_GRANT_APPLICATION.copy()
        fake_grant_application['sent_for_review'] = True
        mocks[2].return_value = fake_grant_application
        response = self.client.get(self.url)
        self.assertRedirects(
            response,
            reverse('grant-applications:confirmation', args=(self.gal.pk, )))

    def test_get_redirects_to_ineligible_if_application_is_not_active(
            self, *mocks):
        fake_grant_application = FAKE_GRANT_APPLICATION.copy()
        fake_grant_application['is_eligible'] = False
        mocks[2].return_value = fake_grant_application
        response = self.client.get(self.url)
        self.assertRedirects(response,
                             reverse('grant-applications:ineligible'))

    def test_post_redirects_to_ineligible_if_application_is_not_active(
            self, *mocks):
        fake_grant_application = FAKE_GRANT_APPLICATION.copy()
        fake_grant_application['is_eligible'] = False
        mocks[2].return_value = fake_grant_application
        response = self.client.post(self.url)
        self.assertRedirects(response,
                             reverse('grant-applications:ineligible'))

    def test_get_does_not_redirect_to_ineligible_if_review_page_has_been_viewed(
            self, *mocks):
        fake_grant_application = FAKE_GRANT_APPLICATION.copy()
        fake_grant_application['is_eligible'] = False
        mocks[1].return_value = fake_grant_application

        self.gal.has_viewed_review_page = True
        self.gal.save()

        response = self.client.get(self.url)
        self.assertEqual(response.status_code, 200)
        self.assertTemplateUsed(response, SelectAnEventView.template_name)

    def test_post_redirects_to_review_page_if_application_review_page_has_been_viewed(
            self, *mocks):
        self.gal.has_viewed_review_page = True
        self.gal.save()
        response = self.client.post(self.url, data={'event': FAKE_EVENT['id']})
        self.assertRedirects(response,
                             reverse('grant-applications:application-review',
                                     args=(self.gal.pk, )),
                             fetch_redirect_response=False)

    def test_event_is_saved_on_form_continue_button(self, *mocks):
        response = self.client.post(self.url, data={'event': FAKE_EVENT['id']})
        self.assertEqual(response.status_code, 302)
        mocks[1].assert_called_once_with(grant_application_id=str(
            self.gal.backoffice_grant_application_id),
                                         event=FAKE_EVENT['id'])

    def test_filter_by_name(self, *mocks):
        response = self.client.get(self.url, data={'filter_by_name': 'AB'})
        self.assertEqual(response.status_code, 200)
        soup = BeautifulSoup(response.content, 'html.parser')
        self.assertEqual(
            soup.find(id='id_filter_by_name').attrs['value'], 'AB')
        # Use name filter as a search_term to the backoffice api
        mocks[0].assert_any_call(page=1, page_size=self.page_size, search='AB')

    def test_filter_by_month(self, *mocks):
        response = self.client.get(
            self.url, data={'filter_by_month': '2020-12-01:2020-12-31'})
        self.assertEqual(response.status_code, 200)
        soup = BeautifulSoup(response.content, 'html.parser')
        self.assertEqual(
            soup.find(id='id_filter_by_month').find('option',
                                                    selected=True).text,
            'December 2020')
        mocks[0].assert_any_call(page=1,
                                 page_size=self.page_size,
                                 start_date_range_after='2020-12-01',
                                 end_date_range_before='2020-12-31')

    def test_filter_by_country(self, *mocks):
        response = self.client.get(self.url,
                                   data={'filter_by_country': 'Country 1'})
        self.assertEqual(response.status_code, 200)
        soup = BeautifulSoup(response.content, 'html.parser')
        self.assertEqual(
            soup.find(id='id_filter_by_country').find('option',
                                                      selected=True).text,
            FAKE_EVENT['country'])
        mocks[0].assert_any_call(page=1,
                                 page_size=self.page_size,
                                 country='Country 1')

    def test_filter_by_sector(self, *mocks):
        response = self.client.get(self.url,
                                   data={'filter_by_sector': 'Sector 1'})
        self.assertEqual(response.status_code, 200)
        soup = BeautifulSoup(response.content, 'html.parser')
        self.assertEqual(
            soup.find(id='id_filter_by_sector').find('option',
                                                     selected=True).text,
            FAKE_EVENT['sector'])
        mocks[0].assert_any_call(page=1,
                                 page_size=self.page_size,
                                 sector='Sector 1')

    def test_no_matching_events_text_is_shown(self, *mocks):
        mocks[0].side_effect = None
        mocks[0].return_value = []
        response = self.client.get(self.url,
                                   data={'filter_by_name': 'Bla Bla Bla'})
        self.assertEqual(response.status_code, 200)
        soup = BeautifulSoup(response.content, 'html.parser')
        html_elements = soup.find_all(
            id=re.compile(r'^id_no_matching_events_\d'))
        self.assertEqual(len(html_elements), 3)

    def test_event_required_on_form_button_submit(self, *mocks):
        response = self.client.post(self.url)
        self.assertFormError(response, 'form', 'event',
                             self.form_msgs['required'])
class TestEditStateAidView(BaseTestCase):

    def setUp(self):
        self.gal = GrantApplicationLinkFactory()
        self.url = reverse(
            'grant-applications:edit-state-aid',
            kwargs={'pk': self.gal.pk, 'state_aid_pk': FAKE_STATE_AID['id']}
        )

    def test_get(self, *mocks):
        response = self.client.get(self.url)
        self.assertEqual(response.status_code, 200)
        self.assertTemplateUsed(response, EditStateAidView.template_name)

    def test_update_state_aid_backoffice_exception(self, *mocks):
        mocks[3].side_effect = BackofficeServiceException
        response = self.client.post(self.url, data={'amount': 2000})
        self.assertEqual(response.status_code, 200)
        self.assertFormError(response, 'form', None, self.form_msgs['resubmit'])
        mocks[3].assert_called_once_with(state_aid_id=FAKE_STATE_AID['id'], amount=Decimal('2000'))

    def test_edit_amount(self, *mocks):
        response = self.client.post(self.url, data={'amount': 2000})
        self.assertEqual(response.status_code, 302)
        mocks[3].assert_called_once_with(state_aid_id=FAKE_STATE_AID['id'], amount=Decimal('2000'))

    def test_all_fields_optional(self, *mocks):
        response = self.client.post(self.url)
        self.assertRedirects(
            response, reverse('grant_applications:state-aid-summary', args=(self.gal.pk,))
        )

    def test_aid_amount_is_a_number(self, *mocks):
        response = self.client.post(self.url, data={'amount': 'bad-value'})
        self.assertFormError(response, 'form', 'amount', self.form_msgs['number'])

    def test_get_redirects_to_confirmation_if_application_already_sent_for_review(self, *mocks):
        fake_grant_application = FAKE_GRANT_APPLICATION.copy()
        fake_grant_application['sent_for_review'] = True
        mocks[1].return_value = fake_grant_application
        response = self.client.get(self.url)
        self.assertRedirects(
            response, reverse('grant-applications:confirmation', args=(self.gal.pk,))
        )

    def test_get_redirects_to_ineligible_if_application_is_not_active(self, *mocks):
        fake_grant_application = FAKE_GRANT_APPLICATION.copy()
        fake_grant_application['is_eligible'] = False
        mocks[1].return_value = fake_grant_application
        response = self.client.get(self.url)
        self.assertRedirects(response, reverse('grant-applications:ineligible'))

    def test_post_redirects_to_ineligible_if_application_is_not_active(self, *mocks):
        fake_grant_application = FAKE_GRANT_APPLICATION.copy()
        fake_grant_application['is_eligible'] = False
        mocks[1].return_value = fake_grant_application
        response = self.client.post(self.url)
        self.assertRedirects(response, reverse('grant-applications:ineligible'))

    def test_get_does_not_redirect_to_ineligible_if_review_page_has_been_viewed(self, *mocks):
        fake_grant_application = FAKE_GRANT_APPLICATION.copy()
        fake_grant_application['is_eligible'] = False
        mocks[1].return_value = fake_grant_application

        self.gal.has_viewed_review_page = True
        self.gal.save()

        response = self.client.get(self.url)
        self.assertEqual(response.status_code, 200)
        self.assertTemplateUsed(response, EditStateAidView.template_name)

    def test_post_redirects_to_state_aid_summary_page_if_review_page_has_been_viewed(self, *mocks):
        self.gal.has_viewed_review_page = True
        self.gal.save()
        response = self.client.post(self.url, data={'amount': 2000})
        self.assertRedirects(
            response,
            reverse('grant-applications:state-aid-summary', args=(self.gal.pk,)),
            fetch_redirect_response=False
        )
class TestCompanyTradingDetailsView(BaseTestCase):
    @classmethod
    def setUpClass(cls):
        super().setUpClass()
        cls.currency_fields = [
            'previous_years_turnover_1',
            'previous_years_turnover_2',
            'previous_years_turnover_3',
            'previous_years_export_turnover_1',
            'previous_years_export_turnover_2',
            'previous_years_export_turnover_3',
        ]

    def setUp(self):
        self.gal = GrantApplicationLinkFactory()
        self.url = reverse('grant-applications:company-trading-details',
                           kwargs={'pk': self.gal.pk})

    def test_get(self, *mocks):
        response = self.client.get(self.url)
        self.assertEqual(response.status_code, 200)
        self.assertTemplateUsed(response,
                                CompanyTradingDetailsView.template_name)

    def test_sector_choices_come_from_sector_list(self, *mocks):
        response = self.client.get(self.url)
        self.assertEqual(response.status_code, 200)

        soup = BeautifulSoup(response.content, 'html.parser')
        options = soup.find_all('option')
        self.assertEqual(options[1].text, FAKE_SECTOR['full_name'])

    def test_post(self, *mocks):
        response = self.client.post(self.url,
                                    data={
                                        'previous_years_turnover_1':
                                        '1.23',
                                        'previous_years_turnover_2':
                                        '1.23',
                                        'previous_years_turnover_3':
                                        '1.23',
                                        'previous_years_export_turnover_1':
                                        '1.23',
                                        'previous_years_export_turnover_2':
                                        '1.23',
                                        'previous_years_export_turnover_3':
                                        '1.23',
                                        'sector':
                                        FAKE_SECTOR['id'],
                                        'other_business_names':
                                        'A name',
                                        'products_and_services_description':
                                        'A description',
                                        'products_and_services_competitors':
                                        'A description'
                                    })
        self.assertEqual(response.status_code, 302)
        mocks[0].assert_called_once_with(
            grant_application_id=str(self.gal.backoffice_grant_application_id),
            previous_years_turnover_1=Decimal('1.23'),
            previous_years_turnover_2=Decimal('1.23'),
            previous_years_turnover_3=Decimal('1.23'),
            previous_years_export_turnover_1=Decimal('1.23'),
            previous_years_export_turnover_2=Decimal('1.23'),
            previous_years_export_turnover_3=Decimal('1.23'),
            sector=FAKE_SECTOR['id'],
            other_business_names='A name',
            products_and_services_description='A description',
            products_and_services_competitors='A description')

    def test_other_business_names_not_required(self, *mocks):
        response = self.client.post(self.url,
                                    data={
                                        'previous_years_turnover_1':
                                        '1.23',
                                        'previous_years_turnover_2':
                                        '1.23',
                                        'previous_years_turnover_3':
                                        '0',
                                        'previous_years_export_turnover_1':
                                        '1.23',
                                        'previous_years_export_turnover_2':
                                        '1.23',
                                        'previous_years_export_turnover_3':
                                        '0',
                                        'sector':
                                        FAKE_SECTOR['id'],
                                        'products_and_services_description':
                                        'A description',
                                        'products_and_services_competitors':
                                        'A description'
                                    })
        self.assertEqual(response.status_code, 302)
        mocks[0].assert_called_once_with(
            grant_application_id=str(self.gal.backoffice_grant_application_id),
            previous_years_turnover_1=Decimal('1.23'),
            previous_years_turnover_2=Decimal('1.23'),
            previous_years_turnover_3=Decimal('0'),
            previous_years_export_turnover_1=Decimal('1.23'),
            previous_years_export_turnover_2=Decimal('1.23'),
            previous_years_export_turnover_3=Decimal('0'),
            sector=FAKE_SECTOR['id'],
            # We expect field to be explicitly set to None to overwrite any previously entered value
            other_business_names=None,
            products_and_services_description='A description',
            products_and_services_competitors='A description')

    def test_initial_form_data_from_grant_application_object(self, *mocks):
        response = self.client.get(self.url)
        self.assertEqual(response.status_code, 200)

        soup = BeautifulSoup(response.content, 'html.parser')
        self.assertEqual(
            soup.find(id='id_sector').find('option',
                                           selected=True).attrs['value'],
            FAKE_GRANT_APPLICATION['sector']['id'])
        for field in CompanyTradingDetailsForm.Meta.fields:
            if field == 'sector':
                continue
            html = soup.find(id=f'id_{field}')
            expected = html.attrs.get('value') or html.text
            self.assertEqual(expected, str(FAKE_GRANT_APPLICATION[field]))

    def test_validation_of_currency_fields_negative(self, *mocks):
        value = '-1'
        response = self.client.post(
            self.url,
            data={
                'sector': FAKE_SECTOR['id'],
                'products_and_services_description': 'A description',
                'products_and_services_competitors': 'A description',
                **{k: value
                   for k in self.currency_fields}
            })
        self.assertEqual(response.status_code, 200)
        for field in self.currency_fields:
            self.assertFormError(response, 'form', field,
                                 self.form_msgs['positive'])

    def test_validation_of_currency_fields_too_many_decimal_places(
            self, *mocks):
        value = '1.234'
        response = self.client.post(
            self.url,
            data={
                'sector': FAKE_SECTOR['id'],
                'products_and_services_description': 'A description',
                'products_and_services_competitors': 'A description',
                **{k: value
                   for k in self.currency_fields}
            })
        self.assertEqual(response.status_code, 200)
        for field in self.currency_fields:
            self.assertFormError(response, 'form', field,
                                 self.form_msgs['2dp'])

    def test_redirect_to_confirmation_page_if_application_already_sent_for_review(
            self, *mocks):
        fake_grant_application = FAKE_GRANT_APPLICATION.copy()
        fake_grant_application['sent_for_review'] = True
        mocks[2].return_value = fake_grant_application
        response = self.client.get(self.url)
        self.assertEqual(response.status_code, 302)
        self.assertRedirects(
            response,
            reverse('grant-applications:confirmation', args=(self.gal.pk, )))

    def test_get_redirects_to_confirmation_if_application_already_sent_for_review(
            self, *mocks):
        fake_grant_application = FAKE_GRANT_APPLICATION.copy()
        fake_grant_application['sent_for_review'] = True
        mocks[2].return_value = fake_grant_application
        response = self.client.get(self.url)
        self.assertRedirects(
            response,
            reverse('grant-applications:confirmation', args=(self.gal.pk, )))

    def test_get_redirects_to_ineligible_if_application_is_not_active(
            self, *mocks):
        fake_grant_application = FAKE_GRANT_APPLICATION.copy()
        fake_grant_application['is_eligible'] = False
        mocks[2].return_value = fake_grant_application
        response = self.client.get(self.url)
        self.assertRedirects(response,
                             reverse('grant-applications:ineligible'))

    def test_post_redirects_to_ineligible_if_application_is_not_active(
            self, *mocks):
        fake_grant_application = FAKE_GRANT_APPLICATION.copy()
        fake_grant_application['is_eligible'] = False
        mocks[2].return_value = fake_grant_application
        response = self.client.post(self.url)
        self.assertRedirects(response,
                             reverse('grant-applications:ineligible'))

    def test_get_does_not_redirect_to_ineligible_if_review_page_has_been_viewed(
            self, *mocks):
        fake_grant_application = FAKE_GRANT_APPLICATION.copy()
        fake_grant_application['is_eligible'] = False
        mocks[2].return_value = fake_grant_application

        self.gal.has_viewed_review_page = True
        self.gal.save()

        response = self.client.get(self.url)
        self.assertEqual(response.status_code, 200)
        self.assertTemplateUsed(response,
                                CompanyTradingDetailsView.template_name)

    def test_post_redirects_to_review_page_if_application_review_page_has_been_viewed(
            self, *mocks):
        self.gal.has_viewed_review_page = True
        self.gal.save()
        response = self.client.post(self.url,
                                    data={
                                        'previous_years_turnover_1':
                                        '1.23',
                                        'previous_years_turnover_2':
                                        '1.23',
                                        'previous_years_turnover_3':
                                        '0',
                                        'previous_years_export_turnover_1':
                                        '1.23',
                                        'previous_years_export_turnover_2':
                                        '1.23',
                                        'previous_years_export_turnover_3':
                                        '0',
                                        'sector':
                                        FAKE_SECTOR['id'],
                                        'products_and_services_description':
                                        'A description',
                                        'products_and_services_competitors':
                                        'A description'
                                    })
        self.assertRedirects(response,
                             reverse('grant-applications:application-review',
                                     args=(self.gal.pk, )),
                             fetch_redirect_response=False)
class TestDuplicateStateAidView(BaseTestCase):

    def setUp(self):
        self.gal = GrantApplicationLinkFactory()
        self.url = reverse(
            'grant-applications:duplicate-state-aid',
            kwargs={'pk': self.gal.pk, 'state_aid_pk': FAKE_STATE_AID['id']}
        )

    def test_duplicate(self, *mocks):
        response = self.client.get(self.url)
        self.assertRedirects(
            response,
            reverse('grant-applications:state-aid-summary', args=(self.gal.pk,)),
            fetch_redirect_response=False
        )
        mocks[1].assert_called_once_with(
            grant_application=self.gal.backoffice_grant_application_id,
            authority=FAKE_STATE_AID['authority'],
            amount=FAKE_STATE_AID['amount'],
            description=FAKE_STATE_AID['description'],
            date_received=FAKE_STATE_AID['date_received']
        )

    def test_on_get_backoffice_exception_redirect_still_happens(self, *mocks):
        mocks[2].side_effect = BackofficeServiceException
        response = self.client.get(self.url)
        self.assertRedirects(
            response,
            reverse('grant-applications:state-aid-summary', args=(self.gal.pk,)),
            fetch_redirect_response=False
        )
        mocks[2].assert_called_once_with(state_aid_id=FAKE_STATE_AID['id'])

    def test_on_create_backoffice_exception_redirect_still_happens(self, *mocks):
        mocks[1].side_effect = BackofficeServiceException
        response = self.client.get(self.url)
        self.assertRedirects(
            response,
            reverse('grant-applications:state-aid-summary', args=(self.gal.pk,)),
            fetch_redirect_response=False
        )
        mocks[1].assert_called_once_with(
            grant_application=self.gal.backoffice_grant_application_id,
            authority=FAKE_STATE_AID['authority'],
            amount=FAKE_STATE_AID['amount'],
            description=FAKE_STATE_AID['description'],
            date_received=FAKE_STATE_AID['date_received']
        )

    def test_get_redirects_to_confirmation_if_application_already_sent_for_review(self, *mocks):
        fake_grant_application = FAKE_GRANT_APPLICATION.copy()
        fake_grant_application['sent_for_review'] = True
        mocks[0].return_value = fake_grant_application
        response = self.client.get(self.url)
        self.assertRedirects(
            response, reverse('grant-applications:confirmation', args=(self.gal.pk,))
        )

    def test_get_redirects_to_ineligible_if_application_is_not_active(self, *mocks):
        fake_grant_application = FAKE_GRANT_APPLICATION.copy()
        fake_grant_application['is_eligible'] = False
        mocks[0].return_value = fake_grant_application
        response = self.client.get(self.url)
        self.assertRedirects(response, reverse('grant-applications:ineligible'))

    def test_post_redirects_to_ineligible_if_application_is_not_active(self, *mocks):
        fake_grant_application = FAKE_GRANT_APPLICATION.copy()
        fake_grant_application['is_eligible'] = False
        mocks[0].return_value = fake_grant_application
        response = self.client.post(self.url)
        self.assertRedirects(response, reverse('grant-applications:ineligible'))

    def test_get_does_not_redirect_to_ineligible_if_review_page_has_been_viewed(self, *mocks):
        fake_grant_application = FAKE_GRANT_APPLICATION.copy()
        fake_grant_application['is_eligible'] = False
        mocks[1].return_value = fake_grant_application

        self.gal.has_viewed_review_page = True
        self.gal.save()

        response = self.client.get(self.url)
        self.assertRedirects(
            response,
            reverse('grant-applications:state-aid-summary', args=(self.gal.pk,)),
            fetch_redirect_response=False
        )

    def test_post_redirects_to_review_page_if_application_review_page_has_been_viewed(self, *mocks):
        self.gal.has_viewed_review_page = True
        self.gal.save()
        response = self.client.get(self.url)
        self.assertRedirects(
            response,
            reverse('grant-applications:state-aid-summary', args=(self.gal.pk,)),
            fetch_redirect_response=False
        )
Beispiel #18
0
class TestManualCompanyDetailsView(BaseTestCase):
    def setUp(self):
        super().setUp()
        self.gal = GrantApplicationLinkFactory()
        self.url = reverse('grant-applications:manual-company-details',
                           args=(self.gal.pk, ))

    def test_get_template(self, *mocks):
        response = self.client.get(self.url)
        self.assertEqual(response.status_code, 200)
        self.assertTemplateUsed(response,
                                ManualCompanyDetailsView.template_name)

    def test_post(self, *mocks):
        response = self.client.post(
            self.url,
            data={
                'manual_company_type':
                ManualCompanyDetailsForm.CompanyType.LIMITED_COMPANY,
                'manual_company_name':
                'A Name',
                'manual_company_address_line_1':
                'Line 1',
                'manual_company_address_line_2':
                'Line 2',
                'manual_company_address_town':
                'Town 1',
                'manual_company_address_county':
                'County 1',
                'manual_company_address_postcode':
                'ZZ1 8ZZ',
                'manual_time_trading_in_uk':
                ManualCompanyDetailsForm.TimeTradingInUk.TWO_TO_FIVE_YEARS,
                'manual_registration_number':
                '10000000',
                'manual_vat_number':
                '123456789',
                'manual_website':
                'https://www.test.com'
            })
        self.assertRedirects(response=response,
                             expected_url=reverse(
                                 'grant-applications:company-details',
                                 args=(self.gal.pk, )))
        mocks[0].assert_called_once_with(
            grant_application_id=str(self.gal.backoffice_grant_application_id),
            manual_company_type=ManualCompanyDetailsForm.CompanyType.
            LIMITED_COMPANY.value,
            manual_company_name='A Name',
            manual_company_address_line_1='Line 1',
            manual_company_address_line_2='Line 2',
            manual_company_address_town='Town 1',
            manual_company_address_county='County 1',
            manual_company_address_postcode='ZZ1 8ZZ',
            manual_time_trading_in_uk=ManualCompanyDetailsForm.TimeTradingInUk.
            TWO_TO_FIVE_YEARS,
            manual_registration_number='10000000',
            manual_vat_number='123456789',
            manual_website='https://www.test.com',
            company=None)

    def test_required_fields(self, *mocks):
        response = self.client.post(self.url)
        msg = self.form_msgs['required']
        self.assertFormError(response, 'form', 'manual_company_type', msg)
        self.assertFormError(response, 'form', 'manual_company_name', msg)
        self.assertFormError(response, 'form', 'manual_company_address_line_1',
                             msg)
        self.assertFormError(response, 'form', 'manual_company_address_town',
                             msg)
        self.assertFormError(response, 'form', 'manual_company_address_county',
                             msg)
        self.assertFormError(response, 'form',
                             'manual_company_address_postcode', msg)
        self.assertFormError(response, 'form', 'manual_time_trading_in_uk',
                             msg)

    def test_optional_fields(self, *mocks):
        response = self.client.post(
            self.url,
            data={
                'manual_company_type':
                ManualCompanyDetailsForm.CompanyType.LIMITED_COMPANY,
                'manual_company_name':
                'A Name',
                'manual_company_address_line_1':
                'Line 1',
                'manual_company_address_line_2':
                'Line 2',
                'manual_company_address_town':
                'Town 1',
                'manual_company_address_county':
                'County 1',
                'manual_company_address_postcode':
                'ZZ1 8ZZ',
                'manual_time_trading_in_uk':
                ManualCompanyDetailsForm.TimeTradingInUk.TWO_TO_FIVE_YEARS,
            })
        self.assertRedirects(response=response,
                             expected_url=reverse(
                                 'grant-applications:company-details',
                                 args=(self.gal.pk, )))
        mocks[0].assert_called_once_with(
            grant_application_id=str(self.gal.backoffice_grant_application_id),
            manual_company_type=ManualCompanyDetailsForm.CompanyType.
            LIMITED_COMPANY.value,
            manual_company_name='A Name',
            manual_company_address_line_1='Line 1',
            manual_company_address_line_2='Line 2',
            manual_company_address_town='Town 1',
            manual_company_address_county='County 1',
            manual_company_address_postcode='ZZ1 8ZZ',
            manual_time_trading_in_uk=ManualCompanyDetailsForm.TimeTradingInUk.
            TWO_TO_FIVE_YEARS,
            manual_registration_number=None,
            manual_vat_number=None,
            manual_website=None,
            company=None)

    def test_get_redirects_to_confirmation_if_application_already_sent_for_review(
            self, *mocks):
        fake_grant_application = FAKE_GRANT_APPLICATION.copy()
        fake_grant_application['sent_for_review'] = True
        mocks[1].return_value = fake_grant_application
        response = self.client.get(self.url)
        self.assertRedirects(
            response,
            reverse('grant-applications:confirmation', args=(self.gal.pk, )))

    def test_get_redirects_to_ineligible_if_application_is_not_active(
            self, *mocks):
        fake_grant_application = FAKE_GRANT_APPLICATION.copy()
        fake_grant_application['is_eligible'] = False
        mocks[1].return_value = fake_grant_application
        response = self.client.get(self.url)
        self.assertRedirects(response,
                             reverse('grant-applications:ineligible'))

    def test_post_redirects_to_ineligible_if_application_is_not_active(
            self, *mocks):
        fake_grant_application = FAKE_GRANT_APPLICATION.copy()
        fake_grant_application['is_eligible'] = False
        mocks[1].return_value = fake_grant_application
        response = self.client.post(self.url)
        self.assertRedirects(response,
                             reverse('grant-applications:ineligible'))

    def test_get_does_not_redirect_to_ineligible_if_review_page_has_been_viewed(
            self, *mocks):
        fake_grant_application = FAKE_GRANT_APPLICATION.copy()
        fake_grant_application['is_eligible'] = False
        mocks[1].return_value = fake_grant_application

        self.gal.has_viewed_review_page = True
        self.gal.save()

        response = self.client.get(self.url)
        self.assertEqual(response.status_code, 200)
        self.assertTemplateUsed(response,
                                ManualCompanyDetailsView.template_name)

    def test_post_redirects_to_review_page_if_application_review_page_has_been_viewed(
            self, *mocks):
        self.gal.has_viewed_review_page = True
        self.gal.save()
        response = self.client.post(
            self.url,
            data={
                'manual_company_type':
                ManualCompanyDetailsForm.CompanyType.LIMITED_COMPANY,
                'manual_company_name':
                'A Name',
                'manual_company_address_line_1':
                'Line 1',
                'manual_company_address_line_2':
                'Line 2',
                'manual_company_address_town':
                'Town 1',
                'manual_company_address_county':
                'County 1',
                'manual_company_address_postcode':
                'ZZ1 8ZZ',
                'manual_time_trading_in_uk':
                ManualCompanyDetailsForm.TimeTradingInUk.TWO_TO_FIVE_YEARS,
                'manual_registration_number':
                '10000000',
                'manual_vat_number':
                '123456789',
                'manual_website':
                'https://www.test.com'
            })
        self.assertRedirects(response,
                             reverse('grant-applications:application-review',
                                     args=(self.gal.pk, )),
                             fetch_redirect_response=False)
 def setUp(self):
     self.gal = GrantApplicationLinkFactory()
     self.url = reverse(
         'grant-applications:duplicate-state-aid',
         kwargs={'pk': self.gal.pk, 'state_aid_pk': FAKE_STATE_AID['id']}
     )
Beispiel #20
0
 def setUpClass(cls):
     super().setUpClass()
     cls.gal = GrantApplicationLinkFactory()
     cls.url = reverse('grant-applications:search-company',
                       args=(cls.gal.pk, ))
Beispiel #21
0
class TestFindAnEventView(BaseTestCase):
    def setUp(self):
        self.gal = GrantApplicationLinkFactory()
        self.url = reverse('grant-applications:find-an-event',
                           args=(self.gal.pk, ))

    def test_get(self, *mocks):
        response = self.client.get(self.url)
        self.assertEqual(response.status_code, 200)
        self.assertTemplateUsed(response, FindAnEventView.template_name)

    def test_back_url(self, *mocks):
        response = self.client.get(self.url)
        self.assertEqual(response.status_code, 200)
        back_html = BeautifulSoup(response.content,
                                  'html.parser').find(id='id_back_link')
        self.assertEqual(
            back_html.attrs['href'],
            reverse('grant-applications:previous-applications',
                    args=(self.gal.pk, )))

    def test_initial_filters_are_set_to_all(self, *mocks):
        response = self.client.get(self.url)
        soup = BeautifulSoup(response.content, 'html.parser')
        self.assertEqual(response.status_code, 200)
        # Filter by name
        self.assertNotIn('value', soup.find(id='id_filter_by_name').attrs)
        # Filter by start date
        self.assertEqual(
            soup.find(id='id_filter_by_month').find('option',
                                                    selected=True).text, 'All')
        # Filter by country
        self.assertEqual(
            soup.find(id='id_filter_by_country').find('option',
                                                      selected=True).text,
            'All')
        # Filter by sector
        self.assertEqual(
            soup.find(id='id_filter_by_sector').find('option',
                                                     selected=True).text,
            'All')

    def test_get_redirects_to_confirmation_if_application_already_sent_for_review(
            self, *mocks):
        fake_grant_application = FAKE_GRANT_APPLICATION.copy()
        fake_grant_application['sent_for_review'] = True
        mocks[2].return_value = fake_grant_application
        response = self.client.get(self.url)
        self.assertRedirects(
            response,
            reverse('grant-applications:confirmation', args=(self.gal.pk, )))

    def test_get_redirects_to_ineligible_if_application_is_not_active(
            self, *mocks):
        fake_grant_application = FAKE_GRANT_APPLICATION.copy()
        fake_grant_application['is_eligible'] = False
        mocks[2].return_value = fake_grant_application
        response = self.client.get(self.url)
        self.assertRedirects(response,
                             reverse('grant-applications:ineligible'))

    def test_post_redirects_to_ineligible_if_application_is_not_active(
            self, *mocks):
        fake_grant_application = FAKE_GRANT_APPLICATION.copy()
        fake_grant_application['is_eligible'] = False
        mocks[2].return_value = fake_grant_application
        response = self.client.post(self.url)
        self.assertRedirects(response,
                             reverse('grant-applications:ineligible'))

    def test_get_does_not_redirect_to_ineligible_if_review_page_has_been_viewed(
            self, *mocks):
        fake_grant_application = FAKE_GRANT_APPLICATION.copy()
        fake_grant_application['is_eligible'] = False
        mocks[2].return_value = fake_grant_application

        self.gal.has_viewed_review_page = True
        self.gal.save()

        response = self.client.get(self.url)
        self.assertEqual(response.status_code, 200)
        self.assertTemplateUsed(response, FindAnEventView.template_name)

    def test_post_redirects_to_event_page_if_application_review_page_has_been_viewed(
            self, *mocks):
        self.gal.has_viewed_review_page = True
        self.gal.save()
        response = self.client.post(self.url)
        self.assertRedirects(response,
                             reverse('grant-applications:select-an-event',
                                     args=(self.gal.pk, )),
                             fetch_redirect_response=False)

    def test_error_on_bad_query_param(self, *mocks):
        response = self.client.post(self.url,
                                    data={'filter_by_month': 'bad-value'})
        self.assertFormError(
            response, 'form', 'filter_by_month',
            self.form_msgs['invalid-choice'].format('bad-value'))

    def test_query_params_sent_on_redirect(self, *mocks):
        params = {
            'filter_by_name': 'Name 1',
            'filter_by_month': '2020-12-01:2020-12-31',
            'filter_by_country': 'Country 1',
            'filter_by_sector': 'Sector 1'
        }
        response = self.client.post(self.url, data=params)
        self.assertEqual(response.status_code, 302)
        self.assertRedirects(
            response=response,
            expected_url=reverse('grant_applications:select-an-event',
                                 args=(self.gal.pk, )) +
            f'?{urlencode(params)}')
        parsed_url = urlparse(response.url)
        for k, v in parse_qs(parsed_url.query).items():
            self.assertEqual(params.get(k), v[0])

    def test_redirect_query_params_populate_redirect_form(self, *mocks):
        response = self.client.post(self.url,
                                    follow=True,
                                    data={
                                        'filter_by_name': 'Name 1',
                                        'filter_by_month':
                                        '2020-12-01:2020-12-31',
                                        'filter_by_country': 'Country 1',
                                        'filter_by_sector': 'Sector 1'
                                    })
        self.assertEqual(response.status_code, 200)
        soup = BeautifulSoup(response.content, 'html.parser')
        # Filter by name
        self.assertEqual(
            soup.find(id='id_filter_by_name').attrs['value'], 'Name 1')
        # Filter by start date
        self.assertEqual(
            soup.find(id='id_filter_by_month').find('option',
                                                    selected=True).text,
            'December 2020')
        # Filter by country
        self.assertEqual(
            soup.find(id='id_filter_by_country').find('option',
                                                      selected=True).text,
            'Country 1')
        # Filter by sector
        self.assertEqual(
            soup.find(id='id_filter_by_sector').find('option',
                                                     selected=True).text,
            'Sector 1')

    def test_get_future_aggregate_trade_events_only(self, *mocks):
        response = self.client.get(self.url)
        mocks[3].assert_called_once_with(start_date_from=timezone.now().date())
        self.assertEqual(response.context_data['total_trade_events'],
                         FAKE_TRADE_EVENT_AGGREGATES['total_trade_events'])
        self.assertEqual(
            response.context_data['trade_event_total_months'],
            len(FAKE_TRADE_EVENT_AGGREGATES['trade_event_months']))
 def setUp(self):
     self.gal = GrantApplicationLinkFactory()
     self.url = reverse('grant-applications:event-commitment',
                        args=(self.gal.pk, ))
class TestExportDetailsView(BaseTestCase):
    def setUp(self):
        self.gal = GrantApplicationLinkFactory()
        self.url = reverse('grant-applications:export-details',
                           kwargs={'pk': self.gal.pk})

    def test_get(self, *mocks):
        response = self.client.get(self.url)
        self.assertEqual(response.status_code, 200)
        self.assertTemplateUsed(response, ExportDetailsView.template_name)

    def test_post(self, *mocks):
        response = self.client.post(self.url,
                                    data={
                                        'has_exported_in_last_12_months':
                                        True,
                                        'export_regions':
                                        ['africa', 'north america'],
                                        'markets_intending_on_exporting_to':
                                        ['existing', 'new'],
                                        'is_in_contact_with_dit_trade_advisor':
                                        True,
                                        'ita_name':
                                        'A Person',
                                        'ita_email':
                                        '*****@*****.**',
                                        'ita_mobile_number':
                                        '07777777777',
                                        'export_experience_description':
                                        'A description',
                                        'export_strategy':
                                        'A strategy'
                                    })
        self.assertEqual(response.status_code, 302)
        mocks[0].assert_called_once_with(
            grant_application_id=str(self.gal.backoffice_grant_application_id),
            has_exported_in_last_12_months=True,
            export_regions=['africa', 'north america'],
            markets_intending_on_exporting_to=['existing', 'new'],
            is_in_contact_with_dit_trade_advisor=True,
            ita_name='A Person',
            ita_email='*****@*****.**',
            ita_mobile_number='+447777777777',
            export_experience_description='A description',
            export_strategy='A strategy')

    def test_required_fields(self, *mocks):
        response = self.client.post(self.url)
        msg = self.form_msgs['required']
        self.assertEqual(response.status_code, 200)
        self.assertFormError(response, 'form',
                             'has_exported_in_last_12_months', msg)
        self.assertFormError(response, 'form', 'export_regions', msg)
        self.assertFormError(response, 'form',
                             'markets_intending_on_exporting_to', msg)
        self.assertFormError(response, 'form',
                             'is_in_contact_with_dit_trade_advisor', msg)
        self.assertFormError(response, 'form', 'export_experience_description',
                             msg)
        self.assertFormError(response, 'form', 'export_strategy', msg)

    def test_conditionally_required_field_errors(self, *mocks):
        response = self.client.post(
            self.url, data={'is_in_contact_with_dit_trade_advisor': True})
        msg = self.form_msgs['required']
        self.assertEqual(response.status_code, 200)
        self.assertFormError(response, 'form', 'ita_name', msg)
        self.assertFormError(response, 'form', 'ita_email', msg)
        self.assertFormError(response, 'form', 'ita_mobile_number', msg)

    def test_conditionally_optional_fields_not_present(self, *mocks):
        response = self.client.post(self.url,
                                    data={
                                        'has_exported_in_last_12_months':
                                        True,
                                        'export_regions':
                                        ['africa', 'north america'],
                                        'markets_intending_on_exporting_to':
                                        ['existing', 'new'],
                                        'is_in_contact_with_dit_trade_advisor':
                                        False,
                                        'export_experience_description':
                                        'A description',
                                        'export_strategy':
                                        'A strategy'
                                    })
        mocks[0].assert_called_once_with(
            grant_application_id=str(self.gal.backoffice_grant_application_id),
            has_exported_in_last_12_months=True,
            export_regions=['africa', 'north america'],
            markets_intending_on_exporting_to=['existing', 'new'],
            is_in_contact_with_dit_trade_advisor=False,
            export_experience_description='A description',
            export_strategy='A strategy',
            # Optional fields all explicitly set to None to overwrite any previously set value
            ita_name=None,
            ita_email=None,
            ita_mobile_number=None,
        )
        self.assertRedirects(response,
                             reverse('grant-applications:trade-event-details',
                                     args=(self.gal.pk, )),
                             fetch_redirect_response=False)

    def test_conditionally_optional_fields_present(self, *mocks):
        response = self.client.post(self.url,
                                    data={
                                        'has_exported_in_last_12_months':
                                        True,
                                        'export_regions':
                                        ['africa', 'north america'],
                                        'markets_intending_on_exporting_to':
                                        ['existing', 'new'],
                                        'is_in_contact_with_dit_trade_advisor':
                                        False,
                                        'ita_name':
                                        'A Person',
                                        'ita_email':
                                        '*****@*****.**',
                                        'ita_mobile_number':
                                        '07777777777',
                                        'export_experience_description':
                                        'A description',
                                        'export_strategy':
                                        'A strategy'
                                    })
        mocks[0].assert_called_once_with(
            grant_application_id=str(self.gal.backoffice_grant_application_id),
            has_exported_in_last_12_months=True,
            export_regions=['africa', 'north america'],
            markets_intending_on_exporting_to=['existing', 'new'],
            is_in_contact_with_dit_trade_advisor=False,
            export_experience_description='A description',
            export_strategy='A strategy',
            # Optional fields all explicitly set to None to overwrite any previously set value
            ita_name=None,
            ita_email=None,
            ita_mobile_number=None,
        )
        self.assertRedirects(response,
                             reverse('grant-applications:trade-event-details',
                                     args=(self.gal.pk, )),
                             fetch_redirect_response=False)

    def test_multiple_choice_fields_mixed_valid_invalid_choices(self, *mocks):
        response = self.client.post(self.url,
                                    data={
                                        'export_regions':
                                        ['north america', 'bad region'],
                                    })
        self.assertEqual(response.status_code, 200)
        self.assertFormError(
            response, 'form', 'export_regions',
            self.form_msgs['invalid-choice'].format('bad region'))

    def test_get_redirects_to_confirmation_if_application_already_sent_for_review(
            self, *mocks):
        fake_grant_application = FAKE_GRANT_APPLICATION.copy()
        fake_grant_application['sent_for_review'] = True
        mocks[1].return_value = fake_grant_application
        response = self.client.get(self.url)
        self.assertRedirects(
            response,
            reverse('grant-applications:confirmation', args=(self.gal.pk, )))

    def test_get_redirects_to_ineligible_if_application_is_not_active(
            self, *mocks):
        fake_grant_application = FAKE_GRANT_APPLICATION.copy()
        fake_grant_application['is_eligible'] = False
        mocks[1].return_value = fake_grant_application
        response = self.client.get(self.url)
        self.assertRedirects(response,
                             reverse('grant-applications:ineligible'))

    def test_post_redirects_to_ineligible_if_application_is_not_active(
            self, *mocks):
        fake_grant_application = FAKE_GRANT_APPLICATION.copy()
        fake_grant_application['is_eligible'] = False
        mocks[1].return_value = fake_grant_application
        response = self.client.post(self.url)
        self.assertRedirects(response,
                             reverse('grant-applications:ineligible'))

    def test_get_does_not_redirect_to_ineligible_if_review_page_has_been_viewed(
            self, *mocks):
        fake_grant_application = FAKE_GRANT_APPLICATION.copy()
        fake_grant_application['is_eligible'] = False
        mocks[1].return_value = fake_grant_application

        self.gal.has_viewed_review_page = True
        self.gal.save()

        response = self.client.get(self.url)
        self.assertEqual(response.status_code, 200)
        self.assertTemplateUsed(response, ExportDetailsView.template_name)

    def test_post_redirects_to_review_page_if_application_review_page_has_been_viewed(
            self, *mocks):
        self.gal.has_viewed_review_page = True
        self.gal.save()
        response = self.client.post(self.url,
                                    data={
                                        'has_exported_in_last_12_months':
                                        True,
                                        'export_regions':
                                        ['africa', 'north america'],
                                        'markets_intending_on_exporting_to':
                                        ['existing', 'new'],
                                        'is_in_contact_with_dit_trade_advisor':
                                        False,
                                        'export_experience_description':
                                        'A description',
                                        'export_strategy':
                                        'A strategy'
                                    })
        self.assertRedirects(response,
                             reverse('grant-applications:application-review',
                                     args=(self.gal.pk, )),
                             fetch_redirect_response=False)
Beispiel #24
0
 def setUp(self):
     self.gal = GrantApplicationLinkFactory(
         backoffice_grant_application_id=FAKE_GRANT_APPLICATION['id']
     )
     self.url = reverse('grant-applications:previous-applications', args=(self.gal.pk,))
class TestTradeEventDetailsView(BaseTestCase):
    def setUp(self):
        self.gal = GrantApplicationLinkFactory()
        self.url = reverse('grant-applications:trade-event-details',
                           kwargs={'pk': self.gal.pk})

    def test_get(self, *mocks):
        response = self.client.get(self.url)
        self.assertEqual(response.status_code, 200)
        self.assertTemplateUsed(response, TradeEventDetailsView.template_name)

    def test_back_url_export_details(self, *mocks):
        fake_grant_application = FAKE_GRANT_APPLICATION.copy()
        fake_grant_application['has_exported_before'] = True
        mocks[1].return_value = fake_grant_application

        response = self.client.get(self.url)

        self.assertEqual(response.status_code, 200)
        back_html = BeautifulSoup(response.content,
                                  'html.parser').find(id='id_back_link')
        self.assertEqual(
            back_html.attrs['href'],
            reverse('grant-applications:export-details', args=(self.gal.pk, )))

    def test_back_url_export_experience(self, *mocks):
        fake_grant_application = FAKE_GRANT_APPLICATION.copy()
        fake_grant_application['has_exported_before'] = False
        mocks[1].return_value = fake_grant_application

        response = self.client.get(self.url)

        self.assertEqual(response.status_code, 200)
        back_html = BeautifulSoup(response.content,
                                  'html.parser').find(id='id_back_link')
        self.assertEqual(
            back_html.attrs['href'],
            reverse('grant-applications:export-experience',
                    args=(self.gal.pk, )))

    def test_post(self, *mocks):
        response = self.client.post(self.url,
                                    data={
                                        'interest_in_event_description':
                                        'A description',
                                        'is_in_contact_with_tcp':
                                        True,
                                        'tcp_name':
                                        'A Person',
                                        'tcp_email':
                                        '*****@*****.**',
                                        'tcp_mobile_number':
                                        '07777777777',
                                        'is_intending_to_exhibit_as_tcp_stand':
                                        True,
                                        'stand_trade_name':
                                        'A name',
                                        'trade_show_experience_description':
                                        'Some experience',
                                        'additional_guidance':
                                        'Some additional guidance'
                                    })
        self.assertEqual(response.status_code, 302)
        mocks[0].assert_called_once_with(
            grant_application_id=str(self.gal.backoffice_grant_application_id),
            interest_in_event_description='A description',
            is_in_contact_with_tcp=True,
            tcp_name='A Person',
            tcp_email='*****@*****.**',
            tcp_mobile_number='+447777777777',
            is_intending_to_exhibit_as_tcp_stand=True,
            stand_trade_name='A name',
            trade_show_experience_description='Some experience',
            additional_guidance='Some additional guidance')

    def test_required_fields(self, *mocks):
        response = self.client.post(self.url)
        msg = self.form_msgs['required']
        self.assertEqual(response.status_code, 200)
        self.assertFormError(response, 'form', 'interest_in_event_description',
                             msg)
        self.assertFormError(response, 'form', 'is_in_contact_with_tcp', msg)
        self.assertFormError(response, 'form',
                             'is_intending_to_exhibit_as_tcp_stand', msg)
        self.assertFormError(response, 'form', 'stand_trade_name', msg)
        self.assertFormError(response, 'form',
                             'trade_show_experience_description', msg)
        self.assertFormError(response, 'form', 'additional_guidance', msg)

    def test_conditionally_required_field_errors(self, *mocks):
        response = self.client.post(self.url,
                                    data={'is_in_contact_with_tcp': True})
        msg = self.form_msgs['required']
        self.assertEqual(response.status_code, 200)
        self.assertFormError(response, 'form', 'tcp_name', msg)
        self.assertFormError(response, 'form', 'tcp_email', msg)
        self.assertFormError(response, 'form', 'tcp_mobile_number', msg)

    def test_conditionally_optional_fields_not_present(self, *mocks):
        response = self.client.post(self.url,
                                    data={
                                        'interest_in_event_description':
                                        'A description',
                                        'is_in_contact_with_tcp':
                                        False,
                                        'is_intending_to_exhibit_as_tcp_stand':
                                        True,
                                        'stand_trade_name':
                                        'A name',
                                        'trade_show_experience_description':
                                        'Some experience',
                                        'additional_guidance':
                                        'Some additional guidance'
                                    })
        mocks[0].assert_called_once_with(
            grant_application_id=str(self.gal.backoffice_grant_application_id),
            interest_in_event_description='A description',
            is_in_contact_with_tcp=False,
            is_intending_to_exhibit_as_tcp_stand=True,
            stand_trade_name='A name',
            trade_show_experience_description='Some experience',
            additional_guidance='Some additional guidance',
            # Optional fields all explicitly set to None to overwrite any previously set value
            tcp_name=None,
            tcp_email=None,
            tcp_mobile_number=None,
        )
        self.assertRedirects(response,
                             reverse('grant-applications:state-aid-summary',
                                     args=(self.gal.pk, )),
                             fetch_redirect_response=False)

    def test_conditionally_optional_fields_present(self, *mocks):
        response = self.client.post(self.url,
                                    data={
                                        'interest_in_event_description':
                                        'A description',
                                        'is_in_contact_with_tcp':
                                        False,
                                        'tcp_name':
                                        'A Person',
                                        'tcp_email':
                                        '*****@*****.**',
                                        'tcp_mobile_number':
                                        '07777777777',
                                        'is_intending_to_exhibit_as_tcp_stand':
                                        True,
                                        'stand_trade_name':
                                        'A name',
                                        'trade_show_experience_description':
                                        'Some experience',
                                        'additional_guidance':
                                        'Some additional guidance'
                                    })
        mocks[0].assert_called_once_with(
            grant_application_id=str(self.gal.backoffice_grant_application_id),
            interest_in_event_description='A description',
            is_in_contact_with_tcp=False,
            is_intending_to_exhibit_as_tcp_stand=True,
            stand_trade_name='A name',
            trade_show_experience_description='Some experience',
            additional_guidance='Some additional guidance',
            # Optional fields all explicitly set to None to overwrite any previously set value
            tcp_name=None,
            tcp_email=None,
            tcp_mobile_number=None,
        )
        self.assertRedirects(response,
                             reverse('grant-applications:state-aid-summary',
                                     args=(self.gal.pk, )),
                             fetch_redirect_response=False)

    def test_get_redirects_to_confirmation_if_application_already_sent_for_review(
            self, *mocks):
        fake_grant_application = FAKE_GRANT_APPLICATION.copy()
        fake_grant_application['sent_for_review'] = True
        mocks[1].return_value = fake_grant_application
        response = self.client.get(self.url)
        self.assertRedirects(
            response,
            reverse('grant-applications:confirmation', args=(self.gal.pk, )))

    def test_get_redirects_to_ineligible_if_application_is_not_active(
            self, *mocks):
        fake_grant_application = FAKE_GRANT_APPLICATION.copy()
        fake_grant_application['is_eligible'] = False
        mocks[1].return_value = fake_grant_application
        response = self.client.get(self.url)
        self.assertRedirects(response,
                             reverse('grant-applications:ineligible'))

    def test_post_redirects_to_ineligible_if_application_is_not_active(
            self, *mocks):
        fake_grant_application = FAKE_GRANT_APPLICATION.copy()
        fake_grant_application['is_eligible'] = False
        mocks[1].return_value = fake_grant_application
        response = self.client.post(self.url)
        self.assertRedirects(response,
                             reverse('grant-applications:ineligible'))

    def test_get_does_not_redirect_to_ineligible_if_review_page_has_been_viewed(
            self, *mocks):
        fake_grant_application = FAKE_GRANT_APPLICATION.copy()
        fake_grant_application['is_eligible'] = False
        mocks[1].return_value = fake_grant_application

        self.gal.has_viewed_review_page = True
        self.gal.save()

        response = self.client.get(self.url)
        self.assertEqual(response.status_code, 200)
        self.assertTemplateUsed(response, TradeEventDetailsView.template_name)

    def test_post_redirects_to_review_page_if_application_review_page_has_been_viewed(
            self, *mocks):
        self.gal.has_viewed_review_page = True
        self.gal.save()
        response = self.client.post(self.url,
                                    data={
                                        'interest_in_event_description':
                                        'A description',
                                        'is_in_contact_with_tcp':
                                        False,
                                        'tcp_name':
                                        'A Person',
                                        'tcp_email':
                                        '*****@*****.**',
                                        'tcp_mobile_number':
                                        '07777777777',
                                        'is_intending_to_exhibit_as_tcp_stand':
                                        True,
                                        'stand_trade_name':
                                        'A name',
                                        'trade_show_experience_description':
                                        'Some experience',
                                        'additional_guidance':
                                        'Some additional guidance'
                                    })
        self.assertRedirects(response,
                             reverse('grant-applications:application-review',
                                     args=(self.gal.pk, )),
                             fetch_redirect_response=False)
Beispiel #26
0
 def setUp(self):
     self.gal = GrantApplicationLinkFactory()
     self.url = reverse('grant-applications:export-experience',
                        kwargs={'pk': self.gal.pk})
Beispiel #27
0
class TestApplicationReviewView(BaseTestCase):
    def setUp(self):
        self.gal = GrantApplicationLinkFactory()
        self.url = reverse('grant-applications:application-review',
                           args=(self.gal.pk, ))

    def test_get(self, *mocks):
        response = self.client.get(self.url)
        self.assertEqual(response.status_code, 200)
        self.assertIn('core/govt_summary_list.html',
                      [t.name for t in response.templates])

    def test_summary_shows_correct_sections_if_company_found(self, *mocks):
        response = self.client.get(self.url)
        html = BeautifulSoup(response.content, 'html.parser')
        headings = html.find_all(id='id_summary_list_heading')
        self.assertListEqual([h.text for h in headings], [
            PreviousApplicationsView.extra_context['page']['heading'],
            SelectAnEventView.extra_context['page']['heading'],
            EventCommitmentView.extra_context['page']['heading'],
            SelectCompanyView.extra_context['page']['heading'],
            CompanyDetailsView.extra_context['page']['heading'],
            ContactDetailsView.extra_context['page']['heading'],
            CompanyTradingDetailsView.extra_context['page']['heading'],
            ExportExperienceView.extra_context['page']['heading'],
            TradeEventDetailsView.extra_context['page']['heading'],
            StateAidSummaryView.extra_context['page']['heading'],
        ])

    def test_summary_shows_correct_sections_on_manual_company_entry(
            self, *mocks):
        fake_grant_application = FAKE_GRANT_APPLICATION.copy()
        fake_grant_application['company'] = None
        fake_grant_application['manual_company_type'] = 'limited company'
        fake_grant_application['manual_company_name'] = 'A Name'
        fake_grant_application['manual_company_address_line_1'] = 'Line 1'
        fake_grant_application['manual_company_address_line_2'] = 'Line 2'
        fake_grant_application['manual_company_address_town'] = 'Town 1'
        fake_grant_application['manual_company_address_county'] = 'County 1'
        fake_grant_application['manual_company_address_postcode'] = 'ZZ0 1ZZ'
        fake_grant_application['manual_time_trading_in_uk'] = '2 to 5 years'
        fake_grant_application['manual_registration_number'] = '12345678'
        fake_grant_application['manual_vat_number'] = '123456789'
        fake_grant_application['manual_website'] = 'www.test.com'
        mocks[4].return_value = fake_grant_application

        response = self.client.get(self.url)
        html = BeautifulSoup(response.content, 'html.parser')
        headings = html.find_all(id='id_summary_list_heading')
        self.assertListEqual([h.text for h in headings], [
            PreviousApplicationsView.extra_context['page']['heading'],
            SelectAnEventView.extra_context['page']['heading'],
            EventCommitmentView.extra_context['page']['heading'],
            ManualCompanyDetailsView.extra_context['page']['heading'],
            CompanyDetailsView.extra_context['page']['heading'],
            ContactDetailsView.extra_context['page']['heading'],
            CompanyTradingDetailsView.extra_context['page']['heading'],
            ExportExperienceView.extra_context['page']['heading'],
            TradeEventDetailsView.extra_context['page']['heading'],
            StateAidSummaryView.extra_context['page']['heading'],
        ])

    def test_summary_shows_correct_sections_on_export_details_entry(
            self, *mocks):
        fake_grant_application = FAKE_GRANT_APPLICATION.copy()
        fake_grant_application['has_exported_before'] = True
        fake_grant_application['has_exported_in_last_12_months'] = True
        fake_grant_application['export_regions'] = ['africa']
        fake_grant_application['markets_intending_on_exporting_to'] = [
            'existing'
        ]
        fake_grant_application['is_in_contact_with_dit_trade_advisor'] = False
        fake_grant_application[
            'export_experience_description'] = 'A description'
        fake_grant_application['export_strategy'] = 'A strategy'
        mocks[4].return_value = fake_grant_application

        response = self.client.get(self.url)
        html = BeautifulSoup(response.content, 'html.parser')
        headings = html.find_all(id='id_summary_list_heading')
        self.assertListEqual([h.text for h in headings], [
            PreviousApplicationsView.extra_context['page']['heading'],
            SelectAnEventView.extra_context['page']['heading'],
            EventCommitmentView.extra_context['page']['heading'],
            SelectCompanyView.extra_context['page']['heading'],
            CompanyDetailsView.extra_context['page']['heading'],
            ContactDetailsView.extra_context['page']['heading'],
            CompanyTradingDetailsView.extra_context['page']['heading'],
            ExportExperienceView.extra_context['page']['heading'],
            ExportDetailsView.extra_context['page']['heading'],
            TradeEventDetailsView.extra_context['page']['heading'],
            StateAidSummaryView.extra_context['page']['heading'],
        ])

    def test_summary_export_experience_section_shows_single_row(self, *mocks):
        fake_grant_application = FAKE_GRANT_APPLICATION.copy()
        fake_grant_application['has_exported_before'] = True
        mocks[4].return_value = fake_grant_application

        response = self.client.get(self.url)
        html = BeautifulSoup(response.content,
                             'html.parser').find(id='id_summary_list_7')

        rows = html.find_all(attrs={'class': 'govuk-summary-list__row'})
        self.assertEqual(len(rows), 1)
        self.assertEqual(
            html.find(id='id_summary_list_key_0').text,
            ExportExperienceForm.base_fields['has_exported_before'].label)
        self.assertIsNone(html.find(id='id_summary_list_key_1'))

    def test_summary_export_experience_section_shows_all_rows(self, *mocks):
        fake_grant_application = FAKE_GRANT_APPLICATION.copy()
        fake_grant_application['has_exported_before'] = False
        mocks[4].return_value = fake_grant_application

        response = self.client.get(self.url)
        html = BeautifulSoup(response.content,
                             'html.parser').find(id='id_summary_list_7')

        rows = html.find_all(attrs={'class': 'govuk-summary-list__row'})
        self.assertEqual(len(rows), 2)
        self.assertEqual(
            html.find(id='id_summary_list_key_0').text,
            ExportExperienceForm.base_fields['has_exported_before'].label)
        self.assertEqual(
            html.find(id='id_summary_list_key_1').text, ExportExperienceForm.
            base_fields['has_product_or_service_for_export'].label)

    def test_has_viewed_review_page_is_set_to_true_on_get(self, *mocks):
        self.client.get(self.url)
        self.gal.refresh_from_db()
        self.assertTrue(self.gal.has_viewed_review_page)

    def test_post_redirects(self, *mocks):
        self.client.get(self.url)
        response = self.client.post(self.url)
        self.assertEqual(response.status_code, 302)
        redirect = resolve(response.url)
        self.assertEqual(redirect.kwargs['pk'], str(self.gal.id))
        self.assertRedirects(
            response,
            reverse('grant-applications:confirmation', args=(self.gal.pk, )))

    def test_send_grant_application_for_review(self, *mocks):
        self.client.get(self.url)
        self.client.post(self.url)
        self.gal.refresh_from_db()
        self.assertIn('application_summary', self.client.session)
        mocks[5].assert_called_once_with(
            str(self.gal.backoffice_grant_application_id),
            application_summary=self.client.session['application_summary'])

    def test_backoffice_exception_on_send_grant_application_for_review(
            self, *mocks):
        mocks[5].side_effect = BackofficeServiceException
        self.client.get(self.url)
        response = self.client.post(self.url)
        self.assertFormError(response, 'form', None,
                             self.form_msgs['resubmit'])

    def test_get_redirects_to_confirmation_if_application_already_sent_for_review(
            self, *mocks):
        fake_grant_application = FAKE_GRANT_APPLICATION.copy()
        fake_grant_application['sent_for_review'] = True
        mocks[4].return_value = fake_grant_application
        response = self.client.get(self.url)
        self.assertRedirects(
            response,
            reverse('grant-applications:confirmation', args=(self.gal.pk, )))

    def test_get_redirects_to_ineligible_if_application_is_not_active(
            self, *mocks):
        fake_grant_application = FAKE_GRANT_APPLICATION.copy()
        fake_grant_application['is_eligible'] = False
        mocks[4].return_value = fake_grant_application
        response = self.client.get(self.url)
        self.assertRedirects(response,
                             reverse('grant-applications:ineligible'))

    def test_post_redirects_to_ineligible_if_application_is_not_active(
            self, *mocks):
        fake_grant_application = FAKE_GRANT_APPLICATION.copy()
        fake_grant_application['is_eligible'] = False
        mocks[4].return_value = fake_grant_application
        response = self.client.post(self.url)
        self.assertRedirects(response,
                             reverse('grant-applications:ineligible'))

    def test_get_does_not_redirect_to_ineligible_if_review_page_has_been_viewed(
            self, *mocks):
        fake_grant_application = FAKE_GRANT_APPLICATION.copy()
        fake_grant_application['is_eligible'] = False
        mocks[4].return_value = fake_grant_application

        self.gal.has_viewed_review_page = True
        self.gal.save()

        response = self.client.get(self.url)
        self.assertEqual(response.status_code, 200)
        self.assertTemplateUsed(response, ApplicationReviewView.template_name)