Skip to content

Commit ac4a1de

Browse files
authored
Add support for filtering by remaining inventory (#17)
1 parent 2dde633 commit ac4a1de

File tree

5 files changed

+26
-3
lines changed

5 files changed

+26
-3
lines changed

CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
### Added
1111

1212
- Adds Sustainable Development Goals (SDGs) field to projects
13-
- Adds the ability to filter Projects on country, type
13+
- Adds the ability to filter Projects on country, type, minimum_available_mass
1414

1515
### Changed
1616

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ Projects are the ways Patch takes CO2 out of the air. They can represent refores
155155
When fetching projects, you can supply filters to the query to narrow your result. Currently supported filters are:
156156
- `country`
157157
- `type`
158+
- `minimum_available_mass`
158159

159160
[API Reference](https://docs.usepatch.com/#/?id=projects)
160161

@@ -178,6 +179,9 @@ patch.projects.retrieve_projects(type="biomass")
178179

179180
# Retrieve a list of projects from Canada
180181
patch.projects.retrieve_projects(country="CA")
182+
183+
# Retrieve a list of projects with at least 100 grams of available offsets
184+
patch.projects.retrieve_projects(minimum_available_mass=100)
181185
```
182186

183187
### Preferences

patch_api/api/projects_api.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ def retrieve_projects(self, **kwargs): # noqa: E501
185185
:param int page:
186186
:param str country:
187187
:param str type:
188+
:param int minimum_available_mass:
188189
:param _preload_content: if False, the urllib3.HTTPResponse object will
189190
be returned without reading/decoding response
190191
data. Default is True.
@@ -212,6 +213,7 @@ def retrieve_projects_with_http_info(self, **kwargs): # noqa: E501
212213
:param int page:
213214
:param str country:
214215
:param str type:
216+
:param int minimum_available_mass:
215217
:param _return_http_data_only: response data without head status code
216218
and headers
217219
:param _preload_content: if False, the urllib3.HTTPResponse object will
@@ -228,7 +230,7 @@ def retrieve_projects_with_http_info(self, **kwargs): # noqa: E501
228230

229231
local_var_params = locals()
230232

231-
all_params = ["page", "country", "type"] # noqa: E501
233+
all_params = ["page", "country", "type", "minimum_available_mass"] # noqa: E501
232234
all_params.append("async_req")
233235
all_params.append("_return_http_data_only")
234236
all_params.append("_preload_content")
@@ -267,6 +269,10 @@ def retrieve_projects_with_http_info(self, **kwargs): # noqa: E501
267269
query_params.append(("country", local_var_params["country"])) # noqa: E501
268270
if "type" in local_var_params:
269271
query_params.append(("type", local_var_params["type"])) # noqa: E501
272+
if "minimum_available_mass" in local_var_params:
273+
query_params.append(
274+
("minimum_available_mass", local_var_params["minimum_available_mass"])
275+
) # noqa: E501
270276

271277
header_params = {}
272278

test/test_orders_api.py

-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ def test_retrieve_orders(self):
5959
self.assertTrue(retrieved_order.id)
6060
self.assertEqual(retrieved_order.production, False)
6161
self.assertEqual(retrieved_order.state, "placed")
62-
self.assertEqual(retrieved_order.allocation_state, "allocated")
6362
self.assertEqual(retrieved_order.metadata, {})
6463
self.assertTrue(isinstance(retrieved_order.allocations, list))
6564

test/test_projects_api.py

+14
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,20 @@ def test_retrieve_american_projects(self):
8686
for project in projects:
8787
self.assertEqual(project.country, project_country)
8888

89+
def test_retrieve_projects_with_more_than_100_grams_of_inventory(self):
90+
"""Test case for retrieve_projects with a country filter
91+
92+
Retrieves a list of projects # noqa: E501
93+
"""
94+
minimum_available_mass = 100
95+
projects = self.api.retrieve_projects(
96+
minimum_available_mass=minimum_available_mass
97+
).data
98+
self.assertTrue(isinstance(projects, list))
99+
100+
for project in projects:
101+
self.assertTrue(project.remaining_mass_g >= minimum_available_mass)
102+
89103

90104
if __name__ == "__main__":
91105
unittest.main()

0 commit comments

Comments
 (0)