Beispiel #1
0
def request_boundary_check(**kwargs):
    """
    Checks to see if the address is within the CHPL boundary
    :param kwargs:
    :return:
    """
    try:
        lookup = kwargs if kwargs else request.args
        address = {
            'street': lookup.get(Flds.street.frm),
            'city': lookup.get(Flds.city.frm),
            'state': lookup.get(Flds.state.frm),
            'postal_code': lookup.get(Flds.postal_code.frm)
        }
        rtn_msg = boundary_check(**address)
        return rtn_msg if kwargs else jsonify(rtn_msg)
    except Exception as err:
        log.exception(err)
Beispiel #2
0
 def test_unable_to_determine(self):
     self.assertIsNone(
         validation.boundary_check(**self.bad_address)['valid'])
Beispiel #3
0
 def test_bounday_not_within(self):
     self.assertFalse(
         validation.boundary_check(**self.out_boundary_address)['valid'])
Beispiel #4
0
 def test_boundary_within(self):
     self.assertTrue(
         validation.boundary_check(**self.valid_address)['valid'])
Beispiel #5
0
def index():
    """
    Default view for handling post submissions from a posted form

    """
    try:
        if not request.method.startswith("POST"):
            return "Method not supported"
        pprint.pprint(request)
        form = request.form.to_dict()
        pprint.pprint(form)
        testing = testing_mode(form)
        valid_form = validate_form(form)

        if valid_form['valid']:
            lookup = form
            address = {
                'street': lookup.get(Flds.street.frm),
                'city': lookup.get(Flds.city.frm),
                'state': lookup.get(Flds.state.frm),
                'postal_code': lookup.get(Flds.postal_code.frm)
            }

            boundary = boundary_check(**address)
            location = "internal" if request.remote_addr \
                       and request.remote_addr.startswith(config.INTERNAL_IP) \
                       else "external"
            try:
                temp_card_number = "testing"
                if not testing:
                    temp_card_number = register_patron(valid_form['form'],
                                                       location, boundary)
                if temp_card_number is not None:
                    if location == "internal":
                        success_uri = config.INTERNAL_SUCCESS
                    else:
                        success_uri = config.SUCCESS_URI
                    return jsonify({
                        "valid":
                        True,
                        "url":
                        "{}?number={}&boundary={}".format(
                            success_uri, temp_card_number,
                            str(boundary['valid']).lower())
                    })
            except exceptions.PasswordError as p_err:
                # log.exception(p_err)
                error_obj = {
                    "field": Flds.password.frm,
                    "valid": False,
                    "message": p_err.msg
                }
                valid_form['errors'].append(error_obj)
                valid_form['valid'] = False
                return jsonify(valid_form)
            except Exception as err1:
                log.exception(err1.with_traceback())
                log.error({
                    key: value
                    for key, value in form.items()
                    if "password" not in key.lower()
                })
            return jsonify({
                "valid":
                True,
                "url":
                "{}?error={}".format(config.ERROR_URI,
                                     "Failed to register Patron")
            })
        else:
            return jsonify(valid_form)
    except Exception as err:
        log.exception(err)
        log.error({
            key: value
            for key, value in form.items() if "password" not in key.lower()
        })
        return jsonify({
            "valid":
            True,
            "url":
            "{}?error={}".format(config.ERROR_URI, ("Failed to register "
                                                    "Patron"))
        })