Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 11
0
def pytest_runtest_logstart(nodeid, location):
    DummyResponseBuilder().set_default_state()
Ejemplo n.º 12
0
def response():
    response = DummyResponseBuilder().method().code().header({}).body()
    return response
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 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