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