Skip to content

Add support for filtering by remaining inventory #17

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added

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

### Changed

Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ Projects are the ways Patch takes CO2 out of the air. They can represent refores
When fetching projects, you can supply filters to the query to narrow your result. Currently supported filters are:
- `country`
- `type`
- `minimum_available_mass`

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

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

# Retrieve a list of projects from Canada
patch.projects.retrieve_projects(country="CA")

# Retrieve a list of projects with at least 100 grams of available offsets
patch.projects.retrieve_projects(minimum_available_mass=100)
```

### Preferences
Expand Down
8 changes: 7 additions & 1 deletion patch_api/api/projects_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ def retrieve_projects(self, **kwargs): # noqa: E501
:param int page:
:param str country:
:param str type:
:param int minimum_available_mass:
:param _preload_content: if False, the urllib3.HTTPResponse object will
be returned without reading/decoding response
data. Default is True.
Expand Down Expand Up @@ -212,6 +213,7 @@ def retrieve_projects_with_http_info(self, **kwargs): # noqa: E501
:param int page:
:param str country:
:param str type:
:param int minimum_available_mass:
:param _return_http_data_only: response data without head status code
and headers
:param _preload_content: if False, the urllib3.HTTPResponse object will
Expand All @@ -228,7 +230,7 @@ def retrieve_projects_with_http_info(self, **kwargs): # noqa: E501

local_var_params = locals()

all_params = ["page", "country", "type"] # noqa: E501
all_params = ["page", "country", "type", "minimum_available_mass"] # noqa: E501
all_params.append("async_req")
all_params.append("_return_http_data_only")
all_params.append("_preload_content")
Expand Down Expand Up @@ -267,6 +269,10 @@ def retrieve_projects_with_http_info(self, **kwargs): # noqa: E501
query_params.append(("country", local_var_params["country"])) # noqa: E501
if "type" in local_var_params:
query_params.append(("type", local_var_params["type"])) # noqa: E501
if "minimum_available_mass" in local_var_params:
query_params.append(
("minimum_available_mass", local_var_params["minimum_available_mass"])
) # noqa: E501

header_params = {}

Expand Down
1 change: 0 additions & 1 deletion test/test_orders_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ def test_retrieve_orders(self):
self.assertTrue(retrieved_order.id)
self.assertEqual(retrieved_order.production, False)
self.assertEqual(retrieved_order.state, "placed")
self.assertEqual(retrieved_order.allocation_state, "allocated")
self.assertEqual(retrieved_order.metadata, {})
self.assertTrue(isinstance(retrieved_order.allocations, list))

Expand Down
14 changes: 14 additions & 0 deletions test/test_projects_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,20 @@ def test_retrieve_american_projects(self):
for project in projects:
self.assertEqual(project.country, project_country)

def test_retrieve_projects_with_more_than_100_grams_of_inventory(self):
"""Test case for retrieve_projects with a country filter

Retrieves a list of projects # noqa: E501
"""
minimum_available_mass = 100
projects = self.api.retrieve_projects(
minimum_available_mass=minimum_available_mass
).data
self.assertTrue(isinstance(projects, list))

for project in projects:
self.assertTrue(project.remaining_mass_g >= minimum_available_mass)


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