@@ -1564,3 +1564,89 @@ async def test_search_max_item_limit(
1564
1564
assert resp .status_code == 200
1565
1565
resp_json = resp .json ()
1566
1566
assert int (limit ) == len (resp_json ["features" ])
1567
+
1568
+
1569
+ @pytest .mark .asyncio
1570
+ async def test_use_datetime_true (app_client , load_test_data , txn_client , monkeypatch ):
1571
+ monkeypatch .setenv ("USE_DATETIME" , "true" )
1572
+
1573
+ test_collection = load_test_data ("test_collection.json" )
1574
+ test_collection ["id" ] = "test-collection-datetime-true"
1575
+ await create_collection (txn_client , test_collection )
1576
+
1577
+ item = load_test_data ("test_item.json" )
1578
+
1579
+ item1 = item .copy ()
1580
+ item1 ["id" ] = "test-item-datetime"
1581
+ item1 ["collection" ] = test_collection ["id" ]
1582
+ item1 ["properties" ]["datetime" ] = "2020-01-01T12:00:00Z"
1583
+ await create_item (txn_client , item1 )
1584
+
1585
+ item2 = item .copy ()
1586
+ item2 ["id" ] = "test-item-start-end"
1587
+ item2 ["collection" ] = test_collection ["id" ]
1588
+ item1 ["properties" ]["datetime" ] = None
1589
+ item2 ["properties" ]["start_datetime" ] = "2020-01-01T10:00:00Z"
1590
+ item2 ["properties" ]["end_datetime" ] = "2020-01-01T13:00:00Z"
1591
+ await create_item (txn_client , item2 )
1592
+
1593
+ resp = await app_client .post (
1594
+ "/search" ,
1595
+ json = {
1596
+ "datetime" : "2020-01-01T12:00:00Z" ,
1597
+ "collections" : [test_collection ["id" ]],
1598
+ },
1599
+ )
1600
+
1601
+ assert resp .status_code == 200
1602
+ resp_json = resp .json ()
1603
+
1604
+ found_ids = {feature ["id" ] for feature in resp_json ["features" ]}
1605
+ assert "test-item-datetime" in found_ids
1606
+ assert "test-item-start-end" in found_ids
1607
+
1608
+
1609
+ @pytest .mark .asyncio
1610
+ async def test_use_datetime_false (app_client , load_test_data , txn_client , monkeypatch ):
1611
+ monkeypatch .setenv ("USE_DATETIME" , "false" )
1612
+
1613
+ test_collection = load_test_data ("test_collection.json" )
1614
+ test_collection ["id" ] = "test-collection-datetime-false"
1615
+ await create_collection (txn_client , test_collection )
1616
+
1617
+ item = load_test_data ("test_item.json" )
1618
+
1619
+ # Item 1: Should NOT be found
1620
+ item1 = item .copy ()
1621
+ item1 ["id" ] = "test-item-datetime-only"
1622
+ item1 ["collection" ] = test_collection ["id" ]
1623
+ item1 ["properties" ]["datetime" ] = "2020-01-01T12:00:00Z"
1624
+ item1 ["properties" ]["start_datetime" ] = "2021-01-01T10:00:00Z"
1625
+ item1 ["properties" ]["end_datetime" ] = "2021-01-01T14:00:00Z"
1626
+ await create_item (txn_client , item1 )
1627
+
1628
+ # Item 2: Should be found
1629
+ item2 = item .copy ()
1630
+ item2 ["id" ] = "test-item-start-end-only"
1631
+ item2 ["collection" ] = test_collection ["id" ]
1632
+ item2 ["properties" ]["datetime" ] = None
1633
+ item2 ["properties" ]["start_datetime" ] = "2020-01-01T10:00:00Z"
1634
+ item2 ["properties" ]["end_datetime" ] = "2020-01-01T14:00:00Z"
1635
+ await create_item (txn_client , item2 )
1636
+
1637
+ resp = await app_client .post (
1638
+ "/search" ,
1639
+ json = {
1640
+ "datetime" : "2020-01-01T12:00:00Z" ,
1641
+ "collections" : [test_collection ["id" ]],
1642
+ "limit" : 10 ,
1643
+ },
1644
+ )
1645
+
1646
+ assert resp .status_code == 200
1647
+ resp_json = resp .json ()
1648
+
1649
+ found_ids = {feature ["id" ] for feature in resp_json ["features" ]}
1650
+
1651
+ assert "test-item-datetime-only" not in found_ids
1652
+ assert "test-item-start-end-only" in found_ids
0 commit comments