def post(self, request, *args, **kwargs):
        application_id = self.request.POST.get('id')
        master_summary = self.request.POST.get('master-summary')
        hide_form = self.request.GET.get('state')

        delete_action = ([
            k for k, v in self.request.POST.items() if k.startswith('remove-')
        ] + [None])[0]
        if delete_action is not None:

            # param name in the form 'remove-[id]'
            delete_id = delete_action[len('remove-'):]

            # id will be blank if user is removing the new, empty form. Can safely ignore
            if delete_id != '':
                response = NannyGatewayActions().delete(
                    'previous-address',
                    params={'previous_address_id': delete_id})
            return HttpResponseRedirect(
                build_url('personal-details:Personal-Details-Previous-Address',
                          get={
                              'id': application_id,
                              'master-summary': master_summary,
                              'state': hide_form
                          }))

        if hide_form == 'hidden':
            api_response = NannyGatewayActions().list('previous-address',
                                                      params={
                                                          'person_id':
                                                          application_id,
                                                          'order': '0'
                                                      })

            if api_response.status_code == 200:
                NannyGatewayActions().delete('previous-address',
                                             params=api_response.record[0])
            return HttpResponseRedirect(
                build_url(
                    'personal-details:Personal-Details-Gaps-In-Address-History',
                    get={
                        'id': request.POST['id'],
                        'summary': master_summary
                    }))
        if 'delete-active' in request.POST:
            return HttpResponseRedirect(
                build_url('personal-details:Personal-Details-Previous-Address',
                          get={
                              'id': request.POST['id'],
                              'state': 'hidden',
                              'summary': master_summary
                          }))

        form = self.get_form()
        if form.is_valid():
            return self.form_valid(form)
        else:
            return self.form_invalid(form)
Exemple #2
0
    def test_error_empty_criminal_convictions(self):
        """
        Test to assert that the 'name' page can be rendered.
        """
        with mock.patch.object(NannyGatewayActions,
                               "read") as nanny_api_read, mock.patch.object(
                                   NannyGatewayActions,
                                   "put") as nanny_api_put, mock.patch.object(
                                       NannyGatewayActions,
                                       "create") as nanny_api_create:
            nanny_api_read.side_effect = side_effect
            nanny_api_put.side_effect = side_effect
            nanny_api_create.side_effect = side_effect

            expected_error = (
                "Select whether you have any criminal convictions or cautions")
            response = self.client.post(
                build_url("suitability:criminal_convictions",
                          get={"id": uuid.UUID}),
                {
                    "criminal_convictions": "",
                },
            )
            self.assertFormError(response, "form", "criminal_convictions",
                                 expected_error)
    def post(self, request, *args, **kwargs):
        application_id = self.request.POST.get('id')
        delete_action = ([
            k for k, v in self.request.POST.items() if k.startswith('remove-')
        ] + [None])[0]
        if delete_action is not None:

            # param name in the form 'remove-[id]'
            delete_id = delete_action[len('remove-'):]

            # id will be blank if user is removing the new, empty form. Can safely ignore
            if delete_id != '':
                response = NannyGatewayActions().delete(
                    'previous-address',
                    params={'previous_address_id': delete_id})
            return HttpResponseRedirect(
                build_url(
                    "personal-details:Personal-Details-Previous-Address-Summary",
                    get={'id': application_id}))

        form = self.get_form()
        if form.is_valid():
            return self.form_valid(form)
        else:
            return self.form_invalid(form)
Exemple #4
0
    def test_can_render_criminal_convictions_page(self):
        """
        Test to assert that the 'criminal_convictions' page can be rendered.
        """
        with mock.patch.object(NannyGatewayActions,
                               "read") as nanny_api_read, mock.patch.object(
                                   NannyGatewayActions,
                                   "put") as nanny_api_put, mock.patch.object(
                                       NannyGatewayActions,
                                       "patch") as nanny_api_patch:
            nanny_api_read.side_effect = side_effect
            nanny_api_put.side_effect = side_effect
            nanny_api_patch.side_effect = side_effect

            response = self.client.get(
                build_url("suitability:criminal_convictions",
                          get={"id": uuid.UUID}))

            content = str(response.content)
            expected_fields = {
                "radio1":
                'input type="radio" name="criminal_convictions" value="True" class="form-control" required',
                "radio2":
                'input type="radio" name="criminal_convictions" value="False" class="form-control" required',
            }
            self.assertEqual(response.status_code, 200)
            self.assertEqual(response.resolver_match.view_name,
                             "suitability:criminal_convictions")

            for _, expected_input in expected_fields.items():
                self.assertIn(expected_input, content)
Exemple #5
0
    def test_error_empty_criminal_convictions_details(self):
        """
        Test to assert that the 'criminal_convictions_details' page can be rendered.
        """
        with mock.patch.object(
                NannyGatewayActions,
                "read") as nanny_api_read, mock.patch.object(
                    NannyGatewayActions,
                    "list") as nanny_api_list, mock.patch.object(
                        NannyGatewayActions,
                        "put") as nanny_api_put, mock.patch.object(
                            NannyGatewayActions,
                            "delete") as nanny_api_delete, mock.patch.object(
                                NannyGatewayActions, "create"
                            ) as nanny_api_create, mock.patch.object(
                                NannyGatewayActions,
                                "patch") as nanny_api_patch, mock.patch.object(
                                    IdentityGatewayActions,
                                    "read") as identity_api_read:
            nanny_api_read.side_effect = side_effect
            nanny_api_put.side_effect = side_effect
            nanny_api_create.side_effect = side_effect
            response = self.client.post(
                build_url("suitability:criminal_convictions_details",
                          get={"id": uuid.UUID}),
                {
                    "criminal_convictions_details": "",
                },
            )

            expected_error = "Details of all criminal convictions and cautions must be entered"
            self.assertFormError(response, "form",
                                 "criminal_convictions_details",
                                 expected_error)
Exemple #6
0
    def test_error_empty_social_services_details(self):
        """
        Test to assert that the 'name' page can be rendered.
        """
        with mock.patch.object(
                NannyGatewayActions,
                "read") as nanny_api_read, mock.patch.object(
                    NannyGatewayActions,
                    "list") as nanny_api_list, mock.patch.object(
                        NannyGatewayActions,
                        "put") as nanny_api_put, mock.patch.object(
                            NannyGatewayActions,
                            "delete") as nanny_api_delete, mock.patch.object(
                                NannyGatewayActions, "create"
                            ) as nanny_api_create, mock.patch.object(
                                NannyGatewayActions,
                                "patch") as nanny_api_patch, mock.patch.object(
                                    IdentityGatewayActions,
                                    "read") as identity_api_read:
            nanny_api_read.side_effect = side_effect
            nanny_api_put.side_effect = side_effect
            nanny_api_create.side_effect = side_effect
            response = self.client.post(
                build_url("suitability:social_services_details",
                          get={"id": uuid.UUID}),
                {
                    "social_services_details": "",
                },
            )

            expected_error = (
                "Details about your involvement with social services must be entered"
            )
            self.assertFormError(response, "form", "social_services_details",
                                 expected_error)
Exemple #7
0
    def test_can_render_social_services_details_page(self):
        """
        Test to assert that the 'social_services_details' page can be rendered.
        """
        with mock.patch.object(NannyGatewayActions,
                               "read") as nanny_api_read, mock.patch.object(
                                   NannyGatewayActions,
                                   "put") as nanny_api_put, mock.patch.object(
                                       NannyGatewayActions,
                                       "patch") as nanny_api_patch:
            nanny_api_read.side_effect = side_effect
            nanny_api_put.side_effect = side_effect
            nanny_api_patch.side_effect = side_effect

            response = self.client.get(
                build_url("suitability:social_services_details",
                          get={"id": uuid.UUID}))
            content = str(response.content)

            expected_input = 'textarea name="social_services_details" cols="40" rows="10" class="form-control" required'

            self.assertEqual(response.status_code, 200)
            self.assertEqual(response.resolver_match.view_name,
                             "suitability:social_services_details")

            self.assertIn(expected_input, content)
Exemple #8
0
    def test_error_empty_social_services(self):
        """
        Test to assert that the 'name' page can be rendered.
        """
        with mock.patch.object(
                NannyGatewayActions,
                "read") as nanny_api_read, mock.patch.object(
                    NannyGatewayActions,
                    "list") as nanny_api_list, mock.patch.object(
                        NannyGatewayActions,
                        "put") as nanny_api_put, mock.patch.object(
                            NannyGatewayActions,
                            "delete") as nanny_api_delete, mock.patch.object(
                                NannyGatewayActions, "create"
                            ) as nanny_api_create, mock.patch.object(
                                NannyGatewayActions,
                                "patch") as nanny_api_patch, mock.patch.object(
                                    IdentityGatewayActions,
                                    "read") as identity_api_read:
            nanny_api_read.side_effect = side_effect
            nanny_api_put.side_effect = side_effect
            nanny_api_create.side_effect = side_effect

            response = self.client.post(
                build_url("suitability:social_services", get={"id":
                                                              uuid.UUID}),
                {
                    "social_services": "",
                },
            )

            expected_error = "Select whether you have been involved with social services in connection with your own children."
            self.assertFormError(response, "form", "social_services",
                                 expected_error)
            self.assertEqual(response.status_code, 200)
Exemple #9
0
    def test_can_submit_valid_suitability_details(self):
        """
        Test to assert that the 'suitability_details' page can be rendered.
        """
        with mock.patch.object(
                NannyGatewayActions,
                "read") as nanny_api_read, mock.patch.object(
                    NannyGatewayActions,
                    "put") as nanny_api_put, mock.patch.object(
                        NannyGatewayActions,
                        "create") as nanny_api_create, mock.patch.object(
                            NannyGatewayActions, "patch") as nanny_api_patch:
            nanny_api_read.side_effect = side_effect
            nanny_api_put.side_effect = side_effect
            nanny_api_patch.side_effect = side_effect
            nanny_api_create.side_effect = side_effect

            token = str(uuid.uuid4())
            url = build_url("suitability:suitability_details",
                            get={"id": token})
            expected_redirect = [(
                f'{reverse("suitability:social_services")}?id={token}',
                302,
            )]
            data = {
                "suitability_circumstances_details":
                "Lorem ipsum dolor sit amet, consectetuer adipiscing elit.",
            }
            response = self.client.post(url, data, follow=True)
            self.assertEqual(response.redirect_chain, expected_redirect)
Exemple #10
0
    def test_error_empty_other_circumstances(self):
        """
        Test to assert that the 'disqualification_details' validates data.
        """
        with mock.patch.object(NannyGatewayActions,
                               "read") as nanny_api_read, mock.patch.object(
                                   NannyGatewayActions,
                                   "put") as nanny_api_put, mock.patch.object(
                                       NannyGatewayActions,
                                       "create") as nanny_api_create:
            nanny_api_read.side_effect = side_effect
            nanny_api_put.side_effect = side_effect
            nanny_api_create.side_effect = side_effect

            expected_error = (
                "Details about disqualification circumstances must be entered")
            response = self.client.post(
                build_url("suitability:disqualification_details",
                          get={"id": uuid.UUID}),
                {
                    "disqualification_details": "",
                },
            )
            self.assertFormError(response, "form", "disqualification_details",
                                 expected_error)
Exemple #11
0
    def test_can_submit_valid_disqualification_question_false(self):
        """
        Test to assert that the 'disqualification_question' page can be rendered.
        """
        with mock.patch.object(
                NannyGatewayActions,
                "read") as nanny_api_read, mock.patch.object(
                    NannyGatewayActions,
                    "put") as nanny_api_put, mock.patch.object(
                        NannyGatewayActions,
                        "create") as nanny_api_create, mock.patch.object(
                            NannyGatewayActions, "patch") as nanny_api_patch:
            nanny_api_read.side_effect = side_effect
            nanny_api_put.side_effect = side_effect
            nanny_api_patch.side_effect = side_effect
            nanny_api_create.side_effect = side_effect
            token = str(uuid.uuid4())
            data = {
                "disqualification": False,
            }
            url = build_url("suitability:disqualification_question",
                            get={"id": token})
            expected_redirect = [(
                f'{reverse("suitability:other_circumstances")}?id={token}',
                302,
            )]
            response = self.client.post(url, data, follow=True)

            self.assertEqual(response.redirect_chain, expected_redirect)
Exemple #12
0
    def test_can_submit_valid_criminal_convictions_false(self):
        """
        Test to assert that the 'criminal_convictions' page can be rendered.
        """
        with mock.patch.object(
                NannyGatewayActions,
                "read") as nanny_api_read, mock.patch.object(
                    NannyGatewayActions,
                    "put") as nanny_api_put, mock.patch.object(
                        NannyGatewayActions,
                        "create") as nanny_api_create, mock.patch.object(
                            NannyGatewayActions, "patch") as nanny_api_patch:
            nanny_api_read.side_effect = side_effect
            nanny_api_put.side_effect = side_effect
            nanny_api_patch.side_effect = side_effect
            nanny_api_create.side_effect = side_effect

            data = {
                "criminal_convictions": False,
            }
            token = str(uuid.uuid4())
            url = build_url("suitability:criminal_convictions",
                            get={"id": token})
            expected_redirect = [(
                f'{reverse("suitability:suitability_summary")}?id={token}',
                302,
            )]

            response = self.client.post(url, data, follow=True)

            self.assertEqual(response.redirect_chain, expected_redirect)
Exemple #13
0
    def get_success_url(self):

        application_id = app_id_finder(self.request)

        if self.request.POST["name_history"] == "True":
            success_url = "personal-details:Personal-Details-Birth-Name"
        elif self.request.POST["name_history"] == "False":
            response = NannyGatewayActions().list(
                "previous-name", params={"application_id": application_id}
            )
            if response.status_code == 200:
                for prev_name in response.record:
                    NannyGatewayActions().delete(
                        "previous-name",
                        params={"previous_name_id": prev_name["previous_name_id"]},
                    )
            success_url = "personal-details:Personal-Details-Home-Address"
        else:
            raise ValueError(
                "Invalid response passed to the name_history view from the Name history question in Nanny"
            )

        url = build_url(success_url, get=self.get_success_parameters())

        return url
    def get_context_data(self, **kwargs):
        """
        Get context data passes arguments into the template context for the view, in this case, the link to be followed
        :param kwargs:
        :return:
        """

        app_id = app_id_finder(self.request)
        pd_api_response = NannyGatewayActions().read('applicant-personal-details', params={'application_id': app_id})
        if pd_api_response.status_code == 200:
            record = pd_api_response.record
            moved_in_date_str = record['moved_in_date']
            moved_in_date = datetime.datetime.strptime(moved_in_date_str, '%Y-%m-%d').date()
        else:
            raise Exception("Issue calculating whether move in date is within the last 5 years.")

        today_date = datetime.date.today()
        five_years_ago_date = today_date - relativedelta(years=5)

        current_address_within_five = 'personal-details:Personal-Details-Previous-Address'
        current_address_outside_five = 'personal-details:Personal-Details-Summary'

        if moved_in_date > five_years_ago_date:
            self.success_url_name = current_address_within_five
        elif moved_in_date <= five_years_ago_date:
            self.success_url_name = current_address_outside_five
        else:
            raise ValueError("Invalid response passed to the lived_abroad view from the Lived abroad question in Nanny")

        context = super(EmailGoodConductCertificatesView, self).get_context_data(**kwargs)
        context['link_url'] = build_url(self.success_url_name, get={'id': app_id})
        context['id'] = app_id_finder(self.request)

        return context
 def post(self, request):
     application_id = app_id_finder(request)
     NannyGatewayActions().patch('application',
                                 params={
                                     'application_id': application_id,
                                     'dbs_status': 'IN_PROGRESS'
                                 })
     return HttpResponseRedirect(
         build_url(self.success_url_name, get={'id': application_id}))
Exemple #16
0
    def post(self, request):
        """ Handle POST request. Create session for user if the request does not return a record. If a record exists,
        a check is completed on if the user has completed the personal details task. If they have, they are presented
        with the task-list, if not they are presented with the personal details task"""

        application_id = request.GET['id']
        nanny_api_response = NannyGatewayActions().read(
            'application', params={'application_id': application_id})

        if nanny_api_response.status_code == 200:
            application_record = NannyGatewayActions().read(
                'application', params={
                    'application_id': application_id
                }).record

            # This differentiates between a new user and one who has signed out during the personal details task.
            if application_record['personal_details_status'] == 'COMPLETED':
                response = HttpResponseRedirect(
                    build_url('Task-List', get={'id': application_id}))
                return response

            else:
                return HttpResponseRedirect(
                    build_url('personal-details:Personal-Details-Name',
                              get={'id': application_id}))

        if nanny_api_response.status_code == 404:
            NannyGatewayActions().create('application',
                                         params={
                                             'application_id':
                                             application_id,
                                             'application_status':
                                             'DRAFTING',
                                             'login_details_status':
                                             'COMPLETED',
                                             'date_last_accessed':
                                             datetime.datetime.now(),
                                             'application_expiry_email_sent':
                                             False
                                         })
            return HttpResponseRedirect(
                build_url('personal-details:Personal-Details-Name',
                          get={'id': application_id}))
 def post(self, request):
     application_id = self.request.POST['id']
     application_record = NannyGatewayActions().read('application',
                                                     params={
                                                         'application_id':
                                                         application_id
                                                     }).record
     application_record['first_aid_status'] = 'COMPLETED'
     NannyGatewayActions().put('application', params=application_record)
     return HttpResponseRedirect(
         build_url(self.success_url_name, get={'id': application_id}))
Exemple #18
0
    def post(self, request):
        application_id = app_id_finder(request)
        application_record = (NannyGatewayActions().read("application",
                                                         params={
                                                             "application_id":
                                                             application_id
                                                         }).record)
        application_record["personal_details_status"] = "COMPLETED"
        NannyGatewayActions().put("application", params=application_record)

        return HttpResponseRedirect(
            build_url(self.success_url_name, get={"id": application_id}))
Exemple #19
0
    def form_valid(self, form):
        # pull the applicant's home address from their personal details
        app_id = self.request.GET['id']

        both_work_and_home_address = None
        if form.cleaned_data['both_work_and_home_address'] == 'True':
            both_work_and_home_address = True
            self.success_url = 'Childcare-Address-Details'
        elif form.cleaned_data['both_work_and_home_address'] == 'False':
            both_work_and_home_address = False
            self.success_url = 'Childcare-Address-Postcode-Entry'

        childcare_address_changed_to_false = self.__check_childcare_address_changed_to_false(app_id,
                                                                                             both_work_and_home_address)

        apd_api_response = NannyGatewayActions().read('applicant-personal-details', params={'application_id': app_id})

        if apd_api_response.status_code == 200:
            personal_detail_id = apd_api_response.record['personal_detail_id']
            aha_api_response = NannyGatewayActions().read('applicant-home-address', params={'application_id': app_id})

            if aha_api_response.status_code == 200:
                home_address_record = aha_api_response.record
                initial_both_work_and_home_address = home_address_record['childcare_address']
                home_address_record['childcare_address'] = both_work_and_home_address
                NannyGatewayActions().put('applicant-home-address', params=home_address_record)



                # add new childcare address
                if both_work_and_home_address and not initial_both_work_and_home_address:
                    NannyGatewayActions().create(
                        'childcare-address',
                        params={
                            'date_created': datetime.today(),
                            'application_id': app_id,
                            'street_line1': home_address_record['street_line1'],
                            'street_line2': home_address_record['street_line2'],
                            'town': home_address_record['town'],
                            'county': home_address_record['county'],
                            'country': home_address_record['country'],
                            'postcode': home_address_record['postcode'],
                            'home_address': True
                        }
                    )

        if childcare_address_changed_to_false:
            # Delete all childcare addresses that are the same as the Applicant's home address.
            self.__delete_home_childcare_addresses(app_id)
            redirect_url = build_url('Childcare-Address-Postcode-Entry', get={'id': app_id, 'add': '1'})
            return HttpResponseRedirect(redirect_url)

        return super(ChildcareLocationView, self).form_valid(form)
Exemple #20
0
 def get_success_url(self):
     """
     Method to construct a url encoded with the necessary varaibles and navigate to it upone successful submission of
     a form.
     :return: a full url for the next page.
     """
     if self.success_url:
         # If not none, run the build url util function.
         return build_url(self.success_url,
                          get=self.get_success_parameters())
     else:
         raise ImproperlyConfigured(
             "No URL to redirect to. Provide a success_url.")
Exemple #21
0
 def post(self, request):
     """
     On a post request, set the task status to completed and redirect the user to the task list
     :return:
     """
     application_id = app_id_finder(request)
     NannyGatewayActions().patch('application',
                                 params={
                                     'application_id': application_id,
                                     'dbs_status': 'COMPLETED'
                                 })
     return HttpResponseRedirect(
         build_url(self.success_url_name, get={'id': application_id}))
Exemple #22
0
    def get_success_url(self):

        # no phone number yet, skip sms validation
        if not self.record['mobile_number']:
            success_view = 'Phone-Number'

        # sms validation
        else:
            self.record = self.sms_magic_link(self.record)
            success_view = 'Security-Code'

        IdentityGatewayActions().put('user', params=self.record)
        return utilities.build_url(success_view,
                                   get={'id': self.record['application_id']})
    def get(self, request, *args, **kwargs):
        app_id = self.request.GET.get('id')
        master_summary = self.request.GET.get('master_summary')
        api_response = NannyGatewayActions().list('previous-address',
                                                  params={
                                                      'person_id': app_id,
                                                      'order': '0'
                                                  })

        if api_response.status_code != 200:
            return HttpResponseRedirect(
                build_url('personal-details:Personal-Details-Previous-Address',
                          get={
                              'id': request.GET['id'],
                              'summary': master_summary
                          }))
        else:
            return super(PersonalDetailSelectPreviousAddressView,
                         self).get(request, *args, **kwargs)
    def get_context_data(self):
        context = dict()
        application_id = self.request.GET['id']
        first_aid_response = NannyGatewayActions().read(
            'first-aid', params={'application_id': application_id})
        if first_aid_response.status_code == 200:
            first_aid_record = first_aid_response.record
            course_date = datetime.datetime.strptime(
                first_aid_record['course_date'], '%Y-%m-%d').date()
            formatted_course_date = course_date.strftime('%d/%m/%Y')

            organisation_row = Row('training_organisation',
                                   'Training organisation',
                                   first_aid_record['training_organisation'],
                                   'first-aid:Training-Details',
                                   "training organisation")
            course_title_row = Row('course_title', 'Title of training course',
                                   first_aid_record['course_title'],
                                   'first-aid:Training-Details',
                                   "course title")
            course_date_row = Row('course_date',
                                  'Date you completed the course',
                                  formatted_course_date,
                                  'first-aid:Training-Details',
                                  "course completion date")

            first_aid_table = Table(application_id)
            first_aid_table.row_list = [
                organisation_row, course_title_row, course_date_row
            ]
            first_aid_table.get_errors()

            context['table_list'] = [first_aid_table]
            context['application_id'] = application_id
            context['page_title'] = 'Check your answers: first aid training'
            context['link_url'] = build_url(self.success_url_name,
                                            get={'id': application_id})
            context['id'] = self.request.GET['id']
            context['first_aid_record'] = first_aid_record
        else:
            raise Exception("A matching first aid record couldn't be found.")
        return context
    def form_valid(self, form):
        application_id = self.request.GET['id']
        api_response = IdentityGatewayActions().read('user', params={'application_id': application_id})

        record = api_response.record
        record['mobile_number'] = form.cleaned_data['mobile_number']
        record['add_phone_number'] = form.cleaned_data['other_phone_number']

        # Expire magic link
        record['email_expiry_date'] = 0

        IdentityGatewayActions().put('user', params=record)

        response = HttpResponseRedirect(build_url('Contact-Details-Summary', get={'id': application_id}))

        COOKIE_IDENTIFIER = CustomAuthenticationHandler.get_cookie_identifier()

        if COOKIE_IDENTIFIER not in self.request.COOKIES:
            CustomAuthenticationHandler.create_session(response, {'email': record['email']})
            return response

        return super(PhoneNumbersFormView, self).form_valid(form)
Exemple #26
0
    def test_error_empty_suitability_details(self):
        """
        Test to assert that the 'uitability_details' validates data.
        """
        with mock.patch.object(
                NannyGatewayActions,
                "read") as nanny_api_read, mock.patch.object(
                    NannyGatewayActions,
                    "list") as nanny_api_list, mock.patch.object(
                        NannyGatewayActions,
                        "put") as nanny_api_put, mock.patch.object(
                            NannyGatewayActions,
                            "delete") as nanny_api_delete, mock.patch.object(
                                NannyGatewayActions, "create"
                            ) as nanny_api_create, mock.patch.object(
                                NannyGatewayActions,
                                "patch") as nanny_api_patch, mock.patch.object(
                                    IdentityGatewayActions,
                                    "read") as identity_api_read:
            nanny_api_read.side_effect = side_effect
            nanny_api_put.side_effect = side_effect
            nanny_api_create.side_effect = side_effect

            response = self.client.post(
                build_url("suitability:suitability_details",
                          get={"id": uuid.UUID}),
                {
                    "suitability_circumstances_details": "",
                },
            )

            self.assertEqual(response.status_code, 200)
            expected_error = "Details of circumstances that might affect your suitability to work with, or be in contact with children must be entered"
            self.assertFormError(response, "form",
                                 "suitability_circumstances_details",
                                 expected_error)
Exemple #27
0
    def test_error_empty_disqualification_question(self):
        """
        Test to assert that the 'name' page can be rendered.
        """
        with mock.patch.object(NannyGatewayActions,
                               "read") as nanny_api_read, mock.patch.object(
                                   NannyGatewayActions,
                                   "put") as nanny_api_put, mock.patch.object(
                                       NannyGatewayActions,
                                       "create") as nanny_api_create:
            nanny_api_read.side_effect = side_effect
            nanny_api_put.side_effect = side_effect
            nanny_api_create.side_effect = side_effect

            expected_error = "Select whether you are disqualified from providing childcare for any reason listed in the criteria for disqualification under the Childcare Act 2006"
            response = self.client.post(
                build_url("suitability:disqualification_question",
                          get={"id": uuid.UUID}),
                {
                    "disqualification": "",
                },
            )
            self.assertFormError(response, "form", "disqualification",
                                 expected_error)
 def post(self, request):
     return HttpResponseRedirect(
         build_url(self.success_url_name, get={'id': request.GET['id']}))
    def form_valid(self, form):
        if not utilities.test_notify():
            return HttpResponseRedirect(reverse('Service-Unavailable'))

        application_id = self.request.GET.get('id')
        self.email_address = form.cleaned_data['email_address']

        # Create GatewayActions instances
        identity_actions = IdentityGatewayActions()
        nanny_actions = NannyGatewayActions()

        # Get relevant records
        user_identity_record = identity_actions.read('user',
                                                     params={
                                                         'application_id':
                                                         application_id
                                                     }).record

        # Get personal_details response, not record, and check if a record exists
        personal_details_response = nanny_actions.read(
            'applicant-personal-details',
            params={'application_id': application_id})
        try:
            personal_details_record_exists = personal_details_response.record is not None
        except AttributeError:
            personal_details_record_exists = False

        # Get user's current email
        account_email = user_identity_record['email']

        # Get first_name if it exists, otherwise use 'Applicant'
        if personal_details_record_exists:
            first_name = personal_details_response.record['first_name']
        else:
            first_name = "Applicant"

        existing_account_response = identity_actions.list(
            'user', params={
                'email': self.email_address,
                'service': 'NANNY'
            })
        existing_account_response_status_code = existing_account_response.status_code

        email_in_use = existing_account_response_status_code == 200

        if self.email_address == account_email:
            # If email is unchanged, return to the sign-in details check-answers page
            same_email_redirect = utilities.build_url(
                self.check_answers_url, get={'id': application_id})
            return HttpResponseRedirect(same_email_redirect)

        elif email_in_use:
            # If the email is already being used,
            if settings.DEBUG:
                print(
                    "You will not see an email validation link printed because an account already exists with that email."
                )
            not_sent_email_redirect = utilities.build_url(
                self.success_url, get={'id': application_id})
            email_address = self.email_address
            return HttpResponseRedirect(not_sent_email_redirect)

        else:
            change_email = self.email_address
            # Generate a new magic link and expiry date
            validation_link, email_expiry_date = utilities.generate_email_validation_link(
                change_email)
            magic_link = validation_link.split('/')[-1]

            # Create an update record with the magic_link information
            email_update_record = user_identity_record
            email_update_record['magic_link_email'] = magic_link
            email_update_record['email_expiry_date'] = email_expiry_date
            email_update_record['change_email'] = change_email

            # Update the user record
            record = IdentityGatewayActions().put('user',
                                                  params=email_update_record)

            # Send the 'Change Email' email
            if settings.DEBUG:
                print(validation_link)

            send_change_email_email(change_email, first_name, validation_link)

            sent_email_redirect = utilities.build_url(
                self.success_url, get={'id': application_id})

            return HttpResponseRedirect(sent_email_redirect)