@@ -36,8 +36,8 @@ def delete_item_in_shopping_list(client, shopping_list_id, shopping_list_item_id
36
36
def get_shopping_list (client , shopping_list_id , auth_headers ):
37
37
return client .get ('/api/v1/shopping-lists/{}' .format (shopping_list_id ), headers = auth_headers )
38
38
39
- def get_all_shopping_list (client , auth_headers , page = 1 , per_page = 10 ):
40
- return client .get ('/api/v1/shopping-lists?page={}&per_page={}' .format (page , per_page ), headers = auth_headers )
39
+ def get_all_shopping_list (client , auth_headers , page = 1 , per_page = 10 , order_by = '' , desc = False ):
40
+ return client .get ('/api/v1/shopping-lists?page={}&per_page={}&order_by={}&desc={} ' .format (page , per_page , order_by , desc ), headers = auth_headers )
41
41
42
42
def patch_shopping_list (client , shopping_list_id , json , auth_headers ):
43
43
return client .patch ('/api/v1/shopping-lists/{}' .format (shopping_list_id ), json = json , headers = auth_headers )
@@ -524,4 +524,100 @@ def test_create_update_timestamp(client: FlaskClient, auth_headers):
524
524
assert response .status_code == 200 \
525
525
and response .json ['name' ] == 'Tomato' \
526
526
and response .json ['insert_timestamp' ] == insert_timestamp \
527
- and response .json ['update_timestamp' ] > update_timestamp
527
+ and response .json ['update_timestamp' ] > update_timestamp
528
+
529
+ def test_get_last_updated (client : FlaskClient , auth_headers ):
530
+ response = create_shopping_list (client , {
531
+ 'name' : 'Rice' ,
532
+ }, auth_headers )
533
+
534
+ assert response .status_code == 201
535
+
536
+ idx_1 = response .json ['_id' ]
537
+ insert_timestamp_1 = response .json ['insert_timestamp' ]
538
+ update_timestamp_1 = response .json ['update_timestamp' ]
539
+
540
+ response = create_shopping_list (client , {
541
+ 'name' : 'Tomato' ,
542
+ }, auth_headers )
543
+
544
+ assert response .status_code == 201
545
+
546
+ idx_2 = response .json ['_id' ]
547
+ insert_timestamp_2 = response .json ['insert_timestamp' ]
548
+ update_timestamp_2 = response .json ['update_timestamp' ]
549
+
550
+ response = get_all_shopping_list (client , auth_headers , order_by = 'update_timestamp' , desc = True , page = 1 , per_page = 1 )
551
+
552
+ assert response .status_code == 200 \
553
+ and len (response .json ['results' ]) == 1 \
554
+ and response .json ['results' ][0 ]['_id' ] == idx_2
555
+
556
+ response = patch_shopping_list (client , idx_1 , {
557
+ 'name' : 'Rice' ,
558
+ }, auth_headers )
559
+
560
+ assert response .status_code == 200 \
561
+ and response .json ['insert_timestamp' ] == insert_timestamp_1 \
562
+ and response .json ['update_timestamp' ] > update_timestamp_1
563
+
564
+ update_timestamp_1 = response .json ['update_timestamp' ]
565
+
566
+ response = get_all_shopping_list (client , auth_headers , order_by = 'update_timestamp' , desc = True , page = 1 , per_page = 1 )
567
+
568
+ assert response .status_code == 200 \
569
+ and len (response .json ['results' ]) == 1 \
570
+ and response .json ['results' ][0 ]['_id' ] == idx_1 \
571
+ and response .json ['results' ][0 ]['update_timestamp' ] == update_timestamp_1
572
+
573
+ response = put_shopping_list (client , idx_1 , {
574
+ 'name' : 'Rice' ,
575
+ }, auth_headers )
576
+
577
+ assert response .status_code == 200 \
578
+ and response .json ['insert_timestamp' ] == insert_timestamp_1 \
579
+ and response .json ['update_timestamp' ] > update_timestamp_1
580
+
581
+ update_timestamp_1 = response .json ['update_timestamp' ]
582
+
583
+ response = get_all_shopping_list (client , auth_headers , order_by = 'update_timestamp' , desc = True , page = 1 , per_page = 1 )
584
+
585
+ assert response .status_code == 200 \
586
+ and len (response .json ['results' ]) == 1 \
587
+ and response .json ['results' ][0 ]['_id' ] == idx_1 \
588
+ and response .json ['results' ][0 ]['update_timestamp' ] == update_timestamp_1
589
+
590
+ response = patch_shopping_list (client , idx_2 , {
591
+ 'name' : 'Tomato' ,
592
+ }, auth_headers )
593
+
594
+ assert response .status_code == 200 \
595
+ and response .json ['insert_timestamp' ] == insert_timestamp_2 \
596
+ and response .json ['update_timestamp' ] > update_timestamp_2
597
+
598
+ update_timestamp_2 = response .json ['update_timestamp' ]
599
+
600
+ response = get_all_shopping_list (client , auth_headers , order_by = 'update_timestamp' , desc = True , page = 1 , per_page = 1 )
601
+
602
+ assert response .status_code == 200 \
603
+ and len (response .json ['results' ]) == 1 \
604
+ and response .json ['results' ][0 ]['_id' ] == idx_2 \
605
+ and response .json ['results' ][0 ]['update_timestamp' ] == update_timestamp_2
606
+
607
+ response = put_shopping_list (client , idx_2 , {
608
+ 'name' : 'Tomato' ,
609
+ }, auth_headers )
610
+
611
+ assert response .status_code == 200 \
612
+ and response .json ['insert_timestamp' ] == insert_timestamp_2 \
613
+ and response .json ['update_timestamp' ] > update_timestamp_2
614
+
615
+ update_timestamp_2 = response .json ['update_timestamp' ]
616
+
617
+ response = get_all_shopping_list (client , auth_headers , order_by = 'update_timestamp' , desc = True , page = 1 , per_page = 1 )
618
+
619
+ assert response .status_code == 200 \
620
+ and len (response .json ['results' ]) == 1 \
621
+ and response .json ['results' ][0 ]['_id' ] == idx_2 \
622
+ and response .json ['results' ][0 ]['update_timestamp' ] == update_timestamp_2
623
+
0 commit comments