@@ -1537,3 +1537,93 @@ async def test_search_max_item_limit(
15371537    assert  resp .status_code  ==  200 
15381538    resp_json  =  resp .json ()
15391539    assert  int (limit ) ==  len (resp_json ["features" ])
1540+ 
1541+ 
1542+ @pytest .mark .asyncio  
1543+ async  def  test_use_datetime_true_finds_both_items (
1544+     app_client , load_test_data , txn_client , monkeypatch 
1545+ ):
1546+     monkeypatch .setenv ("USE_DATETIME" , "true" )
1547+ 
1548+     test_collection  =  load_test_data ("test_collection.json" )
1549+     test_collection ["id" ] =  "test-collection-datetime-true" 
1550+     await  create_collection (txn_client , test_collection )
1551+ 
1552+     item  =  load_test_data ("test_item.json" )
1553+ 
1554+     item1  =  item .copy ()
1555+     item1 ["id" ] =  "test-item-datetime" 
1556+     item1 ["collection" ] =  test_collection ["id" ]
1557+     item1 ["properties" ]["datetime" ] =  "2020-01-01T12:00:00Z" 
1558+     await  create_item (txn_client , item1 )
1559+ 
1560+     item2  =  item .copy ()
1561+     item2 ["id" ] =  "test-item-start-end" 
1562+     item2 ["collection" ] =  test_collection ["id" ]
1563+     item1 ["properties" ]["datetime" ] =  None 
1564+     item2 ["properties" ]["start_datetime" ] =  "2020-01-01T10:00:00Z" 
1565+     item2 ["properties" ]["end_datetime" ] =  "2020-01-01T13:00:00Z" 
1566+     await  create_item (txn_client , item2 )
1567+ 
1568+     resp  =  await  app_client .post (
1569+         "/search" ,
1570+         json = {
1571+             "datetime" : "2020-01-01T12:00:00Z" ,
1572+             "collections" : [test_collection ["id" ]],
1573+         },
1574+     )
1575+ 
1576+     assert  resp .status_code  ==  200 
1577+     resp_json  =  resp .json ()
1578+ 
1579+     found_ids  =  {feature ["id" ] for  feature  in  resp_json ["features" ]}
1580+     assert  "test-item-datetime"  in  found_ids 
1581+     assert  "test-item-start-end"  in  found_ids 
1582+ 
1583+ 
1584+ @pytest .mark .asyncio  
1585+ async  def  test_use_datetime_false_search (
1586+     app_client , load_test_data , txn_client , monkeypatch 
1587+ ):
1588+     monkeypatch .setenv ("USE_DATETIME" , "false" )
1589+ 
1590+     test_collection  =  load_test_data ("test_collection.json" )
1591+     test_collection ["id" ] =  "test-collection-datetime-false" 
1592+     await  create_collection (txn_client , test_collection )
1593+ 
1594+     item  =  load_test_data ("test_item.json" )
1595+ 
1596+     # Item 1: Should NOT be found 
1597+     item1  =  item .copy ()
1598+     item1 ["id" ] =  "test-item-datetime-only" 
1599+     item1 ["collection" ] =  test_collection ["id" ]
1600+     item1 ["properties" ]["datetime" ] =  "2020-01-01T12:00:00Z" 
1601+     item1 ["properties" ]["start_datetime" ] =  "2021-01-01T10:00:00Z" 
1602+     item1 ["properties" ]["end_datetime" ] =  "2021-01-01T14:00:00Z" 
1603+     await  create_item (txn_client , item1 )
1604+ 
1605+     # Item 2: Should be found 
1606+     item2  =  item .copy ()
1607+     item2 ["id" ] =  "test-item-start-end-only" 
1608+     item2 ["collection" ] =  test_collection ["id" ]
1609+     item2 ["properties" ]["datetime" ] =  None 
1610+     item2 ["properties" ]["start_datetime" ] =  "2020-01-01T10:00:00Z" 
1611+     item2 ["properties" ]["end_datetime" ] =  "2020-01-01T14:00:00Z" 
1612+     await  create_item (txn_client , item2 )
1613+ 
1614+     resp  =  await  app_client .post (
1615+         "/search" ,
1616+         json = {
1617+             "datetime" : "2020-01-01T12:00:00Z" ,
1618+             "collections" : [test_collection ["id" ]],
1619+             "limit" : 10 ,
1620+         },
1621+     )
1622+ 
1623+     assert  resp .status_code  ==  200 
1624+     resp_json  =  resp .json ()
1625+ 
1626+     found_ids  =  {feature ["id" ] for  feature  in  resp_json ["features" ]}
1627+ 
1628+     assert  "test-item-datetime-only"  not  in   found_ids 
1629+     assert  "test-item-start-end-only"  in  found_ids 
0 commit comments