Skip to content

Commit 2aa4bcd

Browse files
Copy tests/test.json from the function template instead of generating it (#172)
* Copying tests/test.json from templates instead of generating a new one * Lint error fix
1 parent 1ffbf04 commit 2aa4bcd

2 files changed

Lines changed: 50 additions & 4 deletions

File tree

‎src/datacustomcode/cli.py‎

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -351,14 +351,27 @@ def init(directory: str, code_type: str, use_in_feature: Optional[str]):
351351
+ " to automatically update config.json when you make changes to your code"
352352
)
353353

354-
# Generate test.json for functions
354+
# Prefer the sample tests/test.json shipped in the template; only
355+
# generate one from the request model if the template doesn't have it
355356
if code_type == "function":
356-
test_json_path = _generate_function_test_file(entrypoint_path)
357-
if test_json_path:
357+
template_test_json = os.path.join(
358+
os.path.dirname(entrypoint_path), TESTS_DIR, TEST_FILE
359+
)
360+
test_json_path: Optional[str]
361+
if os.path.isfile(template_test_json):
362+
test_json_path = template_test_json
358363
click.echo(
359-
"Generated test file at "
364+
"Sample test file at "
360365
+ click.style(test_json_path, fg="blue", bold=True)
361366
)
367+
else:
368+
test_json_path = _generate_function_test_file(entrypoint_path)
369+
if test_json_path:
370+
click.echo(
371+
"Generated test file at "
372+
+ click.style(test_json_path, fg="blue", bold=True)
373+
)
374+
if test_json_path:
362375
click.echo(
363376
"Test your function locally with "
364377
+ click.style(
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"input": [
3+
{
4+
"text": "Online Remittance Instructions",
5+
"metadata": {
6+
"type": "text",
7+
"page_number": 1,
8+
"transcript_fields": {
9+
"speaker": "Agent",
10+
"start_timestamp": 1.0,
11+
"end_timestamp": 8.75
12+
},
13+
"text_as_html": "<p>Online Remittance Instructions</p>",
14+
"source_dmo_fields": {
15+
"FilePath__c": "quarterly_report.pdf",
16+
"Size__c": 1377454.0,
17+
"ContentType__c": "pdf",
18+
"LastModified__c": "2026-03-25T02:01:24.918000"
19+
},
20+
"prepend": [
21+
{
22+
"dmo_name": "udmo_1__dlm",
23+
"field_name": "ResolvedFilePath__c",
24+
"value": "udlo_1__dll:quarterly_report.pdf"
25+
}
26+
],
27+
"image_base64": "sample_image_base64",
28+
"image_mime_type": "image/png",
29+
"image_type": "diagram"
30+
}
31+
}
32+
]
33+
}

0 commit comments

Comments
 (0)