How to use the ariadne.file_uploads.combine_multipart_data function in ariadne

To help you get started, we’ve selected a few ariadne examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mirumee / ariadne / tests / test_file_uploads.py View on Github external
def test_files_are_set_in_multiple_variables():
    operations = {"variables": {"fileA": None, "fileB": None}}
    files_map = {"0": ["variables.fileA"], "1": ["variables.fileB"]}
    files = {"0": "A", "1": "B"}

    assert combine_multipart_data(operations, files_map, files) == {
        "variables": {"fileA": "A", "fileB": "B"}
    }
github mirumee / ariadne / tests / test_file_uploads.py View on Github external
def test_single_file_is_set_in_multiple_variables():
    operations = {"variables": {"fileA": None, "fileB": None}}
    files_map = {"0": ["variables.fileA", "variables.fileB"]}
    files = {"0": True}

    assert combine_multipart_data(operations, files_map, files) == {
        "variables": {"fileA": True, "fileB": True}
    }
github mirumee / ariadne / tests / test_file_uploads.py View on Github external
def test_error_is_raised_if_file_paths_value_is_not_a_list():
    operations = {"variables": {"file": None}}
    files_map = {"0": "variables.file"}
    files = {"0": True}

    with pytest.raises(HttpBadRequestError):
        assert combine_multipart_data(operations, files_map, files)
github mirumee / ariadne / tests / test_file_uploads.py View on Github external
def test_error_is_raised_if_file_described_in_map_is_not_found():
    operations = {"variables": {"file": None}}
    files_map = {"0": ["variables.file"]}
    files = {}

    with pytest.raises(HttpBadRequestError):
        assert combine_multipart_data(operations, files_map, files)
github mirumee / ariadne / ariadne / wsgi.py View on Github external
raise HttpBadRequestError("Malformed request data")

        try:
            operations = json.loads(form.getvalue("operations"))
        except (TypeError, ValueError):
            raise HttpBadRequestError(
                "Request 'operations' multipart field is not a valid JSON"
            )
        try:
            files_map = json.loads(form.getvalue("map"))
        except (TypeError, ValueError):
            raise HttpBadRequestError(
                "Request 'map' multipart field is not a valid JSON"
            )

        return combine_multipart_data(operations, files_map, form)
github mirumee / ariadne / ariadne / contrib / django / views.py View on Github external
def extract_data_from_multipart_request(self, request: HttpRequest):
        try:
            operations = json.loads(request.POST.get("operations"))
        except (TypeError, ValueError):
            raise HttpBadRequestError(
                "Request 'operations' multipart field is not a valid JSON"
            )
        try:
            files_map = json.loads(request.POST.get("map"))
        except (TypeError, ValueError):
            raise HttpBadRequestError(
                "Request 'map' multipart field is not a valid JSON"
            )

        return combine_multipart_data(operations, files_map, request.FILES)
github mirumee / ariadne / ariadne / wsgi.py View on Github external
raise HttpBadRequestError("Malformed request data")

        try:
            operations = json.loads(form.getvalue("operations"))
        except (TypeError, ValueError):
            raise HttpBadRequestError(
                "Request 'operations' multipart field is not a valid JSON"
            )
        try:
            files_map = json.loads(form.getvalue("map"))
        except (TypeError, ValueError):
            raise HttpBadRequestError(
                "Request 'map' multipart field is not a valid JSON"
            )

        return combine_multipart_data(operations, files_map, form)