Skip to content

Commit 26f2095

Browse files
committed
feat(restapi): add snapshot_created_on field to resource schemas
This commit adds the snapshot_created_on datetime field to all Resource response schemas. It also updates the `build_` helper functions to include the field in responses and updates the test suite to validate the updated response schemas.
1 parent c404551 commit 26f2095

File tree

11 files changed

+41
-0
lines changed

11 files changed

+41
-0
lines changed

src/dioptra/restapi/v1/schemas.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,13 @@ def generate_base_resource_schema(name: str, snapshot: bool) -> type[Schema]:
6767
),
6868
dump_only=True,
6969
),
70+
"snapshotCreatedOn": fields.DateTime(
71+
attribute="snapshot_created_on",
72+
metadata=dict(
73+
description=f"Timestamp when the {name} resource snapshot was created."
74+
),
75+
dump_only=True,
76+
),
7077
"lastModifiedOn": fields.DateTime(
7178
attribute="last_modified_on",
7279
metadata=dict(

src/dioptra/restapi/v1/utils.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,7 @@ def build_experiment(experiment_dict: ExperimentDict) -> dict[str, Any]:
546546
"group": build_group_ref(experiment.resource.owner),
547547
"created_on": experiment.resource.created_on,
548548
"last_modified_on": experiment.resource.last_modified_on,
549+
"snapshot_created_on": experiment.created_on,
549550
"latest_snapshot": experiment.resource.latest_snapshot_id
550551
== experiment.resource_snapshot_id,
551552
"tags": [build_tag_ref(tag) for tag in experiment.tags],
@@ -608,6 +609,7 @@ def build_entrypoint(entrypoint_dict: EntrypointDict) -> dict[str, Any]:
608609
"group": build_group_ref(entrypoint.resource.owner),
609610
"created_on": entrypoint.resource.created_on,
610611
"last_modified_on": entrypoint.resource.last_modified_on,
612+
"snapshot_created_on": entrypoint.created_on,
611613
"latest_snapshot": entrypoint.resource.latest_snapshot_id
612614
== entrypoint.resource_snapshot_id,
613615
"tags": [build_tag_ref(tag) for tag in entrypoint.tags],
@@ -675,6 +677,7 @@ def build_job(job_dict: JobDict) -> dict[str, Any]:
675677
"entrypoint": build_entrypoint_snapshot_ref(job.entry_point_job.entry_point),
676678
"created_on": job.resource.created_on,
677679
"last_modified_on": job.resource.last_modified_on,
680+
"snapshot_created_on": job.created_on,
678681
"latest_snapshot": job.resource.latest_snapshot_id == job.resource_snapshot_id,
679682
"tags": [build_tag_ref(tag) for tag in job.tags],
680683
}
@@ -725,6 +728,7 @@ def build_model(model_dict: ModelWithVersionDict) -> dict[str, Any]:
725728
"group": build_group_ref(model.resource.owner),
726729
"created_on": model.resource.created_on,
727730
"last_modified_on": model.resource.last_modified_on,
731+
"snapshot_created_on": model.created_on,
728732
"latest_snapshot": model.resource.latest_snapshot_id
729733
== model.resource_snapshot_id,
730734
"tags": [build_tag_ref(tag) for tag in model.tags],
@@ -772,6 +776,7 @@ def build_artifact(artifact_dict: ArtifactDict) -> dict[str, Any]:
772776
"group": build_group_ref(artifact.resource.owner),
773777
"created_on": artifact.resource.created_on,
774778
"last_modified_on": artifact.resource.last_modified_on,
779+
"snapshot_created_on": artifact.created_on,
775780
"latest_snapshot": artifact.resource.latest_snapshot_id
776781
== artifact.resource_snapshot_id,
777782
"tags": [build_tag_ref(tag) for tag in artifact.tags],
@@ -804,6 +809,7 @@ def build_queue(queue_dict: QueueDict) -> dict[str, Any]:
804809
"group": build_group_ref(queue.resource.owner),
805810
"created_on": queue.resource.created_on,
806811
"last_modified_on": queue.resource.last_modified_on,
812+
"snapshot_created_on": queue.created_on,
807813
"latest_snapshot": queue.resource.latest_snapshot_id
808814
== queue.resource_snapshot_id,
809815
"tags": [build_tag_ref(tag) for tag in queue.tags],
@@ -837,6 +843,7 @@ def build_plugin(plugin_with_files: PluginWithFilesDict) -> dict[str, Any]:
837843
"group": build_group_ref(plugin.resource.owner),
838844
"created_on": plugin.resource.created_on,
839845
"last_modified_on": plugin.resource.last_modified_on,
846+
"snapshot_created_on": plugin.created_on,
840847
"latest_snapshot": plugin.resource.latest_snapshot_id
841848
== plugin.resource_snapshot_id,
842849
"tags": [build_tag_ref(tag) for tag in plugin.tags],
@@ -867,6 +874,7 @@ def build_plugin_file(plugin_file_with_plugin: PluginFileDict) -> dict[str, Any]
867874
"group": build_group_ref(plugin_file.resource.owner),
868875
"created_on": plugin_file.resource.created_on,
869876
"last_modified_on": plugin_file.resource.last_modified_on,
877+
"snapshot_created_on": plugin_file.created_on,
870878
"latest_snapshot": plugin_file.resource.latest_snapshot_id
871879
== plugin_file.resource_snapshot_id,
872880
"contents": plugin_file.contents,
@@ -943,6 +951,7 @@ def build_plugin_parameter_type(
943951
"group": build_group_ref(plugin_parameter_type.resource.owner),
944952
"created_on": plugin_parameter_type.resource.created_on,
945953
"last_modified_on": plugin_parameter_type.resource.last_modified_on,
954+
"snapshot_created_on": plugin_parameter_type.created_on,
946955
"latest_snapshot": plugin_parameter_type.resource.latest_snapshot_id
947956
== plugin_parameter_type.resource_snapshot_id,
948957
"tags": [build_tag_ref(tag) for tag in plugin_parameter_type.tags],

tests/unit/restapi/lib/asserts.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,13 @@ def assert_base_resource_contents_match_expectations(response: dict[str, Any]) -
3131
assert isinstance(response["id"], int)
3232
assert isinstance(response["snapshot"], int)
3333
assert isinstance(response["createdOn"], str)
34+
assert isinstance(response["snapshotCreatedOn"], str)
3435
assert isinstance(response["lastModifiedOn"], str)
3536
assert isinstance(response["latestSnapshot"], bool)
3637
assert isinstance(response["hasDraft"], bool)
3738

3839
assert helpers.is_iso_format(response["createdOn"])
40+
assert helpers.is_iso_format(response["snapshotCreatedOn"])
3941
assert helpers.is_iso_format(response["lastModifiedOn"])
4042

4143

tests/unit/restapi/v1/test_artifact.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ def assert_artifact_response_contents_matches_expectations(
5555
"group",
5656
"user",
5757
"createdOn",
58+
"snapshotCreatedOn",
5859
"lastModifiedOn",
5960
"latestSnapshot",
6061
"hasDraft",
@@ -70,6 +71,7 @@ def assert_artifact_response_contents_matches_expectations(
7071
assert isinstance(response["uri"], str)
7172
assert isinstance(response["description"], str)
7273
assert isinstance(response["createdOn"], str)
74+
assert isinstance(response["snapshotCreatedOn"], str)
7375
assert isinstance(response["lastModifiedOn"], str)
7476
assert isinstance(response["latestSnapshot"], bool)
7577
assert isinstance(response["hasDraft"], bool)
@@ -78,6 +80,7 @@ def assert_artifact_response_contents_matches_expectations(
7880
assert response["description"] == expected_contents["description"]
7981

8082
assert helpers.is_iso_format(response["createdOn"])
83+
assert helpers.is_iso_format(response["snapshotCreatedOn"])
8184
assert helpers.is_iso_format(response["lastModifiedOn"])
8285

8386
# Validate the UserRef structure

tests/unit/restapi/v1/test_entrypoint.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ def assert_entrypoint_response_contents_matches_expectations(
5555
"group",
5656
"user",
5757
"createdOn",
58+
"snapshotCreatedOn",
5859
"lastModifiedOn",
5960
"latestSnapshot",
6061
"hasDraft",
@@ -74,6 +75,7 @@ def assert_entrypoint_response_contents_matches_expectations(
7475
assert isinstance(response["name"], str)
7576
assert isinstance(response["description"], str)
7677
assert isinstance(response["createdOn"], str)
78+
assert isinstance(response["snapshotCreatedOn"], str)
7779
assert isinstance(response["lastModifiedOn"], str)
7880
assert isinstance(response["latestSnapshot"], bool)
7981
assert isinstance(response["hasDraft"], bool)
@@ -83,6 +85,7 @@ def assert_entrypoint_response_contents_matches_expectations(
8385
assert response["taskGraph"] == expected_contents["task_graph"]
8486

8587
assert helpers.is_iso_format(response["createdOn"])
88+
assert helpers.is_iso_format(response["snapshotCreatedOn"])
8689
assert helpers.is_iso_format(response["lastModifiedOn"])
8790

8891
# Validate PluginRef structure

tests/unit/restapi/v1/test_experiment.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ def assert_experiment_response_contents_matches_expectations(
5353
"group",
5454
"user",
5555
"createdOn",
56+
"snapshotCreatedOn",
5657
"lastModifiedOn",
5758
"latestSnapshot",
5859
"hasDraft",
@@ -69,13 +70,15 @@ def assert_experiment_response_contents_matches_expectations(
6970
assert isinstance(response["name"], str)
7071
assert isinstance(response["description"], str)
7172
assert isinstance(response["createdOn"], str)
73+
assert isinstance(response["snapshotCreatedOn"], str)
7274
assert isinstance(response["lastModifiedOn"], str)
7375
assert isinstance(response["latestSnapshot"], bool)
7476

7577
assert response["name"] == expected_contents["name"]
7678
assert response["description"] == expected_contents["description"]
7779

7880
assert helpers.is_iso_format(response["createdOn"])
81+
assert helpers.is_iso_format(response["snapshotCreatedOn"])
7982
assert helpers.is_iso_format(response["lastModifiedOn"])
8083

8184
# Validate the UserRef structure

tests/unit/restapi/v1/test_job.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ def assert_job_response_contents_matches_expectations(
5454
"id",
5555
"snapshot",
5656
"createdOn",
57+
"snapshotCreatedOn",
5758
"lastModifiedOn",
5859
"latestSnapshot",
5960
"hasDraft",

tests/unit/restapi/v1/test_model.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ def assert_model_response_contents_matches_expectations(
5656
"user",
5757
"versions",
5858
"createdOn",
59+
"snapshotCreatedOn",
5960
"lastModifiedOn",
6061
"latestSnapshot",
6162
"hasDraft",

tests/unit/restapi/v1/test_plugin.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ def assert_plugin_response_contents_matches_expectations(
5656
"group",
5757
"user",
5858
"createdOn",
59+
"snapshotCreatedOn",
5960
"lastModifiedOn",
6061
"latestSnapshot",
6162
"hasDraft",
@@ -72,6 +73,7 @@ def assert_plugin_response_contents_matches_expectations(
7273
assert isinstance(response["name"], str)
7374
assert isinstance(response["description"], str)
7475
assert isinstance(response["createdOn"], str)
76+
assert isinstance(response["snapshotCreatedOn"], str)
7577
assert isinstance(response["lastModifiedOn"], str)
7678
assert isinstance(response["latestSnapshot"], bool)
7779
assert isinstance(response["hasDraft"], bool)
@@ -80,6 +82,7 @@ def assert_plugin_response_contents_matches_expectations(
8082
assert response["description"] == expected_contents["description"]
8183

8284
assert helpers.is_iso_format(response["createdOn"])
85+
assert helpers.is_iso_format(response["snapshotCreatedOn"])
8386
assert helpers.is_iso_format(response["lastModifiedOn"])
8487

8588
# Validate the UserRef structure
@@ -312,6 +315,7 @@ def assert_plugin_file_response_contents_matches_expectations(
312315
"group",
313316
"user",
314317
"createdOn",
318+
"snapshotCreatedOn",
315319
"lastModifiedOn",
316320
"latestSnapshot",
317321
"hasDraft",
@@ -331,6 +335,7 @@ def assert_plugin_file_response_contents_matches_expectations(
331335
assert isinstance(response["description"], str)
332336
assert isinstance(response["contents"], str)
333337
assert isinstance(response["createdOn"], str)
338+
assert isinstance(response["snapshotCreatedOn"], str)
334339
assert isinstance(response["lastModifiedOn"], str)
335340
assert isinstance(response["latestSnapshot"], bool)
336341
assert isinstance(response["hasDraft"], bool)
@@ -340,6 +345,7 @@ def assert_plugin_file_response_contents_matches_expectations(
340345
assert response["contents"] == expected_contents["contents"]
341346

342347
assert helpers.is_iso_format(response["createdOn"])
348+
assert helpers.is_iso_format(response["snapshotCreatedOn"])
343349
assert helpers.is_iso_format(response["lastModifiedOn"])
344350

345351
# Validate the UserRef structure

tests/unit/restapi/v1/test_plugin_parameter_type.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,7 @@ def assert_plugin_parameter_type_content_matches_expectations(
322322
"group",
323323
"user",
324324
"createdOn",
325+
"snapshotCreatedOn",
325326
"lastModifiedOn",
326327
"latestSnapshot",
327328
"hasDraft",
@@ -339,6 +340,7 @@ def assert_plugin_parameter_type_content_matches_expectations(
339340
assert isinstance(response["structure"], (dict, type(None)))
340341
assert isinstance(response["description"], (str, type(None)))
341342
assert isinstance(response["createdOn"], str)
343+
assert isinstance(response["snapshotCreatedOn"], str)
342344
assert isinstance(response["lastModifiedOn"], str)
343345
assert isinstance(response["latestSnapshot"], bool)
344346
assert isinstance(response["hasDraft"], bool)
@@ -348,6 +350,7 @@ def assert_plugin_parameter_type_content_matches_expectations(
348350
assert response["description"] == expected_contents["description"]
349351

350352
assert helpers.is_iso_format(response["createdOn"])
353+
assert helpers.is_iso_format(response["snapshotCreatedOn"])
351354
assert helpers.is_iso_format(response["lastModifiedOn"])
352355

353356
# Validate the UserRef structure

0 commit comments

Comments
 (0)