Пример #1
0
def test_return_formatted_response_code_message_and_errors():
    response = MockResponse(
        status_code=400,
        text=json.dumps({
            "code":
            "SOME_CODE",
            "message":
            "some message",
            "errors": [
                {
                    "property": "some.property",
                    "message": "some message"
                },
                {
                    "property": "some.other.property",
                    "message": "some other message",
                },
            ],
        }),
        headers={"Content-Type": "application/json"},
    )
    exception = DocScanException("some error", response)

    assert (
        exception.message ==
        'some error - SOME_CODE - some message: some.property "some message", some.other.property "some other message"'
    )
Пример #2
0
def mocked_request_media_content():
    return MockResponse(
        status_code=200,
        text="someContent",
        content=b"someContent",
        headers={"Content-Type": "application/json"},
    )
def test_return_formatted_response_code_and_message():
    response = MockResponse(
        status_code=400,
        text=json.dumps({"code": "SOME_CODE", "message": "some message"}),
        headers={"Content-Type": "application/json"},
    )
    exception = DocScanSandboxException("some error", response)

    assert exception.message == "some error - SOME_CODE - some message"
def test_return_only_message_when_json_response_has_no_message_property():
    response = MockResponse(
        status_code=400,
        text=json.dumps({}),
        headers={"Content-Type": "application/json"},
    )
    exception = DocScanSandboxException("some error", response)

    assert exception.message == "some error"
def test_return_only_message_when_html_response():
    response = MockResponse(
        status_code=400,
        text="<html>some html</html>",
        headers={"Content-Type": "text/html"},
    )
    exception = DocScanSandboxException("some error", response)

    assert exception.message == "some error"
def test_excludes_errors_without_property_or_message():
    response = MockResponse(
        status_code=400,
        text=json.dumps(
            {
                "code": "SOME_CODE",
                "message": "some message",
                "errors": [
                    {"message": "some message"},
                    {"property": "some.other.property"},
                ],
            }
        ),
        headers={"Content-Type": "application/json"},
    )
    exception = DocScanSandboxException("some error", response)

    assert exception.message == "some error - SOME_CODE - some message"
Пример #7
0
def mocked_request_successful_session_creation():
    with open(FIXTURES_DIR + "/session_create_success.txt", "r") as f:
        response = f.read()
    return MockResponse(status_code=201, text=response)
Пример #8
0
def mocked_request_server_error():
    return MockResponse(status_code=500, text="")
Пример #9
0
def mocked_supported_documents_content():
    with open(FIXTURES_DIR + "/supported_documents_success.txt", "r") as f:
        response = f.read()
    return MockResponse(status_code=200, text=response)
Пример #10
0
def mocked_request_missing_content():
    return MockResponse(status_code=404, text="")
Пример #11
0
def mocked_request_failed_session_retrieval():
    return MockResponse(status_code=400, text="")
Пример #12
0
def mocked_request_successful_session_retrieval():
    with open(FIXTURES_DIR + "/retrieve_session_success.txt", "r") as f:
        response = f.read()
    return MockResponse(status_code=200, text=response)
Пример #13
0
def mocked_request_failed_session_creation():
    with open(FIXTURES_DIR + "/failed_request.txt", "r") as f:
        response = f.read()
    return MockResponse(status_code=400, text=response)
def test_return_message():
    response = MockResponse(status_code=400, text="some response")
    exception = DocScanSandboxException("some error", response)

    assert exception.message == "some error"
def test_return_content():
    response = MockResponse(status_code=400, text="", content="some content")
    exception = DocScanSandboxException("some error", response)

    assert exception.content == "some content"