diff --git a/CHANGELOG.md b/CHANGELOG.md index dd8ed0c..43e300b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # Changelog +## [v0.19.0](https://github.com/SebRut/pygrocy/tree/v0.19.0) (2020-08-14) + +[Full Changelog](https://github.com/SebRut/pygrocy/compare/v0.18.0...v0.19.0) + +**Merged pull requests:** + +- Add endpoint for adding generic entity [\#115](https://github.com/SebRut/pygrocy/pull/115) ([isabellaalstrom](https://github.com/isabellaalstrom)) + ## [v0.18.0](https://github.com/SebRut/pygrocy/tree/v0.18.0) (2020-08-14) [Full Changelog](https://github.com/SebRut/pygrocy/compare/v0.17.0...v0.18.0) diff --git a/pygrocy/grocy.py b/pygrocy/grocy.py index 5506f68..d7b7090 100644 --- a/pygrocy/grocy.py +++ b/pygrocy/grocy.py @@ -607,3 +607,6 @@ def recipe(self, recipe_id: int) -> RecipeItem: recipe = self._api_client.get_recipe(recipe_id) if recipe: return RecipeItem(recipe) + + def add_generic(self, entity_type, data): + return self._api_client.add_generic(entity_type, data) diff --git a/pygrocy/grocy_api_client.py b/pygrocy/grocy_api_client.py index aa4e7cd..4ffe858 100644 --- a/pygrocy/grocy_api_client.py +++ b/pygrocy/grocy_api_client.py @@ -672,3 +672,6 @@ def get_recipe(self, object_id: int) -> RecipeDetailsResponse: parsed_json = self._do_get_request(f"objects/recipes/{object_id}") if parsed_json: return RecipeDetailsResponse(parsed_json) + + def add_generic(self, entity_type: str, data: object): + self._do_post_request(f"objects/{entity_type}", data) diff --git a/setup.py b/setup.py index b3d4f26..fe49a23 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ setuptools.setup( name="pygrocy", - version="0.18.0", + version="0.19.0", author="Sebastian Rutofski", author_email="kontakt@sebastian-rutofski.de", description="", diff --git a/test/test_grocy.py b/test/test_grocy.py index 2a742cc..c89676a 100644 --- a/test/test_grocy.py +++ b/test/test_grocy.py @@ -21,6 +21,7 @@ def setUp(self): ) self.base_url = f"{CONST_BASE_URL}:{CONST_PORT}/api" self.date_test = datetime.strptime("2019-05-04 11:31:04", "%Y-%m-%d %H:%M:%S") + self.add_generic_data = {"name": "This is a task"} def test_init(self): self.assertIsInstance(self.grocy, Grocy) @@ -432,6 +433,22 @@ def test_add_product_error(self): HTTPError, self.grocy.add_product, 1, 1.3, 2.44, self.date_test ) + @responses.activate + def test_add_generic_valid(self): + responses.add( + responses.POST, f"{self.base_url}/objects/tasks", status=200 + ) + self.assertIsNone(self.grocy.add_generic("tasks", self.add_generic_data)) + + @responses.activate + def test_add_generic_error(self): + responses.add( + responses.POST, f"{self.base_url}/objects/tasks", status=400 + ) + self.assertRaises( + HTTPError, self.grocy.add_generic, "tasks", self.add_generic_data + ) + @responses.activate def test_consume_product_valid(self): responses.add(