def test_nonsense_values_rejected(self, _):
        class Klass:
            pass

        self.assertFalse(utils.is_nhs_number_valid(None))
        self.assertFalse(utils.is_nhs_number_valid(""))
        self.assertFalse(utils.is_nhs_number_valid(True))
        self.assertFalse(utils.is_nhs_number_valid(False))
        self.assertFalse(utils.is_nhs_number_valid({}))
        self.assertFalse(utils.is_nhs_number_valid([]))
        self.assertFalse(utils.is_nhs_number_valid(Klass()))
        self.assertFalse(utils.is_nhs_number_valid(1))
Esempio n. 2
0
def your_details_review(session_id):
    form = ReviewForm()
    user_details = UserDetails()

    if not session.get(FIRST_NAME) or not session.get(LAST_NAME):
        return redirect_to_route("yourdetails.your_details")

    if not session.get(DOB_DAY) or not session.get(DOB_MONTH) or not session.get(DOB_YEAR):
        return redirect_to_route("yourdetails.details_dob")

    if not session.get(NHS_NUMBER) and not session.get(POST_CODE):
        return redirect_to_route("yourdetails.details_auth_option")

    if form.validate_on_submit():
        if session[NHS_NUMBER] and not utils.is_nhs_number_valid(session[NHS_NUMBER]):
            if session.get('nhs_number_failed'):
                return redirect_to_route("yourdetails.invalid_nhs_number")
            else:
                session['nhs_number_failed'] = True
                return redirect_to_route("yourdetails.nhs_number_not_accepted")

        result = do_pds_search(user_details, session_id)

        if result == constants.PDS_SEARCH_SUCCESS:
            session.pop('timeout_threshold', None)
            return redirect_to_route("verification.waiting_for_results")
        elif result == constants.PDS_RESULT_INVALID_AGE:
            session.pop('timeout_threshold', None)
            return redirect_to_route("verification.age_restriction_error")
        else:
            app.logger.warning("pds search failure")

        # for PDS_REQUEST_TIMEOUT and other unknown errors
        return redirect_to_route("main.generic_error")
    elif form.errors:
        app.logger.info("submission contains errors")

    return render_template(
        "your-details-review.html",
        form=form,
        details=user_details,
        routes=routes
    )
 def test_valid_nhs_numbers_accepted(self, _):
     self.assertTrue(utils.is_nhs_number_valid("9999999999"))
     self.assertTrue(utils.is_nhs_number_valid("9998880025"))
     self.assertTrue(utils.is_nhs_number_valid("9998880017"))
     self.assertTrue(utils.is_nhs_number_valid("9998880009"))
 def test_modulo_check_failures_rejected(self, _):
     self.assertFalse(utils.is_nhs_number_valid("1234567890"))
     self.assertFalse(utils.is_nhs_number_valid("2833272828"))
     self.assertFalse(utils.is_nhs_number_valid("3884383828"))
     self.assertFalse(utils.is_nhs_number_valid("9999999977"))
 def test_strings_not_length_ten_rejected(self, _):
     self.assertFalse(utils.is_nhs_number_valid("123456789"))
     self.assertFalse(utils.is_nhs_number_valid("12345678901"))
 def test_alphabetic_strings_rejected(self, _):
     self.assertFalse(utils.is_nhs_number_valid("1234.53355"))
     self.assertFalse(utils.is_nhs_number_valid("1234A53355"))