From 1286b661326250ad0fa301fcb65976e94061574f Mon Sep 17 00:00:00 2001 From: Sebastian Rutofski Date: Mon, 23 Aug 2021 10:24:34 +0200 Subject: [PATCH 1/2] add execute chore tests --- ...TestChores.test_execute_chore_invalid.yaml | 44 +++++++++++++++++ .../TestChores.test_execute_chore_valid.yaml | 49 +++++++++++++++++++ ...es.test_execute_chore_valid_with_data.yaml | 49 +++++++++++++++++++ test/test_chores.py | 21 ++++++++ 4 files changed, 163 insertions(+) create mode 100644 test/cassettes/test_chores/TestChores.test_execute_chore_invalid.yaml create mode 100644 test/cassettes/test_chores/TestChores.test_execute_chore_valid.yaml create mode 100644 test/cassettes/test_chores/TestChores.test_execute_chore_valid_with_data.yaml diff --git a/test/cassettes/test_chores/TestChores.test_execute_chore_invalid.yaml b/test/cassettes/test_chores/TestChores.test_execute_chore_invalid.yaml new file mode 100644 index 0000000..8811b32 --- /dev/null +++ b/test/cassettes/test_chores/TestChores.test_execute_chore_invalid.yaml @@ -0,0 +1,44 @@ +interactions: +- request: + body: '{"tracked_time": "2021-08-23T08:17:14.341685+00:00"}' + headers: + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + Content-Length: + - '52' + Content-Type: + - application/json + User-Agent: + - python-requests/2.25.1 + accept: + - application/json + method: POST + uri: https://localhost/api/chores/1000/execute + response: + body: + string: '{"error_message":"Chore does not exist"}' + headers: + Access-Control-Allow-Headers: + - '*' + Access-Control-Allow-Methods: + - GET, POST, PUT, DELETE, OPTIONS + Access-Control-Allow-Origin: + - '*' + Connection: + - keep-alive + Content-Type: + - application/json + Date: + - Mon, 23 Aug 2021 08:17:14 GMT + Server: + - nginx/1.20.1 + Transfer-Encoding: + - chunked + X-Powered-By: + - PHP/8.0.9 + status: + code: 400 + message: Bad Request +version: 1 diff --git a/test/cassettes/test_chores/TestChores.test_execute_chore_valid.yaml b/test/cassettes/test_chores/TestChores.test_execute_chore_valid.yaml new file mode 100644 index 0000000..b19bf11 --- /dev/null +++ b/test/cassettes/test_chores/TestChores.test_execute_chore_valid.yaml @@ -0,0 +1,49 @@ +interactions: +- request: + body: '{"tracked_time": "2021-08-23T08:17:14.341685+00:00"}' + headers: + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + Content-Length: + - '52' + Content-Type: + - application/json + User-Agent: + - python-requests/2.25.1 + accept: + - application/json + method: POST + uri: https://localhost/api/chores/1/execute + response: + body: + string: !!binary | + H4sIAAAAAAAEA3WNywrCMBBFf0XuOoUkCpb5mSEmAxbbRKYJUsR/lz5curtncc59Y0gg5w3ivajw + RgZVQ3xI4jpMAoK33nW27/z5ZHtyV3IXGKSShW8Lt1n0J2p5cVQJ9ZDnGqbn30LLawNkDfa5HR5O + buP4+QLriBPloAAAAA== + headers: + Access-Control-Allow-Headers: + - '*' + Access-Control-Allow-Methods: + - GET, POST, PUT, DELETE, OPTIONS + Access-Control-Allow-Origin: + - '*' + Connection: + - keep-alive + Content-Encoding: + - gzip + Content-Type: + - application/json + Date: + - Mon, 23 Aug 2021 08:17:14 GMT + Server: + - nginx/1.20.1 + Transfer-Encoding: + - chunked + X-Powered-By: + - PHP/8.0.9 + status: + code: 200 + message: OK +version: 1 diff --git a/test/cassettes/test_chores/TestChores.test_execute_chore_valid_with_data.yaml b/test/cassettes/test_chores/TestChores.test_execute_chore_valid_with_data.yaml new file mode 100644 index 0000000..5012525 --- /dev/null +++ b/test/cassettes/test_chores/TestChores.test_execute_chore_valid_with_data.yaml @@ -0,0 +1,49 @@ +interactions: +- request: + body: '{"tracked_time": "2020-12-01T15:00:00+00:00", "done_by": 1}' + headers: + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + Content-Length: + - '59' + Content-Type: + - application/json + User-Agent: + - python-requests/2.25.1 + accept: + - application/json + method: POST + uri: https://localhost/api/chores/1/execute + response: + body: + string: !!binary | + H4sIAAAAAAAEA3WNywrCMBBFf0XuOoU0QSzzM0NMBiy2iUwTRMR/lz5curtncc59Y0yg3hvEW1Hh + jQyqhniXxHWcBQRnXd/ZoXP+ZAdyns4XGKSSha8vbovoT9Ty5KgS6iEvNcyPv4WW1wbIGuxzOzyc + 3Kbp8wVSZJlQoAAAAA== + headers: + Access-Control-Allow-Headers: + - '*' + Access-Control-Allow-Methods: + - GET, POST, PUT, DELETE, OPTIONS + Access-Control-Allow-Origin: + - '*' + Connection: + - keep-alive + Content-Encoding: + - gzip + Content-Type: + - application/json + Date: + - Mon, 23 Aug 2021 08:23:57 GMT + Server: + - nginx/1.20.1 + Transfer-Encoding: + - chunked + X-Powered-By: + - PHP/8.0.9 + status: + code: 200 + message: OK +version: 1 diff --git a/test/test_chores.py b/test/test_chores.py index 7e56442..b165139 100644 --- a/test/test_chores.py +++ b/test/test_chores.py @@ -4,6 +4,7 @@ from pygrocy.data_models.chore import AssignmentType, Chore, PeriodType from pygrocy.data_models.user import User +from pygrocy.errors.grocy_error import GrocyError class TestChores: @@ -42,3 +43,23 @@ def test_get_chore_details(self, grocy): assert chore_details.next_execution_assigned_user.id == 2 assert chore_details.next_execution_assigned_to_user_id == 2 assert chore_details.userfields is None + + @pytest.mark.vcr + def test_execute_chore_valid(self, grocy): + result = grocy.execute_chore(1) + assert not isinstance(result, GrocyError) + + @pytest.mark.vcr + def test_execute_chore_valid_with_data(self, grocy): + result = grocy.execute_chore( + 1, done_by=1, tracked_time=datetime.fromisoformat("2020-12-01T16:00:00") + ) + assert not isinstance(result, GrocyError) + + @pytest.mark.vcr + def test_execute_chore_invalid(self, grocy): + with pytest.raises(GrocyError) as exc_info: + grocy.execute_chore(1000) + + error = exc_info.value + assert error.status_code == 400 From fdcb2b685bcd57bc09f9f1806b15b97da0d27855 Mon Sep 17 00:00:00 2001 From: Sebastian Rutofski Date: Mon, 23 Aug 2021 10:51:36 +0200 Subject: [PATCH 2/2] change test for py36 compability --- test/test_chores.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/test/test_chores.py b/test/test_chores.py index b165139..0a19823 100644 --- a/test/test_chores.py +++ b/test/test_chores.py @@ -51,9 +51,7 @@ def test_execute_chore_valid(self, grocy): @pytest.mark.vcr def test_execute_chore_valid_with_data(self, grocy): - result = grocy.execute_chore( - 1, done_by=1, tracked_time=datetime.fromisoformat("2020-12-01T16:00:00") - ) + result = grocy.execute_chore(1, done_by=1, tracked_time=datetime.now()) assert not isinstance(result, GrocyError) @pytest.mark.vcr