@@ -1597,6 +1597,23 @@ async def test_get_item_success(item_descriptions, session):
1597
1597
assert respx .calls .last .response .status_code == HTTPStatus .OK
1598
1598
1599
1599
1600
+ @respx .mock
1601
+ def test_get_item_success_sync (item_descriptions , data_api ):
1602
+ """Test getting an item successfully."""
1603
+ item = item_descriptions [0 ]
1604
+ item_id = item ['id' ]
1605
+ item_type = item ['properties' ]['item_type' ]
1606
+ item_url = f'{ TEST_URL } /item-types/{ item_type } /items/{ item_id } '
1607
+
1608
+ respx .get (item_url ).return_value = httpx .Response (HTTPStatus .OK , json = item )
1609
+
1610
+ result = data_api .get_item (item_type , item_id )
1611
+
1612
+ assert result == item
1613
+ assert respx .calls .last .request .url == item_url
1614
+ assert respx .calls .last .response .status_code == HTTPStatus .OK
1615
+
1616
+
1600
1617
@respx .mock
1601
1618
@pytest .mark .anyio
1602
1619
async def test_get_item_not_found (item_descriptions , session ):
@@ -1612,6 +1629,19 @@ async def test_get_item_not_found(item_descriptions, session):
1612
1629
await cl .get_item (item_type , item_id )
1613
1630
1614
1631
1632
+ @respx .mock
1633
+ def test_get_item_not_found_sync (item_descriptions , data_api ):
1634
+ """Test getting a non-existent item."""
1635
+ item_type = item_descriptions [0 ]['properties' ]['item_type' ]
1636
+ item_id = 'non-existent-id'
1637
+ item_url = f'{ TEST_URL } /item-types/{ item_type } /items/{ item_id } '
1638
+
1639
+ respx .get (item_url ).return_value = httpx .Response (404 , json = {})
1640
+
1641
+ with pytest .raises (exceptions .MissingResource ):
1642
+ data_api .get_item (item_type , item_id )
1643
+
1644
+
1615
1645
@respx .mock
1616
1646
@pytest .mark .anyio
1617
1647
async def test_get_item_coverage_success (item_descriptions , session ):
@@ -1657,3 +1687,46 @@ async def test_get_item_coverage_invalid_geometry(item_descriptions, session):
1657
1687
await cl .get_item_coverage (item_type_id = item_type ,
1658
1688
item_id = item_id ,
1659
1689
geometry = invalid_geom )
1690
+
1691
+
1692
+ @respx .mock
1693
+ def test_get_item_coverage_success_sync (item_descriptions , data_api ):
1694
+ """Test get item coverage successfully."""
1695
+ item = item_descriptions [0 ]
1696
+ item_id = item ['id' ]
1697
+ item_type = item ['properties' ]['item_type' ]
1698
+
1699
+ mock_response = {'clear_percent' : 28 , 'status' : 'complete' }
1700
+
1701
+ coverage_url = f'{ TEST_URL } /item-types/{ item_type } /items/{ item_id } /coverage'
1702
+ respx .post (coverage_url ).return_value = httpx .Response (HTTPStatus .OK ,
1703
+ json = mock_response )
1704
+
1705
+ result = data_api .get_item_coverage (item_type_id = item_type ,
1706
+ item_id = item_id ,
1707
+ geometry = item ['geometry' ],
1708
+ mode = 'UDM2' ,
1709
+ band = 'cloud' )
1710
+
1711
+ assert str (respx .calls .last .request .url ).split ('?' )[0 ] == coverage_url
1712
+
1713
+ assert respx .calls .last .request .url .params ['mode' ] == 'UDM2'
1714
+ assert respx .calls .last .request .url .params ['band' ] == 'cloud'
1715
+
1716
+ assert result == mock_response
1717
+
1718
+
1719
+ @respx .mock
1720
+ def test_get_item_coverage_invalid_geometry_sync (item_descriptions , data_api ):
1721
+ """Test get item coverage with invalid geometry."""
1722
+ item = item_descriptions [0 ]
1723
+ item_id = item ['id' ]
1724
+ item_type = item ['properties' ]['item_type' ]
1725
+
1726
+ invalid_geom = copy .deepcopy (item ['geometry' ])
1727
+ invalid_geom ['type' ] = 'invalid_type'
1728
+
1729
+ with pytest .raises (exceptions .GeoJSONError ):
1730
+ data_api .get_item_coverage (item_type_id = item_type ,
1731
+ item_id = item_id ,
1732
+ geometry = invalid_geom )
0 commit comments