@@ -704,32 +704,55 @@ async def test_big_int_eo_search(
704
704
705
705
706
706
@pytest .mark .asyncio
707
- async def test_create_item_uses_existing_datetime_index (app_client , load_test_data , txn_client , ctx ):
707
+ async def test_create_item_in_past_date_creates_separate_index (app_client , ctx , load_test_data , txn_client ):
708
708
if not os .getenv ("ENABLE_DATETIME_INDEX_FILTERING" ):
709
709
pytest .skip ()
710
710
711
711
item = load_test_data ("test_item.json" )
712
712
item ["id" ] = str (uuid .uuid4 ())
713
- created_item = await app_client .post (f"/collections/{ item ['collection' ]} /items" , json = item )
714
- assert created_item .status_code == 201
713
+ item ["properties" ]["datetime" ] = "2012-02-12T12:30:22Z"
714
+
715
+ response = await app_client .post (f"/collections/{ item ['collection' ]} /items" , json = item )
716
+
717
+ assert response .status_code == 201
718
+
715
719
indices = await txn_client .database .client .indices .get_alias (index = "*" )
716
- assert 'items_test-collection_2020-02-12' in indices .keys ()
717
- await app_client .delete (f"/collections/{ item ['collection' ]} /items/{ item ['id' ]} " )
720
+ expected_indices = ['items_test-collection_2012-02-12' , 'items_test-collection_2020-02-12' ]
721
+
722
+ for expected_index in expected_indices :
723
+ assert expected_index in indices .keys ()
718
724
719
725
720
726
@pytest .mark .asyncio
727
+ async def test_create_item_uses_existing_datetime_index (app_client , ctx , load_test_data , txn_client ):
728
+ if not os .getenv ("ENABLE_DATETIME_INDEX_FILTERING" ):
729
+ pytest .skip ()
730
+
731
+ item = load_test_data ("test_item.json" )
732
+ item ["id" ] = str (uuid .uuid4 ())
733
+
734
+ response = await app_client .post (f"/collections/{ item ['collection' ]} /items" , json = item )
735
+
736
+ assert response .status_code == 201
737
+
738
+ indices = await txn_client .database .client .indices .get_alias (index = "*" )
739
+ assert 'items_test-collection_2020-02-12' in indices .keys ()
740
+
741
+
721
742
async def test_create_item_with_different_date_same_index (app_client , load_test_data , txn_client , ctx ):
722
743
if not os .getenv ("ENABLE_DATETIME_INDEX_FILTERING" ):
723
744
pytest .skip ()
724
745
725
746
item = load_test_data ("test_item.json" )
726
747
item ["id" ] = str (uuid .uuid4 ())
727
748
item ["properties" ]["datetime" ] = "2022-02-12T12:30:22Z"
728
- created_item = await app_client .post (f"/collections/{ item ['collection' ]} /items" , json = item )
729
- assert created_item .status_code == 201
749
+
750
+ response = await app_client .post (f"/collections/{ item ['collection' ]} /items" , json = item )
751
+
752
+ assert response .status_code == 201
753
+
730
754
indices = await txn_client .database .client .indices .get_alias (index = "*" )
731
755
assert 'items_test-collection_2020-02-12' in indices .keys ()
732
- await app_client .delete (f"/collections/{ item ['collection' ]} /items/{ item ['id' ]} " )
733
756
734
757
735
758
@pytest .mark .asyncio
@@ -743,25 +766,126 @@ async def test_create_new_index_when_size_limit_exceeded(app_client, load_test_d
743
766
744
767
with patch ('stac_fastapi.sfeos_helpers.database.AsyncIndexInserter.get_index_size_in_gb' ) as mock_get_size :
745
768
mock_get_size .return_value = 21.0
746
- created_item = await app_client .post (f"/collections/{ item ['collection' ]} /items" , json = item )
769
+ response = await app_client .post (f"/collections/{ item ['collection' ]} /items" , json = item )
770
+
771
+ assert response .status_code == 201
747
772
748
- assert created_item .status_code == 201
749
773
indices = await txn_client .database .client .indices .get_alias (index = "*" )
750
- assert 'items_test-collection_2020-02-12' and "items_test-collection_2024-02-13" in indices .keys ()
751
- await app_client .delete (f"/collections/{ item ['collection' ]} /items/{ item ['id' ]} " )
774
+ expected_indices = ['items_test-collection_2020-02-12' , 'items_test-collection_2024-02-13' ]
775
+
776
+ for expected_index in expected_indices :
777
+ assert expected_index in indices .keys ()
752
778
753
779
754
780
@pytest .mark .asyncio
755
- async def test_create_item_in_past_date_creates_separate_index (app_client , load_test_data , txn_client , ctx ):
781
+ async def test_bulk_create_items_with_same_date_range (app_client , load_test_data , txn_client , ctx ):
756
782
if not os .getenv ("ENABLE_DATETIME_INDEX_FILTERING" ):
757
783
pytest .skip ()
758
784
759
- item = load_test_data ("test_item.json" )
760
- item ["id" ] = str (uuid .uuid4 ())
761
- item ["properties" ]["datetime" ] = "2012-02-12T12:30:22Z"
762
- created_item = await app_client .post (f"/collections/{ item ['collection' ]} /items" , json = item )
763
- breakpoint ()
764
- assert created_item .status_code == 201
785
+ base_item = load_test_data ("test_item.json" )
786
+ items_dict = {}
787
+
788
+ for i in range (10 ):
789
+ item = deepcopy (base_item )
790
+ item ["id" ] = str (uuid .uuid4 ())
791
+ item ["properties" ]["datetime" ] = f"2020-02-{ 12 + i } T12:30:22Z"
792
+ items_dict [item ["id" ]] = item
793
+
794
+ payload = {
795
+ "items" : items_dict ,
796
+ "method" : "insert"
797
+ }
798
+
799
+ response = await app_client .post (
800
+ f"/collections/{ base_item ['collection' ]} /bulk_items" ,
801
+ json = payload
802
+ )
803
+
804
+ assert response .status_code == 200
805
+
765
806
indices = await txn_client .database .client .indices .get_alias (index = "*" )
766
- assert 'items_test-collection_2012-02-12' and 'items_test-collection_2020-02-12' in indices .keys ()
767
- await app_client .delete (f"/collections/{ item ['collection' ]} /items/{ item ['id' ]} " )
807
+ assert 'items_test-collection_2020-02-12' in indices .keys ()
808
+
809
+
810
+ @pytest .mark .asyncio
811
+ async def test_bulk_create_items_with_different_date_ranges (app_client , load_test_data , txn_client , ctx ):
812
+ if not os .getenv ("ENABLE_DATETIME_INDEX_FILTERING" ):
813
+ pytest .skip ()
814
+
815
+ base_item = load_test_data ("test_item.json" )
816
+ items_dict = {}
817
+
818
+ for i in range (3 ):
819
+ item = deepcopy (base_item )
820
+ item ["id" ] = str (uuid .uuid4 ())
821
+ item ["properties" ]["datetime" ] = f"2020-02-{ 12 + i } T12:30:22Z"
822
+ items_dict [item ["id" ]] = item
823
+
824
+ for i in range (2 ):
825
+ item = deepcopy (base_item )
826
+ item ["id" ] = str (uuid .uuid4 ())
827
+ item ["properties" ]["datetime" ] = f"2010-02-{ 10 + i } T12:30:22Z"
828
+ items_dict [item ["id" ]] = item
829
+
830
+ payload = {
831
+ "items" : items_dict ,
832
+ "method" : "insert"
833
+ }
834
+
835
+ response = await app_client .post (
836
+ f"/collections/{ base_item ['collection' ]} /bulk_items" ,
837
+ json = payload
838
+ )
839
+
840
+ assert response .status_code == 200
841
+
842
+ indices = await txn_client .database .client .indices .get_alias (index = "*" )
843
+ expected_indices = ['items_test-collection_2020-02-12' , 'items_test-collection_2010-02-10' ]
844
+
845
+ for expected_index in expected_indices :
846
+ assert expected_index in indices .keys ()
847
+
848
+
849
+ @pytest .mark .asyncio
850
+ async def test_bulk_create_items_with_size_limit_exceeded (app_client , load_test_data , txn_client , ctx ):
851
+ if not os .getenv ("ENABLE_DATETIME_INDEX_FILTERING" ):
852
+ pytest .skip ()
853
+
854
+ base_item = load_test_data ("test_item.json" )
855
+ items_dict = {}
856
+
857
+ for i in range (3 ):
858
+ item = deepcopy (base_item )
859
+ item ["id" ] = str (uuid .uuid4 ())
860
+ item ["properties" ]["datetime" ] = f"2019-02-{ 15 + i } T12:30:22Z"
861
+ items_dict [item ["id" ]] = item
862
+
863
+ for i in range (2 ):
864
+ item = deepcopy (base_item )
865
+ item ["id" ] = str (uuid .uuid4 ())
866
+ item ["properties" ]["datetime" ] = f"2010-02-{ 10 + i } T12:30:22Z"
867
+ items_dict [item ["id" ]] = item
868
+
869
+ payload = {
870
+ "items" : items_dict ,
871
+ "method" : "insert"
872
+ }
873
+
874
+ with patch ('stac_fastapi.sfeos_helpers.database.SyncIndexInserter.get_index_size_in_gb' ) as mock_get_size :
875
+ mock_get_size .return_value = 21.0
876
+ response = await app_client .post (
877
+ f"/collections/{ base_item ['collection' ]} /bulk_items" ,
878
+ json = payload
879
+ )
880
+
881
+ assert response .status_code == 200
882
+
883
+ indices = await txn_client .database .client .indices .get_alias (index = "*" )
884
+ expected_indices = [
885
+ 'items_test-collection_2010-02-10' ,
886
+ 'items_test-collection_2019-02-15' ,
887
+ 'items_test-collection_2020-02-12'
888
+ ]
889
+
890
+ for expected_index in expected_indices :
891
+ assert expected_index in indices .keys ()
0 commit comments