1- import pendulum
21import pytest
32from fastapi .testclient import TestClient
43
76from infrahub .core .initialization import create_branch
87from infrahub .core .manager import NodeManager
98from infrahub .core .node import Node
9+ from infrahub .core .timestamp import Timestamp
1010from infrahub .database import InfrahubDatabase
1111from infrahub .services .adapters .workflow .local import WorkflowLocalExecution
1212from infrahub .workflows .initialization import setup_task_manager
@@ -140,7 +140,7 @@ async def car_person_data_diff(db: InfrahubDatabase, default_branch, car_person_
140140 branch2 = await create_branch (branch_name = "branch2" , db = db )
141141
142142 # Time post Branch Creation
143- time0 = pendulum . now ( tz = "UTC" )
143+ time0 = Timestamp ( )
144144
145145 persons_list = await NodeManager .query (db = db , schema = "Person" , branch = branch2 )
146146 persons = {item .name .value : item for item in persons_list }
@@ -166,7 +166,7 @@ async def car_person_data_diff(db: InfrahubDatabase, default_branch, car_person_
166166 await p1 .save (db = db )
167167
168168 # Time in-between the 2 batch of changes
169- time1 = pendulum . now ( tz = "UTC" )
169+ time1 = Timestamp ( )
170170
171171 # Update Repo 01 in Branch2
172172 repo01 = repos ["repo01" ]
@@ -181,7 +181,7 @@ async def car_person_data_diff(db: InfrahubDatabase, default_branch, car_person_
181181 await cars_main ["bolt" ].save (db = db )
182182
183183 # Time After the changes
184- time2 = pendulum . now ( tz = "UTC" )
184+ time2 = Timestamp ( )
185185
186186 params = {
187187 "branch" : branch2 ,
@@ -198,7 +198,7 @@ async def car_person_data_generic_diff(db: InfrahubDatabase, default_branch, car
198198 branch2 = await create_branch (branch_name = "branch2" , db = db )
199199
200200 # Time After Creation of branch2
201- time0 = pendulum . now ( tz = "UTC" )
201+ time0 = Timestamp ( )
202202
203203 persons_list = await NodeManager .query (db = db , schema = "TestPerson" , branch = branch2 )
204204 persons = {item .name .value : item for item in persons_list }
@@ -213,34 +213,34 @@ async def car_person_data_generic_diff(db: InfrahubDatabase, default_branch, car
213213 gcars = {item .name .value : item for item in gcars_list }
214214
215215 # Add a new Person P3 in Branch2 and assign him as the owner of C1
216- time10 = pendulum . now ( tz = "UTC" )
216+ time10 = Timestamp ( )
217217 p3 = await Node .init (db = db , schema = "TestPerson" , branch = branch2 )
218218 await p3 .new (db = db , name = "Bill" , height = 160 )
219219 await p3 .save (db = db , at = time10 )
220220 persons ["Bill" ] = p3
221221
222- time11 = pendulum . now ( tz = "UTC" )
222+ time11 = Timestamp ( )
223223 await ecars ["volt" ].owner .update (data = p3 , db = db )
224224 await ecars ["volt" ].save (db = db , at = time11 )
225225
226226 # Update Repo 01 in Branch2 a first time
227- time12 = pendulum . now ( tz = "UTC" )
227+ time12 = Timestamp ( )
228228 repo01 = repos ["repo01" ]
229229 repo01 .commit .value = "bbbbbbbbbbbbbbb"
230230 repo01 .description .value = "First change in branch"
231231 await repo01 .save (db = db , at = time12 )
232232
233233 # Update P1 height in main
234- time13 = pendulum . now ( tz = "UTC" )
234+ time13 = Timestamp ( )
235235 p1 = await NodeManager .get_one (id = persons ["John" ].id , db = db )
236236 p1 .height .value = 120
237237 await p1 .save (db = db , at = time13 )
238238
239239 # Time in-between the 2 batch of changes
240- time20 = pendulum . now ( tz = "UTC" )
240+ time20 = Timestamp ( )
241241
242242 # Update Repo 01 in Branch2 a second time
243- time21 = pendulum . now ( tz = "UTC" )
243+ time21 = Timestamp ( )
244244 repo01 = repos ["repo01" ]
245245 repo01 .commit .value = "dddddddddd"
246246 repo01 .description .value = "Second change in branch"
@@ -257,7 +257,7 @@ async def car_person_data_generic_diff(db: InfrahubDatabase, default_branch, car
257257 await ecars_main ["bolt" ].save (db = db )
258258
259259 # Time After the changes
260- time30 = pendulum . now ( tz = "UTC" )
260+ time30 = Timestamp ( )
261261
262262 params = {
263263 "branch" : branch2 ,
@@ -414,7 +414,7 @@ async def data_diff_attribute(db: InfrahubDatabase, default_branch, car_person_d
414414 branch2 = await create_branch (branch_name = "branch2" , db = db )
415415
416416 # Time After Creation of branch2
417- time0 = pendulum . now ( tz = "UTC" )
417+ time0 = Timestamp ( )
418418
419419 persons_list = await NodeManager .query (db = db , schema = "TestPerson" , branch = branch2 )
420420 persons = {item .name .value : item for item in persons_list }
@@ -429,23 +429,23 @@ async def data_diff_attribute(db: InfrahubDatabase, default_branch, car_person_d
429429 gcars = {item .name .value : item for item in gcars_list }
430430
431431 # Update Repo 01 in Branch2 a first time
432- time12 = pendulum . now ( tz = "UTC" )
432+ time12 = Timestamp ( )
433433 repo01 = repos ["repo01" ]
434434 repo01 .commit .value = "bbbbbbbbbbbbbbb"
435435 repo01 .description .value = "First update in Branch"
436436 await repo01 .save (db = db , at = time12 )
437437
438438 # Update P1 height in main
439- time13 = pendulum . now ( tz = "UTC" )
439+ time13 = Timestamp ( )
440440 p1 = await NodeManager .get_one (id = persons ["John" ].id , db = db )
441441 p1 .height .value = 120
442442 await p1 .save (db = db , at = time13 )
443443
444444 # Time in-between the 2 batch of changes
445- time20 = pendulum . now ( tz = "UTC" )
445+ time20 = Timestamp ( )
446446
447447 # Update Repo 01 in Branch2 a second time
448- time21 = pendulum . now ( tz = "UTC" )
448+ time21 = Timestamp ( )
449449 repo01 = repos ["repo01" ]
450450 repo01 .commit .value = "dddddddddd"
451451 repo01 .description .value = "Second update in Branch"
@@ -459,7 +459,7 @@ async def data_diff_attribute(db: InfrahubDatabase, default_branch, car_person_d
459459 await ecars_main ["bolt" ].save (db = db )
460460
461461 # Time After the changes
462- time30 = pendulum . now ( tz = "UTC" )
462+ time30 = Timestamp ( )
463463
464464 params = {
465465 "branch" : branch2 ,
@@ -486,7 +486,7 @@ async def data_conflict_attribute(db: InfrahubDatabase, default_branch, car_pers
486486 branch2 = await create_branch (branch_name = "branch2" , db = db )
487487
488488 # Time After Creation of branch2
489- time0 = pendulum . now ( tz = "UTC" )
489+ time0 = Timestamp ( )
490490
491491 persons_list_branch = await NodeManager .query (db = db , schema = "TestPerson" , branch = branch2 )
492492 persons_branch = {item .name .value : item for item in persons_list_branch }
@@ -501,13 +501,13 @@ async def data_conflict_attribute(db: InfrahubDatabase, default_branch, car_pers
501501 repos_main = {item .name .value : item for item in repos_list_main }
502502
503503 # Update Repo 01 in Branch2 a first time
504- time12 = pendulum . now ( tz = "UTC" )
504+ time12 = Timestamp ( )
505505 repos_branch ["repo01" ].commit .value = "bbbbbbbbbbbbbbb"
506506 repos_branch ["repo01" ].description .value = "First update in Branch"
507507 await repos_branch ["repo01" ].save (db = db , at = time12 )
508508
509509 # Update P1 height in branch2
510- time13 = pendulum . now ( tz = "UTC" )
510+ time13 = Timestamp ( )
511511 persons_branch ["John" ].height .value = 666
512512 await persons_branch ["John" ].save (db = db , at = time13 )
513513
@@ -516,22 +516,22 @@ async def data_conflict_attribute(db: InfrahubDatabase, default_branch, car_pers
516516 await persons_main ["John" ].save (db = db , at = time13 )
517517
518518 # Time in-between the 2 batch of changes
519- time20 = pendulum . now ( tz = "UTC" )
519+ time20 = Timestamp ( )
520520
521521 # Update Repo 01 in Branch2 a second time
522- time21 = pendulum . now ( tz = "UTC" )
522+ time21 = Timestamp ( )
523523 repos_branch ["repo01" ].commit .value = "dddddddddd"
524524 repos_branch ["repo01" ].description .value = "Second update in Branch"
525525 await repos_branch ["repo01" ].save (db = db , at = time21 )
526526
527527 # Update Repo 01 in main
528- time22 = pendulum . now ( tz = "UTC" )
528+ time22 = Timestamp ( )
529529 repos_main ["repo01" ].commit .value = "mmmmmmmmmmmmm"
530530 repos_main ["repo01" ].description .value = "update in main"
531531 await repos_main ["repo01" ].save (db = db , at = time12 )
532532
533533 # Time After the changes
534- time30 = pendulum . now ( tz = "UTC" )
534+ time30 = Timestamp ( )
535535
536536 params = {
537537 "branch" : branch2 ,
@@ -553,7 +553,7 @@ async def data_conflict_attribute(db: InfrahubDatabase, default_branch, car_pers
553553@pytest .fixture
554554async def data_diff_relationship_one (db : InfrahubDatabase , default_branch , car_person_data_generic , first_account ):
555555 # Set some values in C1 in Main before creating the branch
556- time_minus1 = pendulum . now ( tz = "UTC" )
556+ time_minus1 = Timestamp ( )
557557
558558 c1_main = await NodeManager .get_one_by_id_or_default_filter (
559559 db = db , id = "volt" , kind = "TestElectricCar" , branch = default_branch
@@ -569,7 +569,7 @@ async def data_diff_relationship_one(db: InfrahubDatabase, default_branch, car_p
569569 branch2 = await create_branch (branch_name = "branch2" , db = db )
570570
571571 # Time After Creation of branch2
572- time0 = pendulum . now ( tz = "UTC" )
572+ time0 = Timestamp ( )
573573
574574 persons_list = await NodeManager .query (db = db , schema = "TestPerson" , branch = branch2 )
575575 persons = {item .name .value : item for item in persons_list }
@@ -578,19 +578,19 @@ async def data_diff_relationship_one(db: InfrahubDatabase, default_branch, car_p
578578 ecars = {item .name .value : item for item in ecars_list }
579579
580580 # Change previous owner of C1 from P1 to P2 in branch
581- time11 = pendulum . now ( tz = "UTC" )
581+ time11 = Timestamp ( )
582582 await ecars ["volt" ].previous_owner .update (data = persons ["John" ], db = db )
583583 await ecars ["volt" ].save (db = db , at = time11 )
584584
585585 # Time in-between the 2 batch of changes
586- time20 = pendulum . now ( tz = "UTC" )
586+ time20 = Timestamp ( )
587587
588588 # Set previous owner for C2 in branch
589589 await ecars ["bolt" ].previous_owner .update (data = persons ["Jane" ], db = db )
590590 await ecars ["bolt" ].save (db = db , at = time20 )
591591
592592 # Time After the changes
593- time30 = pendulum . now ( tz = "UTC" )
593+ time30 = Timestamp ( )
594594
595595 params = {
596596 "branch" : branch2 ,
@@ -610,7 +610,7 @@ async def data_diff_relationship_one(db: InfrahubDatabase, default_branch, car_p
610610@pytest .fixture
611611async def data_conflict_relationship_one (db : InfrahubDatabase , default_branch , car_person_data_generic , first_account ):
612612 # Set some values in C1 in Main before creating the branch
613- time_minus1 = pendulum . now ( tz = "UTC" )
613+ time_minus1 = Timestamp ( )
614614
615615 ecars_list_main = await NodeManager .query (db = db , schema = "TestElectricCar" , branch = default_branch )
616616 ecars_main = {item .name .value : item for item in ecars_list_main }
@@ -624,7 +624,7 @@ async def data_conflict_relationship_one(db: InfrahubDatabase, default_branch, c
624624 branch2 = await create_branch (branch_name = "branch2" , db = db )
625625
626626 # Time After Creation of branch2
627- time0 = pendulum . now ( tz = "UTC" )
627+ time0 = Timestamp ( )
628628
629629 persons_list_branch = await NodeManager .query (db = db , schema = "TestPerson" , branch = branch2 )
630630 persons_branch = {item .name .value : item for item in persons_list_branch }
@@ -633,30 +633,30 @@ async def data_conflict_relationship_one(db: InfrahubDatabase, default_branch, c
633633 ecars_branch = {item .name .value : item for item in ecars_list_branch }
634634
635635 # Change previous owner of C1 from P1 to P2 in branch
636- time11 = pendulum . now ( tz = "UTC" )
636+ time11 = Timestamp ( )
637637 await ecars_branch ["volt" ].previous_owner .update (data = persons_branch ["John" ], db = db )
638638 await ecars_branch ["volt" ].save (db = db , at = time11 )
639639
640640 # Change previous owner of C1 from P1 to Null in main
641- time12 = pendulum . now ( tz = "UTC" )
641+ time12 = Timestamp ( )
642642 await ecars_main ["volt" ].previous_owner .update (data = None , db = db )
643643 await ecars_main ["volt" ].save (db = db , at = time12 )
644644
645645 # Time in-between the 2 batch of changes
646- time20 = pendulum . now ( tz = "UTC" )
646+ time20 = Timestamp ( )
647647
648648 # Set previous owner for C2 in branch
649649 await ecars_branch ["bolt" ].previous_owner .update (data = persons_branch ["Jane" ], db = db )
650650 await ecars_branch ["bolt" ].save (db = db , at = time20 )
651651
652652 # Set previous owner for C2 in main
653- time21 = pendulum . now ( tz = "UTC" )
653+ time21 = Timestamp ( )
654654
655655 await ecars_main ["bolt" ].previous_owner .update (data = persons_branch ["John" ], db = db )
656656 await ecars_main ["bolt" ].save (db = db , at = time21 )
657657
658658 # Time After the changes
659- time30 = pendulum . now ( tz = "UTC" )
659+ time30 = Timestamp ( )
660660
661661 params = {
662662 "branch" : branch2 ,
0 commit comments