Example #1
0
def post_compliance_person_present(request, case_id, json):
    data = client.post(request,
                       f"/compliance/visit/{case_id}/people-present/",
                       data=json)

    # Translate errors to be more user friendly, from
    #   {'errors': [{}, {'name': ['This field may not be blank.'], 'job_title': ['This field may not be blank.']}, ...]}
    #   to
    #   {'errors': {'name-2': ['This field may not be blank'], 'job-title-2': ['This field may not be blank'], ...}}
    # This allows the errors to specify the specific textbox input for name/job-title inputs allowing the users
    #   to see the exact field it didn't validate on.
    if "errors" in data.json():
        errors = data.json()["errors"]
        translated_errors = {}

        index = 1
        for error in errors:
            if error:
                if "name" in error:
                    translated_errors[f"name-{index}"] = [
                        f"{index}. " + error.pop("name")[0]
                    ]
                if "job_title" in error:
                    translated_errors[f"job-title-{index}"] = [
                        f"{index}. " + error.pop("job_title")[0]
                    ]
            index += 1

        return {**json, "errors": translated_errors}, data.status_code
    return data.json(), data.status_code
Example #2
0
 def post(self, request, **kwargs):
     data = []
     for match_id in request.POST.getlist("objects", []):
         data.append({"application": str(kwargs["pk"]), "denial": match_id, "category": kwargs["category"]})
     response = client.post(request, f"/applications/{kwargs['pk']}/denial-matches/", data)
     response.raise_for_status()
     return redirect(reverse("cases:case", kwargs={"queue_pk": kwargs["queue_pk"], "pk": kwargs["pk"]}))
Example #3
0
def post_enforcement_xml(request, queue_pk, json):
    if len(request.FILES) == 0:
        return {
            "errors": {
                "file": [UploadEnforcementXML.Errors.NO_FILE]
            }
        }, HTTPStatus.BAD_REQUEST
    if len(request.FILES) != 1:
        return {
            "errors": {
                "file": [UploadEnforcementXML.Errors.MULTIPLE_FILES]
            }
        }, HTTPStatus.BAD_REQUEST
    if request.FILES["file"].size > ENFORCEMENT_XML_MAX_FILE_SIZE:
        return {
            "errors": {
                "file": [UploadEnforcementXML.Errors.FILE_TOO_LARGE]
            }
        }, HTTPStatus.BAD_REQUEST

    try:
        file = request.FILES.pop("file")[0]
        file_format = {"file": file.read().decode("utf-8")}
    except Exception:  # noqa
        return {
            "errors": {
                "file": [UploadEnforcementXML.Errors.FILE_READ]
            }
        }, HTTPStatus.BAD_REQUEST

    data = client.post(request, f"/cases/enforcement-check/{queue_pk}",
                       file_format)
    return data.json(), data.status_code
Example #4
0
def post_good_documents(request, pk, json):
    if "description" not in json:
        json["description"] = ""
    json = [json]

    data = client.post(request, f"/goods/{pk}/documents/", json)
    return data.json(), data.status_code
Example #5
0
def post_good_on_application(request, pk, json):
    good = None
    preexisting = str_to_bool(request.GET.get("preexisting"))
    if json.get("good_id"):
        good, _ = services.get_good(request, json["good_id"])
    post_data = serialize_good_on_app_data(json, good, preexisting)
    response = client.post(request, f"/applications/{pk}/goods/", post_data)
    return response.json(), response.status_code
Example #6
0
def _register_organisation(request, json, _type):
    data = {
        "type": _type,
        "user": {
            "email": request.session["email"]
        },
    }
    response = client.post(request, "/organisations/", {**json, **data})
    return response.json(), response.status_code
Example #7
0
def post_review_goods(request, case_id, json):
    json = {
        "objects": request.GET.getlist("goods", request.GET.getlist("goods_types")),
        "comment": request.POST.get("comment"),
        "control_list_entries": request.POST.getlist("control_list_entries[]", []),
        "is_good_controlled": request.POST.get("is_good_controlled") == "True",
        "report_summary": request.POST.get("report_summary"),
    }
    response = client.post(request, f"/goods/control-list-entries/{case_id}/", json)
    return response.json(), response.status_code
Example #8
0
def post_sites(request, organisation_id, json):
    if json.get("are_you_sure", True) == "None":
        return (
            {"errors": {"are_you_sure": [AddSiteForm.WhereIsYourSiteBased.EXISTING_SITE_ERROR]}},
            HTTPStatus.BAD_REQUEST,
        )

    if "location" not in json:
        return {"errors": {"location": [AddSiteForm.WhereIsYourSiteBased.ERROR]}}, HTTPStatus.BAD_REQUEST

    data = client.post(request, f"/organisations/{organisation_id}/sites/", json)
    return data.json(), data.status_code
Example #9
0
def post_external_locations(request, pk, json):
    organisation_id = request.session["organisation"]
    data = client.post(
        request, f"/organisations/{organisation_id}/external_locations/", json)

    if "errors" in data.json():
        return data.json(), data.status_code

    # Append the new external location to the list of external locations rather than clearing them
    _id = data.json()["external_location"]["id"]
    data = {"external_locations": [_id], "method": "append_location"}
    return post_external_locations_on_draft(request, str(pk), data)
Example #10
0
def post_organisations(request, json):
    errors = {}

    if not json.get("type"):
        errors["type"] = [RegisterAnOrganisation.CommercialOrIndividual.ERROR]

    if not json.get("location"):
        errors["location"] = [
            RegisterAnOrganisation.WhereIsTheExporterBased.ERROR
        ]

    if errors:
        return {"errors": errors}, HTTPStatus.BAD_REQUEST

    data = client.post(request, "/organisations/", json)
    return data.json(), data.status_code
Example #11
0
def post_open_licence_return(request, json):
    if not json.get("year"):
        return {
            "errors": {
                "year": [OpenReturnsForm.Year.ERROR]
            }
        }, HTTPStatus.BAD_REQUEST

    if len(request.FILES) == 0:
        return {
            "errors": {
                "file": [OpenReturnsForm.Upload.NO_FILE_ERROR]
            }
        }, HTTPStatus.BAD_REQUEST
    if len(request.FILES) != 1:
        return {
            "errors": {
                "file": [OpenReturnsForm.Upload.MULTIPLE_FILES_ERROR]
            }
        }, HTTPStatus.BAD_REQUEST
    if request.FILES[
            "file"].size > constants.MAX_OPEN_LICENCE_RETURNS_FILE_SIZE:
        return {
            "errors": {
                "file": [OpenReturnsForm.Upload.SIZE_ERROR]
            }
        }, HTTPStatus.BAD_REQUEST

    try:
        file = request.FILES.pop("file")[0]
        json["file"] = file.read().decode("utf-8")
    except Exception:  # noqa
        return {
            "errors": {
                "file": [OpenReturnsForm.Upload.READ_ERROR]
            }
        }, HTTPStatus.BAD_REQUEST

    data = client.post(request, "/compliance/open-licence-returns/", json)
    return data.json(), data.status_code
Example #12
0
def post_goods(request, json):
    json["item_category"] = json.get("item_category", "group2_firearms")

    if "is_pv_graded" in json and json["is_pv_graded"] == "yes":
        if "reference" in json:
            json["pv_grading_details"] = {
                "grading": json["grading"],
                "custom_grading": json["custom_grading"],
                "prefix": json["prefix"],
                "suffix": json["suffix"],
                "issuing_authority": json["issuing_authority"],
                "reference": json["reference"],
                "date_of_issue": format_date(json, "date_of_issue"),
            }

    if "item_category" in json and json["item_category"] == "group2_firearms":
        add_firearm_details_to_data(json)

    data = client.post(request, "/goods/", json)

    if data.status_code == HTTPStatus.OK:
        data.json().get("good"), data.status_code
    return data.json(), data.status_code
Example #13
0
def post_picklist_item(request, json):
    data = client.post(request, "/picklist/", json)
    return data.json(), data.status_code
Example #14
0
def post_letter_template(request, json):
    data = client.post(request, "/letter-templates/", json)
    return data.json(), data.status_code
Example #15
0
def raise_goods_query(request, pk, json):
    post_data = json
    post_data["good_id"] = pk

    data = client.post(request, "/queries/goods-queries/", post_data)
    return data.json(), data.status_code
Example #16
0
def post_routing_rule(request, json):
    data = _remove_none_from_post_data_additional_rules_list(json)
    data = convert_flags_to_list(data)
    response = client.post(request, "/routing-rules/", data)
    return response.json(), response.status_code
Example #17
0
def create_spire_product_comment(request, pk, data):
    response = client.post(request, f"/search/product/spire/{pk}/comment/", data)
    response.raise_for_status()
    return response.json()
Example #18
0
def post_role(request, json):
    data = client.post(request, "/gov-users/roles/", json)
    return data.json(), data.status_code
Example #19
0
def upload_denials(request, data):
    return client.post(
        request=request,
        appended_address="/external-data/denial/",
        data=data,
    )
Example #20
0
def post_good_document_sensitivity(request, pk, json):
    data = client.post(request, f"/goods/{pk}/document-sensitivity/", json)
    return data.json(), data.status_code
Example #21
0
def post_open_general_licence_cases(request, json):
    data = client.post(request, "/licences/open-general-licences/", json)
    return data.json(), data.status_code
Example #22
0
def post_ecju_query_document(request, pk, query_pk, json):
    response = client.post(request, f"/cases/{pk}/ecju-queries/{query_pk}/document/", json)
    response.raise_for_status()
    return response.json(), response.status_code
Example #23
0
def post_hmrc_organisations(request, json):
    data = client.post(request, "/organisations/", json)
    return data.json(), data.status_code
Example #24
0
def post_queues(request, json):
    data = client.post(request, "/queues/", json)
    return data.json(), data.status_code
Example #25
0
def post_gov_users(request, json):
    json.setdefault("first_name", "")
    json.setdefault("last_name", "")
    data = client.post(request, "/gov-users/", json)
    return data.json(), data.status_code
Example #26
0
def post_sites_on_draft(request, pk, json):
    data = client.post(request, f"/applications/{pk}/sites/", json)
    return data.json(), data.status_code
Example #27
0
def post_enforcement_xml(request, queue_pk, json):
    response = client.post(request, f"/cases/enforcement-check/{queue_pk}", json)
    return response
Example #28
0
def post_external_locations_on_draft(request, pk, json):
    data = client.post(request, f"/applications/{pk}/external_locations/",
                       json)
    return data.json(), data.status_code
Example #29
0
def authenticate_gov_user(request, json):
    data = client.post(request, "/gov-users/authenticate/", json)
    return data.json(), data.status_code
Example #30
0
def authenticate_exporter_user(request, json):
    data = client.post(request, "/users/authenticate/", json)
    return data.json(), data.status_code