|
17 | 17 | from openapi_core.schema.responses.models import Response |
18 | 18 | from openapi_core.schema.schemas.exceptions import ( |
19 | 19 | UndefinedSchemaProperty, MissingSchemaProperty, NoOneOfSchema, |
| 20 | + NoValidSchema, |
20 | 21 | ) |
21 | 22 | from openapi_core.schema.schemas.models import Schema |
22 | 23 | from openapi_core.schema.servers.exceptions import InvalidServer |
@@ -1032,3 +1033,143 @@ def test_post_tags_additional_properties( |
1032 | 1033 | assert response_result.data.message == message |
1033 | 1034 | assert response_result.data.rootCause == rootCause |
1034 | 1035 | assert response_result.data.additionalinfo == additionalinfo |
| 1036 | + |
| 1037 | + def test_post_tags_created_now( |
| 1038 | + self, spec, response_validator): |
| 1039 | + host_url = 'http://petstore.swagger.io/v1' |
| 1040 | + path_pattern = '/v1/tags' |
| 1041 | + created = 'now' |
| 1042 | + pet_name = 'Dog' |
| 1043 | + data_json = { |
| 1044 | + 'created': created, |
| 1045 | + 'name': pet_name, |
| 1046 | + } |
| 1047 | + data = json.dumps(data_json) |
| 1048 | + |
| 1049 | + request = MockRequest( |
| 1050 | + host_url, 'POST', '/tags', |
| 1051 | + path_pattern=path_pattern, data=data, |
| 1052 | + ) |
| 1053 | + |
| 1054 | + parameters = request.get_parameters(spec) |
| 1055 | + body = request.get_body(spec) |
| 1056 | + |
| 1057 | + assert parameters == {} |
| 1058 | + assert isinstance(body, BaseModel) |
| 1059 | + assert body.created == created |
| 1060 | + assert body.name == pet_name |
| 1061 | + |
| 1062 | + code = 400 |
| 1063 | + message = 'Bad request' |
| 1064 | + rootCause = 'Tag already exist' |
| 1065 | + additionalinfo = 'Tag Dog already exist' |
| 1066 | + data_json = { |
| 1067 | + 'code': 400, |
| 1068 | + 'message': 'Bad request', |
| 1069 | + 'rootCause': 'Tag already exist', |
| 1070 | + 'additionalinfo': 'Tag Dog already exist', |
| 1071 | + } |
| 1072 | + data = json.dumps(data_json) |
| 1073 | + response = MockResponse(data, status_code=404) |
| 1074 | + |
| 1075 | + response_result = response_validator.validate(request, response) |
| 1076 | + |
| 1077 | + assert response_result.errors == [] |
| 1078 | + assert isinstance(response_result.data, BaseModel) |
| 1079 | + assert response_result.data.code == code |
| 1080 | + assert response_result.data.message == message |
| 1081 | + assert response_result.data.rootCause == rootCause |
| 1082 | + assert response_result.data.additionalinfo == additionalinfo |
| 1083 | + |
| 1084 | + def test_post_tags_created_datetime( |
| 1085 | + self, spec, response_validator): |
| 1086 | + host_url = 'http://petstore.swagger.io/v1' |
| 1087 | + path_pattern = '/v1/tags' |
| 1088 | + created = '2016-04-16T16:06:05Z' |
| 1089 | + pet_name = 'Dog' |
| 1090 | + data_json = { |
| 1091 | + 'created': created, |
| 1092 | + 'name': pet_name, |
| 1093 | + } |
| 1094 | + data = json.dumps(data_json) |
| 1095 | + |
| 1096 | + request = MockRequest( |
| 1097 | + host_url, 'POST', '/tags', |
| 1098 | + path_pattern=path_pattern, data=data, |
| 1099 | + ) |
| 1100 | + |
| 1101 | + parameters = request.get_parameters(spec) |
| 1102 | + body = request.get_body(spec) |
| 1103 | + |
| 1104 | + assert parameters == {} |
| 1105 | + assert isinstance(body, BaseModel) |
| 1106 | + assert body.created == created |
| 1107 | + assert body.name == pet_name |
| 1108 | + |
| 1109 | + code = 400 |
| 1110 | + message = 'Bad request' |
| 1111 | + rootCause = 'Tag already exist' |
| 1112 | + additionalinfo = 'Tag Dog already exist' |
| 1113 | + data_json = { |
| 1114 | + 'code': code, |
| 1115 | + 'message': message, |
| 1116 | + 'rootCause': rootCause, |
| 1117 | + 'additionalinfo': additionalinfo, |
| 1118 | + } |
| 1119 | + data = json.dumps(data_json) |
| 1120 | + response = MockResponse(data, status_code=404) |
| 1121 | + |
| 1122 | + response_result = response_validator.validate(request, response) |
| 1123 | + |
| 1124 | + assert response_result.errors == [] |
| 1125 | + assert isinstance(response_result.data, BaseModel) |
| 1126 | + assert response_result.data.code == code |
| 1127 | + assert response_result.data.message == message |
| 1128 | + assert response_result.data.rootCause == rootCause |
| 1129 | + assert response_result.data.additionalinfo == additionalinfo |
| 1130 | + |
| 1131 | + @pytest.mark.xfail(reason='OneOf for string not supported atm') |
| 1132 | + def test_post_tags_created_invalid_type( |
| 1133 | + self, spec, response_validator): |
| 1134 | + host_url = 'http://petstore.swagger.io/v1' |
| 1135 | + path_pattern = '/v1/tags' |
| 1136 | + created = 'long time ago' |
| 1137 | + pet_name = 'Dog' |
| 1138 | + data_json = { |
| 1139 | + 'created': created, |
| 1140 | + 'name': pet_name, |
| 1141 | + } |
| 1142 | + data = json.dumps(data_json) |
| 1143 | + |
| 1144 | + request = MockRequest( |
| 1145 | + host_url, 'POST', '/tags', |
| 1146 | + path_pattern=path_pattern, data=data, |
| 1147 | + ) |
| 1148 | + |
| 1149 | + parameters = request.get_parameters(spec) |
| 1150 | + with pytest.raises(NoValidSchema): |
| 1151 | + request.get_body(spec) |
| 1152 | + |
| 1153 | + assert parameters == {} |
| 1154 | + |
| 1155 | + code = 400 |
| 1156 | + message = 'Bad request' |
| 1157 | + rootCause = 'Tag already exist' |
| 1158 | + additionalinfo = 'Tag Dog already exist' |
| 1159 | + data_json = { |
| 1160 | + 'code': code, |
| 1161 | + 'message': message, |
| 1162 | + 'rootCause': rootCause, |
| 1163 | + 'additionalinfo': additionalinfo, |
| 1164 | + } |
| 1165 | + data = json.dumps(data_json) |
| 1166 | + response = MockResponse(data, status_code=404) |
| 1167 | + |
| 1168 | + response_result = response_validator.validate(request, response) |
| 1169 | + |
| 1170 | + assert response_result.errors == [] |
| 1171 | + assert isinstance(response_result.data, BaseModel) |
| 1172 | + assert response_result.data.code == code |
| 1173 | + assert response_result.data.message == message |
| 1174 | + assert response_result.data.rootCause == rootCause |
| 1175 | + assert response_result.data.additionalinfo == additionalinfo |
0 commit comments