From fc35276f6aad7e41f073c98c644d635680ccce84 Mon Sep 17 00:00:00 2001 From: Marco Julian Moser Date: Sun, 15 Oct 2023 16:31:00 +0000 Subject: [PATCH 1/8] create Todos class --- src/sxapi/publicV2/todos.py | 44 +++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 src/sxapi/publicV2/todos.py diff --git a/src/sxapi/publicV2/todos.py b/src/sxapi/publicV2/todos.py new file mode 100644 index 0000000..a876383 --- /dev/null +++ b/src/sxapi/publicV2/todos.py @@ -0,0 +1,44 @@ +class Todos: + def __init__(self, api=None): + self.api = api + self.path_suffix = "/todos" + + def post_todos(self, todo_id, organisation_id, **kwargs): + params = {"organisation_id": organisation_id, "todo_id": todo_id} + + for k, v in kwargs.items(): + params[k] = v + + self.api.post(self.path_suffix, json=params) + + def put_todos(self, todo_id, **kwargs): + params = {} + for k, v in kwargs.items(): + params[k] = v + + url_suffix = self.path_suffix + f"/{todo_id}" + return self.api.put(url_suffix, json=params) + + def get_todos(self, todo_id): + return self.api.get(self.path_suffix + f"/{todo_id}") + + def post_todos_comment(self, todo_id, content): + params = { + "content": content, + } + + url_suffix = self.path_suffix + f"/{todo_id}/comments" + return self.api.post(url_suffix, json=params) + + def delete_todos_comment(self, todo_id, comment_id): + + url_suffix = self.path_suffix + f"/{todo_id}/comments/{comment_id}" + return self.api.delete(url_suffix) + + def put_todos_comment(self, todo_id, comment_id, content): + params = { + "content": content, + } + + url_suffix = self.path_suffix + f"/{todo_id}/comments/{comment_id}" + return self.api.put(url_suffix, json=params) From 042af2b8606a4515f8175493f5b7b0d37870087f Mon Sep 17 00:00:00 2001 From: Marco Julian Moser Date: Sun, 15 Oct 2023 16:32:07 +0000 Subject: [PATCH 2/8] added test --- tests/test_publicV2/test_get_sensor_data.py | 50 ++++++++++++ tests/test_publicV2/test_todos.py | 90 +++++++++++++++++++++ 2 files changed, 140 insertions(+) create mode 100644 tests/test_publicV2/test_get_sensor_data.py create mode 100644 tests/test_publicV2/test_todos.py diff --git a/tests/test_publicV2/test_get_sensor_data.py b/tests/test_publicV2/test_get_sensor_data.py new file mode 100644 index 0000000..c675cdc --- /dev/null +++ b/tests/test_publicV2/test_get_sensor_data.py @@ -0,0 +1,50 @@ +import mock + +from sxapi.base import ( + IntegrationAPIV2, + PublicAPIV2, +) +from sxapi.publicV2.sensordata import get_sensor_data_from_animal + + +@mock.patch("builtins.print") +@mock.patch("sxapi.base.PublicAPIV2.get") +def test_get_sensor_data(get_mock, print_mock): + get_sensor_data_from_animal(IntegrationAPIV2(), "animal_id") + call_args = print_mock.call_args_list[0] + assert print_mock.call_count == 1 + assert call_args.args[0] == "This function is only available to PublicAPIV2!" + print_mock.reset_mock() + + get_sensor_data_from_animal( + PublicAPIV2(), "1233455", metrics="act", to_date=["21-12-2"] + ) + call_args = print_mock.call_args_list[0] + assert print_mock.call_count == 1 + assert call_args.args[0] == "to_date has not the right format YYYY-MM-DD!" + print_mock.reset_mock() + + get_sensor_data_from_animal( + PublicAPIV2(), + "1233455", + metrics="act", + to_date=["2001-12-2"], + from_date=["0334"], + ) + call_args = print_mock.call_args_list[0] + assert print_mock.call_count == 1 + assert call_args.args[0] == "from_date has not the right format YYYY-MM-DD!" + print_mock.reset_mock() + + get_sensor_data_from_animal( + PublicAPIV2(), + "1233455", + metrics="act", + to_date=["2001-12-02"], + from_date=["2001-11-02"], + ) + + get_mock.assert_called_once_with( + "/data/animals/1233455.json?" + "metrics=act&to_date=2001-12-02+00%3A00%3A00&from_date=2001-11-02+00%3A00%3A00" + ) diff --git a/tests/test_publicV2/test_todos.py b/tests/test_publicV2/test_todos.py new file mode 100644 index 0000000..7761281 --- /dev/null +++ b/tests/test_publicV2/test_todos.py @@ -0,0 +1,90 @@ +import mock + +from sxapi.base import PublicAPIV2 + + +@mock.patch("sxapi.base.PublicAPIV2.post") +def test_post_todos(post_mock): + test_api = PublicAPIV2() + test_api.todos.post_todos( + "test_todo_id", "test_orga_id", kwarg1="kwarg1", optional2="optional2" + ) + + call_args = post_mock.call_args_list[0] + + assert post_mock.call_count == 1 + assert call_args.args[0] == "/todos" + assert call_args.kwargs["json"] == { + "todo_id": "test_todo_id", + "organisation_id": "test_orga_id", + "kwarg1": "kwarg1", + "optional2": "optional2", + } + + +@mock.patch("sxapi.base.PublicAPIV2.post") +def test_post_todo_comment(post_mock): + test_api = PublicAPIV2() + test_api.todos.post_todos_comment("test_todo_id", content="comment_content") + + call_args = post_mock.call_args_list[0] + + assert post_mock.call_count == 1 + assert call_args.args[0] == "/todos/test_todo_id/comments" + assert call_args.kwargs["json"] == { + "content": "comment_content", + } + + +@mock.patch("sxapi.base.PublicAPIV2.put") +def test_put_todos(put_mock): + test_api = PublicAPIV2() + test_api.todos.put_todos("test_todo_id", kwarg1="1", kwarg2="2", kwarg3=3) + + call_args = put_mock.call_args_list[0] + + assert put_mock.call_count == 1 + assert call_args.args[0] == "/todos/test_todo_id" + assert call_args.kwargs["json"] == { + "kwarg1": "1", + "kwarg2": "2", + "kwarg3": 3, + } + + +@mock.patch("sxapi.base.PublicAPIV2.put") +def test_put_todo_comments(get_mock): + test_api = PublicAPIV2() + test_api.todos.put_todos_comment( + "test_todo_id", "test_comment_id", "updated_content" + ) + + call_args = get_mock.call_args_list[0] + + assert get_mock.call_count == 1 + assert call_args.args[0] == "/todos/test_todo_id/comments/test_comment_id" + assert call_args.kwargs["json"] == {"content": "updated_content"} + + +@mock.patch("sxapi.base.PublicAPIV2.get") +def test_get_todos(get_mock): + test_api = PublicAPIV2() + test_api.todos.get_todos("test_todo_id") + + call_args = get_mock.call_args_list[0] + + assert get_mock.call_count == 1 + assert call_args.args[0] == "/todos/test_todo_id" + assert call_args.kwargs == {} + + +@mock.patch("sxapi.base.PublicAPIV2.delete") +def test_delete_todo_comments(get_mock): + test_api = PublicAPIV2() + test_api.todos.delete_todos_comment("test_todo_id", "test_comment_id") + + call_args = get_mock.call_args_list[0] + + assert get_mock.call_count == 1 + assert call_args.args[0] == "/todos/test_todo_id/comments/test_comment_id" + assert call_args.kwargs == {} From 13e53cf44d68ea80cd03b268fa8b61147995f674 Mon Sep 17 00:00:00 2001 From: Marco Julian Moser Date: Sun, 15 Oct 2023 16:33:19 +0000 Subject: [PATCH 3/8] renamed test file --- tests/test_publicV2.py | 50 ------------------------------------------ 1 file changed, 50 deletions(-) delete mode 100644 tests/test_publicV2.py diff --git a/tests/test_publicV2.py b/tests/test_publicV2.py deleted file mode 100644 index c675cdc..0000000 --- a/tests/test_publicV2.py +++ /dev/null @@ -1,50 +0,0 @@ -import mock - -from sxapi.base import ( - IntegrationAPIV2, - PublicAPIV2, -) -from sxapi.publicV2.sensordata import get_sensor_data_from_animal - - -@mock.patch("builtins.print") -@mock.patch("sxapi.base.PublicAPIV2.get") -def test_get_sensor_data(get_mock, print_mock): - get_sensor_data_from_animal(IntegrationAPIV2(), "animal_id") - call_args = print_mock.call_args_list[0] - assert print_mock.call_count == 1 - assert call_args.args[0] == "This function is only available to PublicAPIV2!" - print_mock.reset_mock() - - get_sensor_data_from_animal( - PublicAPIV2(), "1233455", metrics="act", to_date=["21-12-2"] - ) - call_args = print_mock.call_args_list[0] - assert print_mock.call_count == 1 - assert call_args.args[0] == "to_date has not the right format YYYY-MM-DD!" - print_mock.reset_mock() - - get_sensor_data_from_animal( - PublicAPIV2(), - "1233455", - metrics="act", - to_date=["2001-12-2"], - from_date=["0334"], - ) - call_args = print_mock.call_args_list[0] - assert print_mock.call_count == 1 - assert call_args.args[0] == "from_date has not the right format YYYY-MM-DD!" - print_mock.reset_mock() - - get_sensor_data_from_animal( - PublicAPIV2(), - "1233455", - metrics="act", - to_date=["2001-12-02"], - from_date=["2001-11-02"], - ) - - get_mock.assert_called_once_with( - "/data/animals/1233455.json?" - "metrics=act&to_date=2001-12-02+00%3A00%3A00&from_date=2001-11-02+00%3A00%3A00" - ) From 0e43497fc747c1ba1d2510b2b01a1539d92f27fb Mon Sep 17 00:00:00 2001 From: Marco Julian Moser Date: Sun, 15 Oct 2023 16:36:05 +0000 Subject: [PATCH 4/8] moved publicApiV2 impelemntation to publicV2 folder --- src/sxapi/base.py | 15 --------------- src/sxapi/publicV2/__init__.py | 24 ++++++++++++++++++++++++ 2 files changed, 24 insertions(+), 15 deletions(-) create mode 100644 src/sxapi/publicV2/__init__.py diff --git a/src/sxapi/base.py b/src/sxapi/base.py index 783af59..ea3ce77 100644 --- a/src/sxapi/base.py +++ b/src/sxapi/base.py @@ -5,7 +5,6 @@ import requests -PUBLIC_API_V2_BASE_URL = "https://api.smaxtec.com/api/v2" INTEGRATION_API_V2_BASE_URL = "https://api.smaxtec.com/integration/v2" @@ -93,20 +92,6 @@ def delete(self, path, *args, **kwargs): return r.json() -class PublicAPIV2(BaseAPI): - def __init__(self, base_url=None, email=None, password=None, api_token=None): - """Initialize a new public api client instance.""" - base_url = base_url or PUBLIC_API_V2_BASE_URL - api_type = ApiTypes.PUBLIC - super().__init__( - base_url, - email=email, - password=password, - api_token=api_token, - api_type=api_type, - ) - - class IntegrationAPIV2(BaseAPI): def __init__(self, base_url=None, email=None, password=None, api_token=None): """Initialize a new integration api client instance.""" diff --git a/src/sxapi/publicV2/__init__.py b/src/sxapi/publicV2/__init__.py new file mode 100644 index 0000000..bcf1829 --- /dev/null +++ b/src/sxapi/publicV2/__init__.py @@ -0,0 +1,24 @@ +from sxapi.base import ( + ApiTypes, + BaseAPI, +) +from sxapi.publicV2.todos import Todos + +PUBLIC_API_V2_BASE_URL = "https://api.smaxtec.com/api/v2" + + +class PublicAPIV2(BaseAPI): + def __init__(self, base_url=None, email=None, password=None, api_token=None): + """Initialize a new public api client instance.""" + base_url = base_url or PUBLIC_API_V2_BASE_URL + api_type = ApiTypes.PUBLIC + + self.todos = Todos(api=self) + + super().__init__( + base_url, + email=email, + password=password, + api_token=api_token, + api_type=api_type, + ) From 306adf5919e51ba6f4b99fec7447595d50daf7db Mon Sep 17 00:00:00 2001 From: Marco Julian Moser Date: Mon, 16 Oct 2023 19:19:16 +0000 Subject: [PATCH 5/8] fixed imports after moving publicAPIV2 class --- src/sxapi/cli/cli_user.py | 6 ++---- src/sxapi/cli/subparser/token.py | 2 +- src/sxapi/publicV2/sensordata.py | 2 +- tests/cli_tests/test_cli.py | 4 ++-- tests/cli_tests/test_gsd_subparser.py | 2 +- tests/cli_tests/test_token_subparser.py | 4 ++-- tests/test_base.py | 6 ++---- tests/test_publicV2/test_get_sensor_data.py | 8 +++----- tests/test_publicV2/test_todos.py | 14 +++++++------- 9 files changed, 21 insertions(+), 27 deletions(-) diff --git a/src/sxapi/cli/cli_user.py b/src/sxapi/cli/cli_user.py index 54a7877..f7d2d3f 100644 --- a/src/sxapi/cli/cli_user.py +++ b/src/sxapi/cli/cli_user.py @@ -2,10 +2,8 @@ import keyring -from sxapi.base import ( - IntegrationAPIV2, - PublicAPIV2, -) +from sxapi.base import IntegrationAPIV2 +from sxapi.publicV2 import PublicAPIV2 class CliUser: diff --git a/src/sxapi/cli/subparser/token.py b/src/sxapi/cli/subparser/token.py index 1a24925..28b5a9f 100644 --- a/src/sxapi/cli/subparser/token.py +++ b/src/sxapi/cli/subparser/token.py @@ -2,8 +2,8 @@ import requests -from sxapi.base import PublicAPIV2 from sxapi.cli import cli_user +from sxapi.publicV2 import PublicAPIV2 def create_token_parser(subparsers): diff --git a/src/sxapi/publicV2/sensordata.py b/src/sxapi/publicV2/sensordata.py index 656da16..fc205ab 100644 --- a/src/sxapi/publicV2/sensordata.py +++ b/src/sxapi/publicV2/sensordata.py @@ -4,7 +4,7 @@ ) from urllib.parse import urlencode -from ..base import PublicAPIV2 +from sxapi.publicV2 import PublicAPIV2 def get_sensor_data_from_animal(api, animal_id, *args, **kwargs): diff --git a/tests/cli_tests/test_cli.py b/tests/cli_tests/test_cli.py index 3ae4653..d3fed55 100644 --- a/tests/cli_tests/test_cli.py +++ b/tests/cli_tests/test_cli.py @@ -11,7 +11,7 @@ @mock.patch("sxapi.cli.cli.Cli.version_info") @mock.patch("builtins.print") @mock.patch("sxapi.cli.cli_user.get_token_keyring", return_value="keyring-token") -@mock.patch("sxapi.base.PublicAPIV2.get_token", return_value="keyring-token") +@mock.patch("sxapi.publicV2.PublicAPIV2.get_token", return_value="keyring-token") def test_func(get_token_mock, keyring_mock, print_mock, version_mock): with mock.patch("sys.argv", ["sx_api", "--version"]): assert version_mock.call_count == 0 @@ -86,7 +86,7 @@ def test_config(keyring_mock, version_mock): @mock.patch("sxapi.cli.cli.Cli.version_info") @mock.patch("sxapi.cli.cli_user.get_token_keyring", return_value="keyring-token") -@mock.patch("sxapi.base.PublicAPIV2.get_token", return_value="api-token") +@mock.patch("sxapi.publicV2.PublicAPIV2.get_token", return_value="api-token") def test_init_user(api_mock, k_mock, version_mock): with mock.patch( "sys.argv", diff --git a/tests/cli_tests/test_gsd_subparser.py b/tests/cli_tests/test_gsd_subparser.py index 4b1005d..6a8afea 100644 --- a/tests/cli_tests/test_gsd_subparser.py +++ b/tests/cli_tests/test_gsd_subparser.py @@ -1,7 +1,7 @@ import mock -from sxapi.base import PublicAPIV2 from sxapi.cli.cli import Cli +from sxapi.publicV2 import PublicAPIV2 args_parser = Cli.parse_args diff --git a/tests/cli_tests/test_token_subparser.py b/tests/cli_tests/test_token_subparser.py index 5b49534..3569b9a 100644 --- a/tests/cli_tests/test_token_subparser.py +++ b/tests/cli_tests/test_token_subparser.py @@ -12,7 +12,7 @@ @mock.patch("builtins.print") -@mock.patch("sxapi.base.PublicAPIV2.get_token", return_value="api_token") +@mock.patch("sxapi.publicV2.PublicAPIV2.get_token", return_value="api_token") def test_handle_print_token(api_mock, print_mock): namespace = args_parser(["token", "-p"]) assert namespace.print_token == "ek" @@ -118,7 +118,7 @@ def test_handle_new_token(creds_mock, getpass_mock, print_mock): assert call_args.args[0] == "Username or Password is wrong!" print_mock.reset_mock() - with mock.patch("sxapi.base.PublicAPIV2.get_token", return_value="api_token"): + with mock.patch("sxapi.publicV2.PublicAPIV2.get_token", return_value="api_token"): namespace = args_parser(["token", "-n", "marco@test", "pwd"]) assert namespace.new_token == ["marco@test", "pwd"] handle_new_token(namespace) diff --git a/tests/test_base.py b/tests/test_base.py index 0160da1..e29831a 100644 --- a/tests/test_base.py +++ b/tests/test_base.py @@ -1,9 +1,7 @@ import mock -from sxapi.base import ( - IntegrationAPIV2, - PublicAPIV2, -) +from sxapi.base import IntegrationAPIV2 +from sxapi.publicV2 import PublicAPIV2 @mock.patch("requests.Session.delete") diff --git a/tests/test_publicV2/test_get_sensor_data.py b/tests/test_publicV2/test_get_sensor_data.py index c675cdc..9206422 100644 --- a/tests/test_publicV2/test_get_sensor_data.py +++ b/tests/test_publicV2/test_get_sensor_data.py @@ -1,14 +1,12 @@ import mock -from sxapi.base import ( - IntegrationAPIV2, - PublicAPIV2, -) +from sxapi.base import IntegrationAPIV2 +from sxapi.publicV2 import PublicAPIV2 from sxapi.publicV2.sensordata import get_sensor_data_from_animal @mock.patch("builtins.print") -@mock.patch("sxapi.base.PublicAPIV2.get") +@mock.patch("sxapi.publicV2.PublicAPIV2.get") def test_get_sensor_data(get_mock, print_mock): get_sensor_data_from_animal(IntegrationAPIV2(), "animal_id") call_args = print_mock.call_args_list[0] diff --git a/tests/test_publicV2/test_todos.py b/tests/test_publicV2/test_todos.py index 7761281..e374b52 100644 --- a/tests/test_publicV2/test_todos.py +++ b/tests/test_publicV2/test_todos.py @@ -1,9 +1,9 @@ import mock -from sxapi.base import PublicAPIV2 +from sxapi.publicV2 import PublicAPIV2 -@mock.patch("sxapi.base.PublicAPIV2.post") +@mock.patch("sxapi.publicV2.PublicAPIV2.post") def test_post_todos(post_mock): test_api = PublicAPIV2() test_api.todos.post_todos( @@ -22,7 +22,7 @@ def test_post_todos(post_mock): } -@mock.patch("sxapi.base.PublicAPIV2.post") +@mock.patch("sxapi.publicV2.PublicAPIV2.post") def test_post_todo_comment(post_mock): test_api = PublicAPIV2() test_api.todos.post_todos_comment("test_todo_id", content="comment_content") @@ -36,7 +36,7 @@ def test_post_todo_comment(post_mock): } -@mock.patch("sxapi.base.PublicAPIV2.put") +@mock.patch("sxapi.publicV2.PublicAPIV2.put") def test_put_todos(put_mock): test_api = PublicAPIV2() test_api.todos.put_todos("test_todo_id", kwarg1="1", kwarg2="2", kwarg3=3) @@ -52,7 +52,7 @@ def test_put_todos(put_mock): } -@mock.patch("sxapi.base.PublicAPIV2.put") +@mock.patch("sxapi.publicV2.PublicAPIV2.put") def test_put_todo_comments(get_mock): test_api = PublicAPIV2() test_api.todos.put_todos_comment( @@ -66,7 +66,7 @@ def test_put_todo_comments(get_mock): assert call_args.kwargs["json"] == {"content": "updated_content"} -@mock.patch("sxapi.base.PublicAPIV2.get") +@mock.patch("sxapi.publicV2.PublicAPIV2.get") def test_get_todos(get_mock): test_api = PublicAPIV2() test_api.todos.get_todos("test_todo_id") @@ -78,7 +78,7 @@ def test_get_todos(get_mock): assert call_args.kwargs == {} -@mock.patch("sxapi.base.PublicAPIV2.delete") +@mock.patch("sxapi.publicV2.PublicAPIV2.delete") def test_delete_todo_comments(get_mock): test_api = PublicAPIV2() test_api.todos.delete_todos_comment("test_todo_id", "test_comment_id") From e7144ef84f966adcd5a6d05eeb5d5c033e092c24 Mon Sep 17 00:00:00 2001 From: Marco Julian Moser Date: Mon, 16 Oct 2023 20:07:05 +0000 Subject: [PATCH 6/8] added docstrings --- src/sxapi/publicV2/todos.py | 74 ++++++++++++++++++++++++++++++- tests/test_publicV2/test_todos.py | 4 +- 2 files changed, 74 insertions(+), 4 deletions(-) diff --git a/src/sxapi/publicV2/todos.py b/src/sxapi/publicV2/todos.py index a876383..af6a655 100644 --- a/src/sxapi/publicV2/todos.py +++ b/src/sxapi/publicV2/todos.py @@ -1,10 +1,31 @@ class Todos: + """ + This Class represents the /todos endpoint of the PublicAPIV2. + https://api.smaxtec.com/api/v2/ + """ + def __init__(self, api=None): self.api = api self.path_suffix = "/todos" - def post_todos(self, todo_id, organisation_id, **kwargs): - params = {"organisation_id": organisation_id, "todo_id": todo_id} + def post_todos(self, todo_type, organisation_id, **kwargs): + """ + + Args: + todo_type (str): Type of the todo to be created + organisation_id (str): Id of organisation the todo should be created for + **kwargs: Optional parameters of the API call. + Find supported parameters under + https://api.smaxtec.com/api/v2/ + + Returns: + dict: Response of API call. Created todo on success, error message else. + + """ + params = { + "todo_type": todo_type, + "organisation_id": organisation_id, + } for k, v in kwargs.items(): params[k] = v @@ -12,6 +33,18 @@ def post_todos(self, todo_id, organisation_id, **kwargs): self.api.post(self.path_suffix, json=params) def put_todos(self, todo_id, **kwargs): + """ + + Args: + todo_id (str): Id of the todo which should be updated. + **kwargs: Optional parameters of the API call. + Find supported parameters under + https://api.smaxtec.com/api/v2/ + + Returns: + dict: Response of API call. Updated todo on success, error message else. + + """ params = {} for k, v in kwargs.items(): params[k] = v @@ -20,9 +53,27 @@ def put_todos(self, todo_id, **kwargs): return self.api.put(url_suffix, json=params) def get_todos(self, todo_id): + """ + + Args: + todo_id (str): Id of the desired todo + + Returns: + dict: Response of API call. Queried todo on success, error message else. + + """ return self.api.get(self.path_suffix + f"/{todo_id}") def post_todos_comment(self, todo_id, content): + """ + + Args: + todo_id (str): Id of the todo a comment is to be created. + content (str): Content of the comment + + Returns: + dict: Response of API call. Updated todo on success, error message else. + """ params = { "content": content, } @@ -31,11 +82,30 @@ def post_todos_comment(self, todo_id, content): return self.api.post(url_suffix, json=params) def delete_todos_comment(self, todo_id, comment_id): + """ + + Args: + todo_id (str): Id of the todo a comment is to be deleted. + comment_id (str): Id of the comment to delete. + + Returns: + dict: Response of API call. Updated todo on success, error message else. + """ url_suffix = self.path_suffix + f"/{todo_id}/comments/{comment_id}" return self.api.delete(url_suffix) def put_todos_comment(self, todo_id, comment_id, content): + """ + + Args: + todo_id (str): Id of the todo a comment is to be updated. + comment_id (str): Id of the comment to be updated. + content (str): Updated content of the Id. + + Returns: + dict: Response of API call. Updated todo on success, error message else. + """ params = { "content": content, } diff --git a/tests/test_publicV2/test_todos.py b/tests/test_publicV2/test_todos.py index e374b52..d44b6d2 100644 --- a/tests/test_publicV2/test_todos.py +++ b/tests/test_publicV2/test_todos.py @@ -7,7 +7,7 @@ def test_post_todos(post_mock): test_api = PublicAPIV2() test_api.todos.post_todos( - "test_todo_id", "test_orga_id", kwarg1="kwarg1", optional2="optional2" + "test_todo_type", "test_orga_id", kwarg1="kwarg1", optional2="optional2" ) call_args = post_mock.call_args_list[0] @@ -15,7 +15,7 @@ def test_post_todos(post_mock): assert post_mock.call_count == 1 assert call_args.args[0] == "/todos" assert call_args.kwargs["json"] == { - "todo_id": "test_todo_id", + "todo_type": "test_todo_type", "organisation_id": "test_orga_id", "kwarg1": "kwarg1", "optional2": "optional2", From eb963d53ad391d74050aa0d1fac1834c180ccb86 Mon Sep 17 00:00:00 2001 From: Marco Julian Moser Date: Mon, 16 Oct 2023 20:10:41 +0000 Subject: [PATCH 7/8] docstring v2 --- src/sxapi/publicV2/todos.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/sxapi/publicV2/todos.py b/src/sxapi/publicV2/todos.py index af6a655..e545443 100644 --- a/src/sxapi/publicV2/todos.py +++ b/src/sxapi/publicV2/todos.py @@ -9,7 +9,7 @@ def __init__(self, api=None): self.path_suffix = "/todos" def post_todos(self, todo_type, organisation_id, **kwargs): - """ + """Creates a new todo. Args: todo_type (str): Type of the todo to be created @@ -33,7 +33,7 @@ def post_todos(self, todo_type, organisation_id, **kwargs): self.api.post(self.path_suffix, json=params) def put_todos(self, todo_id, **kwargs): - """ + """Updates an existing todo. Args: todo_id (str): Id of the todo which should be updated. @@ -53,7 +53,7 @@ def put_todos(self, todo_id, **kwargs): return self.api.put(url_suffix, json=params) def get_todos(self, todo_id): - """ + """Get one todo. Args: todo_id (str): Id of the desired todo @@ -65,7 +65,7 @@ def get_todos(self, todo_id): return self.api.get(self.path_suffix + f"/{todo_id}") def post_todos_comment(self, todo_id, content): - """ + """Create a comment for a todo. Args: todo_id (str): Id of the todo a comment is to be created. @@ -82,7 +82,7 @@ def post_todos_comment(self, todo_id, content): return self.api.post(url_suffix, json=params) def delete_todos_comment(self, todo_id, comment_id): - """ + """Delete a comment from a todo. Args: todo_id (str): Id of the todo a comment is to be deleted. @@ -96,7 +96,7 @@ def delete_todos_comment(self, todo_id, comment_id): return self.api.delete(url_suffix) def put_todos_comment(self, todo_id, comment_id, content): - """ + """Update a comment from a todo. Args: todo_id (str): Id of the todo a comment is to be updated. From 9601d8735cc60aae31d4a2e190b47d7355990309 Mon Sep 17 00:00:00 2001 From: Marco Julian Moser Date: Fri, 20 Oct 2023 14:29:39 +0000 Subject: [PATCH 8/8] improved naming --- src/sxapi/publicV2/todos.py | 12 ++++++------ tests/test_publicV2/test_todos.py | 14 ++++++-------- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/src/sxapi/publicV2/todos.py b/src/sxapi/publicV2/todos.py index e545443..5ad5c4c 100644 --- a/src/sxapi/publicV2/todos.py +++ b/src/sxapi/publicV2/todos.py @@ -8,7 +8,7 @@ def __init__(self, api=None): self.api = api self.path_suffix = "/todos" - def post_todos(self, todo_type, organisation_id, **kwargs): + def post(self, todo_type, organisation_id, **kwargs): """Creates a new todo. Args: @@ -32,7 +32,7 @@ def post_todos(self, todo_type, organisation_id, **kwargs): self.api.post(self.path_suffix, json=params) - def put_todos(self, todo_id, **kwargs): + def put(self, todo_id, **kwargs): """Updates an existing todo. Args: @@ -52,7 +52,7 @@ def put_todos(self, todo_id, **kwargs): url_suffix = self.path_suffix + f"/{todo_id}" return self.api.put(url_suffix, json=params) - def get_todos(self, todo_id): + def get(self, todo_id): """Get one todo. Args: @@ -64,7 +64,7 @@ def get_todos(self, todo_id): """ return self.api.get(self.path_suffix + f"/{todo_id}") - def post_todos_comment(self, todo_id, content): + def post_comment(self, todo_id, content): """Create a comment for a todo. Args: @@ -81,7 +81,7 @@ def post_todos_comment(self, todo_id, content): url_suffix = self.path_suffix + f"/{todo_id}/comments" return self.api.post(url_suffix, json=params) - def delete_todos_comment(self, todo_id, comment_id): + def delete_comment(self, todo_id, comment_id): """Delete a comment from a todo. Args: @@ -95,7 +95,7 @@ def delete_todos_comment(self, todo_id, comment_id): url_suffix = self.path_suffix + f"/{todo_id}/comments/{comment_id}" return self.api.delete(url_suffix) - def put_todos_comment(self, todo_id, comment_id, content): + def put_comment(self, todo_id, comment_id, content): """Update a comment from a todo. Args: diff --git a/tests/test_publicV2/test_todos.py b/tests/test_publicV2/test_todos.py index d44b6d2..20c6ef0 100644 --- a/tests/test_publicV2/test_todos.py +++ b/tests/test_publicV2/test_todos.py @@ -6,7 +6,7 @@ @mock.patch("sxapi.publicV2.PublicAPIV2.post") def test_post_todos(post_mock): test_api = PublicAPIV2() - test_api.todos.post_todos( + test_api.todos.post( "test_todo_type", "test_orga_id", kwarg1="kwarg1", optional2="optional2" ) @@ -25,7 +25,7 @@ def test_post_todos(post_mock): @mock.patch("sxapi.publicV2.PublicAPIV2.post") def test_post_todo_comment(post_mock): test_api = PublicAPIV2() - test_api.todos.post_todos_comment("test_todo_id", content="comment_content") + test_api.todos.post_comment("test_todo_id", content="comment_content") call_args = post_mock.call_args_list[0] @@ -39,7 +39,7 @@ def test_post_todo_comment(post_mock): @mock.patch("sxapi.publicV2.PublicAPIV2.put") def test_put_todos(put_mock): test_api = PublicAPIV2() - test_api.todos.put_todos("test_todo_id", kwarg1="1", kwarg2="2", kwarg3=3) + test_api.todos.put("test_todo_id", kwarg1="1", kwarg2="2", kwarg3=3) call_args = put_mock.call_args_list[0] @@ -55,9 +55,7 @@ def test_put_todos(put_mock): @mock.patch("sxapi.publicV2.PublicAPIV2.put") def test_put_todo_comments(get_mock): test_api = PublicAPIV2() - test_api.todos.put_todos_comment( - "test_todo_id", "test_comment_id", "updated_content" - ) + test_api.todos.put_comment("test_todo_id", "test_comment_id", "updated_content") call_args = get_mock.call_args_list[0] @@ -69,7 +67,7 @@ def test_put_todo_comments(get_mock): @mock.patch("sxapi.publicV2.PublicAPIV2.get") def test_get_todos(get_mock): test_api = PublicAPIV2() - test_api.todos.get_todos("test_todo_id") + test_api.todos.get("test_todo_id") call_args = get_mock.call_args_list[0] @@ -81,7 +79,7 @@ def test_get_todos(get_mock): @mock.patch("sxapi.publicV2.PublicAPIV2.delete") def test_delete_todo_comments(get_mock): test_api = PublicAPIV2() - test_api.todos.delete_todos_comment("test_todo_id", "test_comment_id") + test_api.todos.delete_comment("test_todo_id", "test_comment_id") call_args = get_mock.call_args_list[0]