def test_json_body_nested_mixed_valid_values(self, _, response, builder, method): test_body = { "testKey1": "testValue1", "testKey2": 2, "testKey3": True, "testKey4": [0, 1, "false", False], "testKey5": [ { "nestedKey1": "nestedValue1", "nestedKey2": 2, "nestedKey4": [0, 1, "false", False] }, { "nested2Key1": "nestedValue1", "nested2Key2": 2, "nested2Key4": [0, 1, "false", False] }, ] } setattr(builder.endpoint.response_model, f"{method}_data", test_body) builder.endpoint.request_model.allowed_methods = (method, ) response.body(test_body) response.method(method) try: getattr(builder.endpoint, method)() except Exception as e: pytest.fail(f"DID RAISE {e}")
def test_list_body_skip_value(self, _, response, builder, method): test_body = [SKIP, "testValue2"] setattr(builder.endpoint.response_model, f"{method}_data", test_body) builder.endpoint.request_model.allowed_methods = (method, ) response.body(["testValue3", "testValue2"]) response.method(method) try: getattr(builder.endpoint, method)() except Exception as e: pytest.fail(f"DID RAISE {e}")
def test_json_body_list_invalid_value(self, _, response, builder, method): test_body = {"testKey1": ["testValue1"]} setattr(builder.endpoint.response_model, f"{method}_data", test_body) builder.endpoint.request_model.allowed_methods = (method, ) response.body({"testKey1": ["testValue2"]}) response.method(method) with pytest.raises(RestResponseValidationError) as excinfo: getattr(builder.endpoint, method)() assert f"Field '{method}_data->testKey1->0', expected value 'testValue1', but got 'testValue2'" \ in str(excinfo.value)
def test_json_body_list_valid_value(self, _, response, builder, method): test_body = {"testKey1": ["testValue1"]} setattr(builder.endpoint.response_model, f"{method}_data", test_body) builder.endpoint.request_model.allowed_methods = (method, ) response.body(test_body) response.method(method) try: getattr(builder.endpoint, method)() except Exception as e: pytest.fail(f"DID RAISE {e}")
def test_list_body_skip_and_invalid_values(self, _, response, builder, method): test_body = [SKIP, "testValue2"] setattr(builder.endpoint.response_model, f"{method}_data", test_body) builder.endpoint.request_model.allowed_methods = (method, ) response.body(["testValue2", "testValue1"]) response.method(method) with pytest.raises(RestResponseValidationError) as excinfo: getattr(builder.endpoint, method)() assert f"Field '{method}_data->1', expected value 'testValue2', but got 'testValue1'" in str( excinfo.value)
def test_json_body_nested_mixed_valid_invalid_values( self, _, response, builder, method): expected_body = { "testKey1": "testValue1", "testKey2": 2, "testKey3": True, "testKey4": [0, 1, "false", False, SKIP], "testKey5": [ { "nestedKey1": "nestedValue1", "nestedKey2": 2, "nestedKey4": [0, 1, "false", False] }, { "nested2Key1": "nestedValue1", "nested2Key2": 2, "nested2Key3": SKIP, "nested2Key4": [0, 1, "false", False] }, ], "testKey6": SKIP } actual_body = { "testKey1": "testValue4", "testKey2": None, "testKey3": False, "testKey4": [0, 2, "true", False, "skippedListValue"], "testKey5": [ { "nested2Key1": "nestedValue5", "nested2Key2": 2.2, "nested2Key3": "skippedNestedValue", "nested2Key4": [0, 1.2, "false", "false"] }, ], "testKey6": "skippedKeyValue" } setattr(builder.endpoint.response_model, f"{method}_data", expected_body) builder.endpoint.request_model.allowed_methods = (method, ) response.body(actual_body) response.method(method) with pytest.raises(RestResponseValidationError) as excinfo: getattr(builder.endpoint, method)() assert f"Field '{method}_data->testKey1', expected value 'testValue1', but got 'testValue4'" \ in str(excinfo.value) assert f"Field '{method}_data->testKey2', expected value '2', but got 'None'" in str( excinfo.value) assert f"Field '{method}_data->testKey3', expected value 'True', but got 'False'" in str( excinfo.value) assert f"Field '{method}_data->testKey4->1', expected value '1', but got '2'" in str( excinfo.value) assert f"Field '{method}_data->testKey4->2', expected value 'false', but got 'true'" in str( excinfo.value) assert f"Field '{method}_data->testKey5->0->nestedKey1', expected value 'nestedValue1', " \ f"but got 'field does not present in response'" in str(excinfo.value) assert f"Field '{method}_data->testKey5->0->nestedKey2', expected value '2', " \ f"but got 'field does not present in response'" in str(excinfo.value) assert f"Field '{method}_data->testKey5->0->nestedKey4', expected value " \ f"'{expected_body['testKey5'][0]['nestedKey4']}', " \ f"but got 'field does not present in response'" in str(excinfo.value) assert f"Field '{method}_data->testKey5->1', expected value '{expected_body['testKey5']}', " \ f"but got '{actual_body['testKey5']}'" in str(excinfo.value)