Skip to content

Commit 729a029

Browse files
committed
chore: gen cts sync tests
1 parent 39cb203 commit 729a029

File tree

10 files changed

+133
-76
lines changed

10 files changed

+133
-76
lines changed

generators/src/main/java/com/algolia/codegen/AlgoliaPythonGenerator.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,9 @@ public OperationsMap postProcessOperationsWithModels(OperationsMap objs, List<Mo
135135

136136
List<OperationsMap> modes = new ArrayList<>();
137137
modes.add(operations);
138-
OperationsMap operationsAsync = (OperationsMap) operations.clone();
139-
operationsAsync.put("isAsync", true);
140-
modes.add(operationsAsync);
138+
OperationsMap operationsSync = (OperationsMap) operations.clone();
139+
operationsSync.put("isSync", true);
140+
modes.add(operationsSync);
141141

142142
additionalProperties.put("modes", modes);
143143

generators/src/main/java/com/algolia/codegen/cts/tests/TestsClient.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@
1717
public class TestsClient extends TestsGenerator {
1818

1919
private final boolean withBenchmark;
20+
private final boolean withSyncTests;
2021
private final String testType;
2122

2223
public TestsClient(String language, String client, boolean withBenchmark) {
2324
super(language, client);
2425
this.withBenchmark = withBenchmark;
26+
this.withSyncTests = language.equals("python");
2527
this.testType = withBenchmark ? "benchmark" : "client";
2628
}
2729

@@ -208,5 +210,20 @@ public void run(Map<String, CodegenModel> models, Map<String, CodegenOperation>
208210
blocks.add(testObj);
209211
}
210212
bundle.put(withBenchmark ? "blocksBenchmark" : "blocksClient", blocks);
213+
if (this.withSyncTests) {
214+
List<Object> modes = new ArrayList<>();
215+
216+
Map<String, Object> sync = new HashMap<>();
217+
sync.put("isSync", true);
218+
sync.put(withBenchmark ? "blocksBenchmarkSync" : "blocksClientSync", blocks);
219+
220+
Map<String, Object> async = new HashMap<>();
221+
async.put(withBenchmark ? "blocksBenchmark" : "blocksClient", blocks);
222+
223+
modes.add(sync);
224+
modes.add(async);
225+
226+
bundle.put("modes", modes);
227+
}
211228
}
212229
}

generators/src/main/java/com/algolia/codegen/cts/tests/TestsRequest.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,13 @@
1515
public class TestsRequest extends TestsGenerator {
1616

1717
private final boolean withSnippets;
18+
private final boolean withSyncTests;
1819
private List<SupportingFile> supportingFiles;
1920

2021
public TestsRequest(String language, String client, boolean withSnippets) {
2122
super(language, client);
2223
this.withSnippets = withSnippets;
24+
this.withSyncTests = language.equals("python");
2325
}
2426

2527
protected Map<String, Request[]> loadRequestCTS() throws Exception {
@@ -256,5 +258,34 @@ public void run(Map<String, CodegenModel> models, Map<String, CodegenOperation>
256258
} else if (supportingFiles != null) {
257259
supportingFiles.removeIf(f -> f.getTemplateFile().equals("tests/e2e/e2e.mustache"));
258260
}
261+
262+
if (this.withSyncTests) {
263+
List<Object> modes = new ArrayList<>();
264+
265+
if (!blocksE2E.isEmpty()) {
266+
Map<String, Object> sync = new HashMap<>();
267+
sync.put("isSync", true);
268+
sync.put("blocksE2ESync", blocksE2E);
269+
270+
Map<String, Object> async = new HashMap<>();
271+
sync.put("isSync", true);
272+
sync.put("blocksE2E", blocksE2E);
273+
274+
modes.add(sync);
275+
modes.add(async);
276+
}
277+
278+
Map<String, Object> sync = new HashMap<>();
279+
sync.put("isSync", true);
280+
sync.put("blocksRequestsSync", blocks);
281+
282+
Map<String, Object> async = new HashMap<>();
283+
async.put("blocksRequests", blocks);
284+
285+
modes.add(sync);
286+
modes.add(async);
287+
288+
bundle.put("modes", modes);
289+
}
259290
}
260291
}

templates/python/api.mustache

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ from algoliasearch.{{packageName}}.models.{{#lambda.snakecase}}{{{.}}}{{/lambda.
1717

1818
{{#modes}}
1919
{{#operations}}
20-
class {{classname}}{{^isAsync}}Sync{{/isAsync}}:
21-
"""The Algolia '{{classname}}{{^isAsync}}Sync{{/isAsync}}' class.
20+
class {{classname}}{{#isSync}}Sync{{/isSync}}:
21+
"""The Algolia '{{classname}}{{#isSync}}Sync{{/isSync}}' class.
2222

2323
Args:
2424
app_id (str): The Algolia application ID to retrieve information from.
@@ -29,10 +29,10 @@ class {{classname}}{{^isAsync}}Sync{{/isAsync}}:
2929
The initialized API client.
3030

3131
Example:
32-
_client = {{classname}}{{^isAsync}}Sync{{/isAsync}}("YOUR_ALGOLIA_APP_ID", "YOUR_ALGOLIA_API_KEY"{{#hasRegionalHost}}, region="{{#allowedRegions}}'{{.}}'{{^-last}} or {{/-last}}{{/allowedRegions}}"{{/hasRegionalHost}})
33-
_client_with_named_args = {{classname}}{{^isAsync}}Sync{{/isAsync}}(app_id="YOUR_ALGOLIA_APP_ID", api_key="YOUR_ALGOLIA_API_KEY"{{#hasRegionalHost}}, region="{{#allowedRegions}}'{{.}}'{{^-last}} or {{/-last}}{{/allowedRegions}}"{{/hasRegionalHost}})
32+
_client = {{classname}}{{#isSync}}Sync{{/isSync}}("YOUR_ALGOLIA_APP_ID", "YOUR_ALGOLIA_API_KEY"{{#hasRegionalHost}}, region="{{#allowedRegions}}'{{.}}'{{^-last}} or {{/-last}}{{/allowedRegions}}"{{/hasRegionalHost}})
33+
_client_with_named_args = {{classname}}{{#isSync}}Sync{{/isSync}}(app_id="YOUR_ALGOLIA_APP_ID", api_key="YOUR_ALGOLIA_API_KEY"{{#hasRegionalHost}}, region="{{#allowedRegions}}'{{.}}'{{^-last}} or {{/-last}}{{/allowedRegions}}"{{/hasRegionalHost}})
3434

35-
See `{{classname}}{{^isAsync}}Sync{{/isAsync}}.create_with_config` for advanced configuration.
35+
See `{{classname}}{{#isSync}}Sync{{/isSync}}.create_with_config` for advanced configuration.
3636
"""
3737

3838
_transporter: Transporter
@@ -63,34 +63,34 @@ class {{classname}}{{^isAsync}}Sync{{/isAsync}}:
6363
The initialized API client.
6464

6565
Example:
66-
_client_with_custom_config = {{classname}}{{^isAsync}}Sync{{/isAsync}}.create_with_config(config={{#lambda.pascalcase}}{{client}}Config{{/lambda.pascalcase}}(...))
67-
_client_with_custom_config_and_transporter = {{classname}}{{^isAsync}}Sync{{/isAsync}}.create_with_config(config={{#lambda.pascalcase}}{{client}}Config{{/lambda.pascalcase}}(...), transporter=Transporter(...))
66+
_client_with_custom_config = {{classname}}{{#isSync}}Sync{{/isSync}}.create_with_config(config={{#lambda.pascalcase}}{{client}}Config{{/lambda.pascalcase}}(...))
67+
_client_with_custom_config_and_transporter = {{classname}}{{#isSync}}Sync{{/isSync}}.create_with_config(config={{#lambda.pascalcase}}{{client}}Config{{/lambda.pascalcase}}(...), transporter=Transporter(...))
6868
"""
6969
if transporter is None:
7070
transporter = Transporter(config)
7171

72-
return {{classname}}{{^isAsync}}Sync{{/isAsync}}(app_id=config.app_id, api_key=config.api_key, {{#hasRegionalHost}}region=config.region, {{/hasRegionalHost}}transporter=transporter, config=config)
72+
return {{classname}}{{#isSync}}Sync{{/isSync}}(app_id=config.app_id, api_key=config.api_key, {{#hasRegionalHost}}region=config.region, {{/hasRegionalHost}}transporter=transporter, config=config)
7373

74-
{{#isAsync}}
74+
{{^isSync}}
7575
async def __aenter__(self) -> None:
7676
return self
7777

7878
async def __aexit__(self, exc_type, exc_value, traceback) -> None:
7979
"""Closes the underlying `transporter` of the API client."""
80-
{{#isAsync}}await {{/isAsync}}self.close()
80+
{{^isSync}}await {{/isSync}}self.close()
8181

8282
async def close(self) -> None:
8383
"""Closes the underlying `transporter` of the API client."""
84-
return {{#isAsync}}await {{/isAsync}}self._transporter.close()
85-
{{/isAsync}}
84+
return {{^isSync}}await {{/isSync}}self._transporter.close()
85+
{{/isSync}}
8686

8787
{{#isSearchClient}}
8888
{{> search_helpers}}
8989
{{/isSearchClient}}
9090

9191
{{#operation}}
9292

93-
{{#isAsync}}async {{/isAsync}}def {{operationId}}_with_http_info{{> partial_api_args}} -> ApiResponse[str]:
93+
{{^isSync}}async {{/isSync}}def {{operationId}}_with_http_info{{> partial_api_args}} -> ApiResponse[str]:
9494
"""
9595
{{#isDeprecated}}
9696
(Deprecated) {{operationId}}
@@ -151,7 +151,7 @@ class {{classname}}{{^isAsync}}Sync{{/isAsync}}:
151151
_data = {{paramName}}
152152
{{/bodyParam}}
153153

154-
return {{#isAsync}}await {{/isAsync}}self._transporter.request(
154+
return {{^isSync}}await {{/isSync}}self._transporter.request(
155155
verb=Verb.{{httpMethod}},
156156
path={{#vendorExtensions}}'{{{path}}}'{{#pathParams}}.replace({{=<% %>=}}'{<%baseName%>}'<%={{ }}=%>, {{#x-is-custom-request}}{{paramName}}{{/x-is-custom-request}}{{^x-is-custom-request}}quote(str({{paramName}}), safe=''){{/x-is-custom-request}}){{/pathParams}},{{/vendorExtensions}}
157157
request_options=self._request_options.merge(
@@ -165,7 +165,7 @@ class {{classname}}{{^isAsync}}Sync{{/isAsync}}:
165165
{{/vendorExtensions}}
166166
)
167167

168-
{{#isAsync}}async {{/isAsync}}def {{operationId}}{{> partial_api_args}} -> {{{returnType}}}{{^returnType}}None{{/returnType}}:
168+
{{^isSync}}async {{/isSync}}def {{operationId}}{{> partial_api_args}} -> {{{returnType}}}{{^returnType}}None{{/returnType}}:
169169
"""
170170
{{#isDeprecated}}
171171
(Deprecated) {{operationId}}
@@ -186,7 +186,7 @@ class {{classname}}{{^isAsync}}Sync{{/isAsync}}:
186186
:return: Returns the deserialized response in a '{{{returnType}}}' result object.
187187
{{/returnType}}
188188
"""
189-
return ({{#isAsync}}await {{/isAsync}}self.{{operationId}}_with_http_info({{#allParams}}{{paramName}},{{/allParams}}request_options)).deserialize({{{returnType}}})
189+
return ({{^isSync}}await {{/isSync}}self.{{operationId}}_with_http_info({{#allParams}}{{paramName}},{{/allParams}}request_options)).deserialize({{{returnType}}})
190190

191191
{{/operation}}
192192
{{/operations}}

0 commit comments

Comments
 (0)