66from opentaxii .persistence .sqldb .api import Taxii2SQLDatabaseAPI
77from opentaxii .persistence .sqldb .taxii2models import Job , JobDetail , STIXObject
88from opentaxii .taxii2 import entities
9- from opentaxii .taxii2 .utils import DATETIMEFORMAT
9+ from opentaxii .taxii2 .utils import get_object_version
1010from tests .taxii2 .utils import (
1111 API_ROOTS ,
1212 API_ROOTS_WITH_DEFAULT ,
@@ -794,7 +794,37 @@ def test_get_objects(
794794 "valid_from" : "2016-01-01T00:00:00Z" ,
795795 }
796796 ], # objects
797- id = "single object" ,
797+ id = "single-object-version-modified" ,
798+ ),
799+ pytest .param (
800+ API_ROOTS [0 ].id , # api_root_id
801+ COLLECTIONS [5 ].id , # collection_id
802+ [
803+ {
804+ "definition" : {
805+ "statement" : "Copyright 2015-2025, The MITRE Corporation. [...]"
806+ },
807+ "id" : "marking-definition--fa42a846-8d90-4e51-bc29-71d5b4802168" ,
808+ "type" : "marking-definition" ,
809+ "created" : "2017-06-01T00:00:00.000Z" ,
810+ "created_by_ref" : "identity--c78cb6e5-0c4b-4611-8297-d1b8b55e40b5" ,
811+ "definition_type" : "statement" ,
812+ "spec_version" : "2.1" ,
813+ }
814+ ], # objects
815+ id = "single-object-version-created" ,
816+ ),
817+ pytest .param (
818+ API_ROOTS [0 ].id , # api_root_id
819+ COLLECTIONS [5 ].id , # collection_id
820+ [
821+ {
822+ "type" : "x-no-version" ,
823+ "id" : "x-no-version--5e113376-8a13-432d-b711-92f566ebbd92" ,
824+ "spec_version" : "2.1" ,
825+ }
826+ ], # objects
827+ id = "single-object-version-created" ,
798828 ),
799829 pytest .param (
800830 API_ROOTS [0 ].id , # api_root_id
@@ -869,9 +899,7 @@ def test_add_objects(
869899 id = job_detail .id ,
870900 job_id = job .id ,
871901 stix_id = obj ["id" ],
872- version = datetime .datetime .strptime (
873- obj ["modified" ], DATETIMEFORMAT
874- ).replace (tzinfo = datetime .timezone .utc ),
902+ version = get_object_version (obj ),
875903 message = "" ,
876904 status = "success" ,
877905 )
@@ -894,10 +922,7 @@ def test_add_objects(
894922 taxii2_sqldb_api .db .session .query (STIXObject )
895923 .filter (
896924 STIXObject .id == obj ["id" ],
897- STIXObject .version
898- == datetime .datetime .strptime (obj ["modified" ], DATETIMEFORMAT ).replace (
899- tzinfo = datetime .timezone .utc
900- ),
925+ STIXObject .version == get_object_version (obj ),
901926 )
902927 .one ()
903928 )
@@ -906,9 +931,7 @@ def test_add_objects(
906931 assert db_obj .type == obj ["type" ]
907932 assert db_obj .spec_version == obj ["spec_version" ]
908933 assert isinstance (db_obj .date_added , datetime .datetime )
909- assert db_obj .version == datetime .datetime .strptime (
910- obj ["modified" ], DATETIMEFORMAT
911- ).replace (tzinfo = datetime .timezone .utc )
934+ assert db_obj .version == get_object_version (obj )
912935 assert db_obj .serialized_data == {
913936 key : value
914937 for (key , value ) in obj .items ()
@@ -921,9 +944,7 @@ def test_add_objects(
921944 )
922945 assert db_job_detail .job_id == db_job .id
923946 assert db_job_detail .stix_id == obj ["id" ]
924- assert db_job_detail .version == datetime .datetime .strptime (
925- obj ["modified" ], DATETIMEFORMAT
926- ).replace (tzinfo = datetime .timezone .utc )
947+ assert db_job_detail .version == get_object_version (obj )
927948 assert db_job_detail .message == ""
928949 assert db_job_detail .status == "success"
929950
0 commit comments