Skip to content

Commit 966be98

Browse files
committed
fix tests after adding request bodies feature
1 parent 6105da6 commit 966be98

File tree

5 files changed

+82
-19
lines changed

5 files changed

+82
-19
lines changed

tests/test_cli.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import pytest
55
from typer.testing import CliRunner
66

7-
from openapi_python_client import Config
87
from openapi_python_client.parser.errors import GeneratorError, ParseError
98

109
runner = CliRunner()
@@ -149,7 +148,7 @@ def test_generate_encoding(self, _create_new_client):
149148
def test_generate_encoding_errors(self, _create_new_client):
150149
path = "cool/path"
151150
file_encoding = "error-file-encoding"
152-
from openapi_python_client.cli import MetaType, app
151+
from openapi_python_client.cli import app
153152

154153
result = runner.invoke(app, ["generate", f"--path={path}", f"--file-encoding={file_encoding}"])
155154

@@ -286,7 +285,7 @@ def test_update_encoding(self, _update_existing_client):
286285
def test_update_encoding_errors(self, _update_existing_client):
287286
path = "cool/path"
288287
file_encoding = "error-file-encoding"
289-
from openapi_python_client.cli import MetaType, app
288+
from openapi_python_client.cli import app
290289

291290
result = runner.invoke(app, ["update", f"--path={path}", f"--file-encoding={file_encoding}"])
292291

tests/test_parser/test_openapi.py

Lines changed: 75 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from openapi_python_client import Config, GeneratorError
88
from openapi_python_client.parser.errors import ParseError
99
from openapi_python_client.parser.openapi import Endpoint, EndpointCollection
10-
from openapi_python_client.parser.properties import IntProperty, Parameters, Schemas
10+
from openapi_python_client.parser.properties import IntProperty, Parameters, Schemas, RequestBodies
1111

1212
MODULE_NAME = "openapi_python_client.parser.openapi"
1313

@@ -18,6 +18,7 @@ def test_from_dict(self, mocker, model_property_factory, enum_property_factory):
1818

1919
build_schemas = mocker.patch(f"{MODULE_NAME}.build_schemas")
2020
build_parameters = mocker.patch(f"{MODULE_NAME}.build_parameters")
21+
build_request_bodies = mocker.patch(f"{MODULE_NAME}.build_request_bodies")
2122
EndpointCollection = mocker.patch(f"{MODULE_NAME}.EndpointCollection")
2223
schemas = mocker.MagicMock()
2324
schemas.classes_by_name = {
@@ -48,6 +49,7 @@ def test_from_dict(self, mocker, model_property_factory, enum_property_factory):
4849
data=openapi.paths,
4950
schemas=build_schemas.return_value,
5051
parameters=build_parameters.return_value,
52+
request_bodies=build_request_bodies.return_value,
5153
config=config,
5254
)
5355
assert generator_data.title == openapi.info.title
@@ -279,8 +281,13 @@ def test_add_body_no_data(self, mocker):
279281
parse_request_form_body = mocker.patch.object(Endpoint, "parse_request_form_body")
280282
endpoint = self.make_endpoint()
281283
schemas = Schemas()
282-
283-
Endpoint._add_body(endpoint=endpoint, data=oai.Operation.construct(), schemas=schemas, config=MagicMock())
284+
Endpoint._add_body(
285+
endpoint=endpoint,
286+
data=oai.Operation.construct(),
287+
schemas=schemas,
288+
request_bodies=RequestBodies(),
289+
config=MagicMock(),
290+
)
284291

285292
parse_request_form_body.assert_not_called()
286293

@@ -299,6 +306,7 @@ def test_add_body_bad_json_data(self, mocker):
299306
endpoint=endpoint,
300307
data=oai.Operation.construct(requestBody=request_body),
301308
schemas=schemas,
309+
request_bodies=(RequestBodies()),
302310
config=MagicMock(),
303311
)
304312

@@ -328,6 +336,7 @@ def test_add_body_bad_form_data(self, enum_property_factory):
328336
)
329337
),
330338
schemas=schemas,
339+
request_bodies=RequestBodies(),
331340
config=Config(),
332341
)
333342

@@ -356,6 +365,7 @@ def test_add_body_bad_multipart_data(self, mocker):
356365
endpoint=endpoint,
357366
data=oai.Operation.construct(requestBody=request_body),
358367
schemas=schemas,
368+
request_bodies=RequestBodies(),
359369
config=MagicMock(),
360370
)
361371

@@ -406,6 +416,7 @@ def test_add_body_happy(self, mocker):
406416
endpoint=endpoint,
407417
data=oai.Operation.construct(requestBody=request_body),
408418
schemas=initial_schemas,
419+
request_bodies=RequestBodies(),
409420
config=config,
410421
)
411422

@@ -984,6 +995,7 @@ def test_from_data_bad_params(self, mocker):
984995
tag="default",
985996
schemas=initial_schemas,
986997
parameters=parameters,
998+
request_bodies=RequestBodies(),
987999
config=config,
9881000
)
9891001

@@ -1019,6 +1031,7 @@ def test_from_data_bad_responses(self, mocker):
10191031
tag="default",
10201032
schemas=initial_schemas,
10211033
parameters=initial_parameters,
1034+
request_bodies=RequestBodies(),
10221035
config=config,
10231036
)
10241037

@@ -1051,6 +1064,7 @@ def test_from_data_standard(self, mocker):
10511064
)
10521065
initial_schemas = mocker.MagicMock()
10531066
initial_parameters = mocker.MagicMock()
1067+
request_bodies = RequestBodies()
10541068
config = MagicMock()
10551069

10561070
mocker.patch("openapi_python_client.utils.remove_string_escapes", return_value=data.description)
@@ -1062,6 +1076,7 @@ def test_from_data_standard(self, mocker):
10621076
tag="default",
10631077
schemas=initial_schemas,
10641078
parameters=initial_parameters,
1079+
request_bodies=request_bodies,
10651080
config=config,
10661081
)
10671082

@@ -1086,7 +1101,11 @@ def test_from_data_standard(self, mocker):
10861101
endpoint=param_endpoint, data=data.responses, schemas=param_schemas, config=config
10871102
)
10881103
_add_body.assert_called_once_with(
1089-
endpoint=response_endpoint, data=data, schemas=response_schemas, config=config
1104+
endpoint=response_endpoint,
1105+
data=data,
1106+
schemas=response_schemas,
1107+
request_bodies=request_bodies,
1108+
config=config,
10901109
)
10911110

10921111
def test_from_data_no_operation_id(self, mocker):
@@ -1111,9 +1130,17 @@ def test_from_data_no_operation_id(self, mocker):
11111130
mocker.patch("openapi_python_client.utils.remove_string_escapes", return_value=data.description)
11121131
config = MagicMock()
11131132
parameters = mocker.MagicMock()
1133+
request_bodies = mocker.MagicMock()
11141134

11151135
endpoint, return_schemas, return_params = Endpoint.from_data(
1116-
data=data, path=path, method=method, tag="default", schemas=schemas, parameters=parameters, config=config
1136+
data=data,
1137+
path=path,
1138+
method=method,
1139+
tag="default",
1140+
schemas=schemas,
1141+
parameters=parameters,
1142+
request_bodies=request_bodies,
1143+
config=config,
11171144
)
11181145

11191146
assert (endpoint, return_schemas) == _add_body.return_value
@@ -1140,7 +1167,11 @@ def test_from_data_no_operation_id(self, mocker):
11401167
config=config,
11411168
)
11421169
_add_body.assert_called_once_with(
1143-
endpoint=_add_responses.return_value[0], data=data, schemas=_add_responses.return_value[1], config=config
1170+
endpoint=_add_responses.return_value[0],
1171+
data=data,
1172+
schemas=_add_responses.return_value[1],
1173+
request_bodies=request_bodies,
1174+
config=config,
11441175
)
11451176

11461177
def test_from_data_no_security(self, mocker):
@@ -1164,10 +1195,18 @@ def test_from_data_no_security(self, mocker):
11641195
mocker.patch("openapi_python_client.utils.remove_string_escapes", return_value=data.description)
11651196
schemas = mocker.MagicMock()
11661197
parameters = mocker.MagicMock()
1198+
request_bodies = mocker.MagicMock()
11671199
config = MagicMock()
11681200

11691201
Endpoint.from_data(
1170-
data=data, path=path, method=method, tag="a", schemas=schemas, parameters=parameters, config=config
1202+
data=data,
1203+
path=path,
1204+
method=method,
1205+
tag="a",
1206+
schemas=schemas,
1207+
parameters=parameters,
1208+
request_bodies=request_bodies,
1209+
config=config,
11711210
)
11721211

11731212
add_parameters.assert_called_once_with(
@@ -1192,7 +1231,11 @@ def test_from_data_no_security(self, mocker):
11921231
config=config,
11931232
)
11941233
_add_body.assert_called_once_with(
1195-
endpoint=_add_responses.return_value[0], data=data, schemas=_add_responses.return_value[1], config=config
1234+
endpoint=_add_responses.return_value[0],
1235+
data=data,
1236+
schemas=_add_responses.return_value[1],
1237+
request_bodies=request_bodies,
1238+
config=config,
11961239
)
11971240

11981241
@pytest.mark.parametrize(
@@ -1261,9 +1304,12 @@ def test_from_data(self, mocker):
12611304
)
12621305
schemas = mocker.MagicMock()
12631306
parameters = mocker.MagicMock()
1307+
request_bodies = mocker.MagicMock()
12641308
config = MagicMock()
12651309

1266-
result = EndpointCollection.from_data(data=data, schemas=schemas, parameters=parameters, config=config)
1310+
result = EndpointCollection.from_data(
1311+
data=data, schemas=schemas, parameters=parameters, request_bodies=request_bodies, config=config
1312+
)
12671313

12681314
endpoint_from_data.assert_has_calls(
12691315
[
@@ -1274,6 +1320,7 @@ def test_from_data(self, mocker):
12741320
tag="default",
12751321
schemas=schemas,
12761322
parameters=parameters,
1323+
request_bodies=request_bodies,
12771324
config=config,
12781325
),
12791326
mocker.call(
@@ -1283,6 +1330,7 @@ def test_from_data(self, mocker):
12831330
tag="tag_2",
12841331
schemas=schemas_1,
12851332
parameters=parameters_1,
1333+
request_bodies=request_bodies,
12861334
config=config,
12871335
),
12881336
mocker.call(
@@ -1292,6 +1340,7 @@ def test_from_data(self, mocker):
12921340
tag="default",
12931341
schemas=schemas_2,
12941342
parameters=parameters_2,
1343+
request_bodies=request_bodies,
12951344
config=config,
12961345
),
12971346
],
@@ -1328,6 +1377,7 @@ def test_from_data_overrides_path_item_params_with_operation_params(self):
13281377
data=data,
13291378
schemas=Schemas(),
13301379
parameters=Parameters(),
1380+
request_bodies=RequestBodies(),
13311381
config=Config(),
13321382
)
13331383
collection: EndpointCollection = collections["default"]
@@ -1349,6 +1399,7 @@ def test_from_data_errors(self, mocker):
13491399
parameters_1 = mocker.MagicMock()
13501400
parameters_2 = mocker.MagicMock()
13511401
parameters_3 = mocker.MagicMock()
1402+
request_bodies = mocker.MagicMock()
13521403
endpoint_from_data = mocker.patch.object(
13531404
Endpoint,
13541405
"from_data",
@@ -1363,7 +1414,11 @@ def test_from_data_errors(self, mocker):
13631414
config = MagicMock()
13641415

13651416
result, result_schemas, result_parameters = EndpointCollection.from_data(
1366-
data=data, schemas=schemas, config=config, parameters=parameters
1417+
data=data,
1418+
schemas=schemas,
1419+
config=config,
1420+
parameters=parameters,
1421+
request_bodies=request_bodies,
13671422
)
13681423

13691424
endpoint_from_data.assert_has_calls(
@@ -1375,6 +1430,7 @@ def test_from_data_errors(self, mocker):
13751430
tag="default",
13761431
schemas=schemas,
13771432
parameters=parameters,
1433+
request_bodies=request_bodies,
13781434
config=config,
13791435
),
13801436
mocker.call(
@@ -1384,6 +1440,7 @@ def test_from_data_errors(self, mocker):
13841440
tag="tag_2",
13851441
schemas=schemas_1,
13861442
parameters=parameters_1,
1443+
request_bodies=request_bodies,
13871444
config=config,
13881445
),
13891446
mocker.call(
@@ -1393,6 +1450,7 @@ def test_from_data_errors(self, mocker):
13931450
tag="default",
13941451
schemas=schemas_2,
13951452
parameters=parameters_2,
1453+
request_bodies=request_bodies,
13961454
config=config,
13971455
),
13981456
],
@@ -1434,9 +1492,12 @@ def test_from_data_tags_snake_case_sanitizer(self, mocker):
14341492
)
14351493
schemas = mocker.MagicMock()
14361494
parameters = mocker.MagicMock()
1495+
request_bodies = mocker.MagicMock()
14371496
config = MagicMock()
14381497

1439-
result = EndpointCollection.from_data(data=data, schemas=schemas, parameters=parameters, config=config)
1498+
result = EndpointCollection.from_data(
1499+
data=data, schemas=schemas, parameters=parameters, request_bodies=request_bodies, config=config
1500+
)
14401501

14411502
endpoint_from_data.assert_has_calls(
14421503
[
@@ -1447,6 +1508,7 @@ def test_from_data_tags_snake_case_sanitizer(self, mocker):
14471508
tag="default",
14481509
schemas=schemas,
14491510
parameters=parameters,
1511+
request_bodies=request_bodies,
14501512
config=config,
14511513
),
14521514
mocker.call(
@@ -1456,6 +1518,7 @@ def test_from_data_tags_snake_case_sanitizer(self, mocker):
14561518
tag="amf_subscription_info_document",
14571519
schemas=schemas_1,
14581520
parameters=parameters_1,
1521+
request_bodies=request_bodies,
14591522
config=config,
14601523
),
14611524
mocker.call(
@@ -1465,6 +1528,7 @@ def test_from_data_tags_snake_case_sanitizer(self, mocker):
14651528
tag="tag3_abc",
14661529
schemas=schemas_2,
14671530
parameters=parameters_2,
1531+
request_bodies=request_bodies,
14681532
config=config,
14691533
),
14701534
],

tests/test_parser/test_properties/test_init.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ def test_property_from_data_str_enum_with_null(self, enum_property_factory):
338338
}
339339

340340
def test_property_from_data_null_enum(self, enum_property_factory, none_property_factory):
341-
from openapi_python_client.parser.properties import Class, Schemas, property_from_data
341+
from openapi_python_client.parser.properties import Schemas, property_from_data
342342
from openapi_python_client.schema import Schema
343343

344344
data = Schema(title="AnEnumWithOnlyNull", enum=[None], nullable=False, default=None)
@@ -459,7 +459,7 @@ def test_property_from_data_ref_enum_with_invalid_default(self, enum_property_fa
459459
assert prop == PropertyError(data=data, detail="x is an invalid default for enum MyEnum")
460460

461461
def test_property_from_data_ref_model(self, model_property_factory):
462-
from openapi_python_client.parser.properties import Class, ModelProperty, Schemas, property_from_data
462+
from openapi_python_client.parser.properties import Class, Schemas, property_from_data
463463

464464
name = "new_name"
465465
required = False
@@ -646,7 +646,7 @@ def test_property_from_data_union(self, mocker):
646646
)
647647

648648
def test_property_from_data_union_of_one_element(self, mocker, model_property_factory):
649-
from openapi_python_client.parser.properties import Class, ModelProperty, Schemas, property_from_data
649+
from openapi_python_client.parser.properties import Schemas, property_from_data
650650

651651
name = "new_name"
652652
required = False

tests/test_parser/test_properties/test_schemas.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def test_cannot_parse_parameters_by_reference(self):
5757
def test_parameters_without_schema_are_ignored(self):
5858
from openapi_python_client.parser.properties import Parameters
5959
from openapi_python_client.parser.properties.schemas import parameter_from_data
60-
from openapi_python_client.schema import ParameterLocation, Schema
60+
from openapi_python_client.schema import ParameterLocation
6161

6262
param = Parameter(name="a_schemaless_param", param_in=ParameterLocation.QUERY)
6363
parameters = Parameters()

tests/test_parser/test_responses.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import openapi_python_client.schema as oai
44
from openapi_python_client.parser.errors import ParseError, PropertyError
5-
from openapi_python_client.parser.properties import AnyProperty, Schemas, StringProperty
5+
from openapi_python_client.parser.properties import Schemas
66

77
MODULE_NAME = "openapi_python_client.parser.responses"
88

0 commit comments

Comments
 (0)