Example #1
0
def test_status_code_converter_as_mixin():
    orig_response = DummyResponseBuilder().method().code(500).body()
    converted_response = TestEndpointBuilder._TestResponseModel(
        config).convert_raw_response(orig_response)
    assert converted_response.status_code == orig_response.status_code
    assert exclude_fields_from_obj(converted_response, affected_fields_error) == \
           exclude_fields_from_obj(TestEndpointBuilder._TestResponseModel(config), affected_fields_error)
Example #2
0
def test_headers_converter_as_mixin():
    orig_response = DummyResponseBuilder().method().code().body()
    converted_response = TestEndpointBuilder._TestResponseModel(
        config).convert_raw_response(orig_response)
    assert converted_response.headers == orig_response.headers
    assert exclude_fields_from_obj(converted_response, affected_fields_get) == \
           exclude_fields_from_obj(TestEndpointBuilder._TestResponseModel(config), affected_fields_get)
Example #3
0
def test_body_json_converter_error_status_code():
    test_body = {"testField": "testValue"}
    orig_response = DummyResponseBuilder().method().code(500).body(
        json.dumps(test_body))
    converted_response = ResponseConverterMixin().convert_raw_response(
        orig_response)
    assert converted_response.error_data == json.dumps(test_body)
Example #4
0
def test_body_json_converter_no_mime_type_provided():
    test_body = {"testField": "testValue"}
    orig_response = DummyResponseBuilder().method().code().body(
        json.dumps(test_body))
    converted_response = ResponseConverterMixin().convert_raw_response(
        orig_response)
    assert converted_response.get_data == json.dumps(test_body)
Example #5
0
def test_body_json_converter_as_mixin_error_status_code():
    test_body = "testField = testValue"
    orig_response = DummyResponseBuilder().method().code(500).body(test_body)
    converted_response = TestEndpointBuilder._TestResponseModel(
        config).convert_raw_response(orig_response)
    assert converted_response.error_data == test_body
    assert exclude_fields_from_obj(converted_response, affected_fields_error) == \
           exclude_fields_from_obj(TestEndpointBuilder._TestResponseModel(config), affected_fields_error)
Example #6
0
def test_body_json_converter_invalid_body():
    test_body = "testField = testValue"
    orig_response = DummyResponseBuilder().method().code().header({
        "Content-Type":
        "application/json"
    }).body(test_body)
    with pytest.raises(TypeError) as excinfo:
        ResponseConverterMixin().convert_raw_response(orig_response)
    assert f"Incorrect json format: {test_body}" in str(excinfo.value)
Example #7
0
def test_body_json_converter_not_json_mime_type():
    test_body = {"testField": "testValue"}
    orig_response = DummyResponseBuilder().method().code().header({
        "Content-Type":
        "text/plain"
    }).body(json.dumps(test_body))
    converted_response = ResponseConverterMixin().convert_raw_response(
        orig_response)
    assert converted_response.get_data == json.dumps(test_body)
Example #8
0
def test_body_json_converter_valid_value():
    test_body = {"testField": "testValue"}
    orig_response = DummyResponseBuilder().method().code().header({
        "Content-Type":
        "application/json"
    }).body(json.dumps(test_body))
    converted_response = ResponseConverterMixin().convert_raw_response(
        orig_response)
    assert converted_response.get_data == test_body
Example #9
0
def test_body_json_converter_as_mixin_no_mime_type_provided():
    test_body = {"testField": "testValue"}
    orig_response = DummyResponseBuilder().method().code().body(
        json.dumps(test_body))
    converted_response = TestEndpointBuilder._TestResponseModel(
        config).convert_raw_response(orig_response)
    assert converted_response.get_data == json.dumps(test_body)
    assert exclude_fields_from_obj(converted_response, affected_fields_get) == \
           exclude_fields_from_obj(TestEndpointBuilder._TestResponseModel(config), affected_fields_get)
Example #10
0
def test_body_json_converter_as_mixin_valid_value():
    test_body = {"testField": "testValue"}
    orig_response = DummyResponseBuilder().method().code().header({
        "Content-Type":
        "application/json"
    }).body(json.dumps(test_body))
    converted_response = TestEndpointBuilder._TestResponseModel(
        config).convert_raw_response(orig_response)
    assert converted_response.get_data == test_body
    assert exclude_fields_from_obj(converted_response, affected_fields_get) == \
           exclude_fields_from_obj(TestEndpointBuilder._TestResponseModel(config), affected_fields_get)
Example #11
0
def pytest_runtest_logstart(nodeid, location):
    DummyResponseBuilder().set_default_state()
Example #12
0
def response():
    response = DummyResponseBuilder().method().code().header({}).body()
    return response
Example #13
0
def test_converter_raw_response():
    orig_response = DummyResponseBuilder().method().code(500).body(
        "asd: asd").header({"Content-Type": "text/plain"})
    converted_response = ResponseConverterMixin().convert_raw_response(
        orig_response)
    assert converted_response.raw_response == orig_response
Example #14
0
def test_headers_converter():
    orig_response = DummyResponseBuilder().method().code().body()
    converted_response = ResponseConverterMixin().convert_raw_response(
        orig_response)
    assert converted_response.headers == orig_response.headers
Example #15
0
def test_status_code_converter():
    orig_response = DummyResponseBuilder().method().code(500).body()
    converted_response = ResponseConverterMixin().convert_raw_response(
        orig_response)
    assert converted_response.status_code == orig_response.status_code