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