diff --git a/rachiopy/rachioobject.py b/rachiopy/rachioobject.py index 11e4122..4eec922 100644 --- a/rachiopy/rachioobject.py +++ b/rachiopy/rachioobject.py @@ -33,7 +33,7 @@ def __init__(self, authtoken: str, http_session=None, timeout=25): self.timeout = timeout def _request(self, path: str, method: str, body=None): - """Make a request from the API. + """Make a request to the API. :return: The return value is a tuple of (response, content), the first being and instance of the httplib2.Response class, the second @@ -103,7 +103,7 @@ def delete_request(self, path: str, body=None): return self._request(path, "DELETE", body) def _valve_request(self, path: str, method: str, body=None): - """Make a request from the API. + """Make a request to the API. :return: The return value is a tuple of (response, content), the first being and instance of the httplib2.Response class, the second diff --git a/tests/test_valve.py b/tests/test_valve.py index a4e5b65..d9ab8e7 100644 --- a/tests/test_valve.py +++ b/tests/test_valve.py @@ -110,12 +110,21 @@ def test_set_default_runtime(self, mock): ), ) + @patch("requests.Session.request") + def test_set_default_runtime_exception(self, mock): + """Test if the set_default_runtime method catches incorrect values.""" + mock.return_value = RESPONSE200 + + valveid = str(uuid.uuid4()) + duration1 = randrange(-50, -1) + duration2 = randrange(86401, 86500) + # Check that values should be within range. self.assertRaises( - AssertionError, self.valve.start_watering, valveid, -1 + AssertionError, self.valve.start_watering, valveid, duration1 ) self.assertRaises( - AssertionError, self.valve.start_watering, valveid, 86401 + AssertionError, self.valve.start_watering, valveid, duration2 ) @patch("requests.Session.request") @@ -138,12 +147,21 @@ def test_start_watering(self, mock): json.dumps({"valveId": valveid, "durationSeconds": duration}), ) + @patch("requests.Session.request") + def test_start_watering_exception(self, mock): + """Test if the start_watering method catches incorrect values.""" + mock.return_value = RESPONSE204 + + valveid = str(uuid.uuid4()) + duration1 = randrange(-50, -1) + duration2 = randrange(86401, 86500) + # Check that values should be within range. self.assertRaises( - AssertionError, self.valve.start_watering, valveid, -1 + AssertionError, self.valve.start_watering, valveid, duration1 ) self.assertRaises( - AssertionError, self.valve.start_watering, valveid, 86401 + AssertionError, self.valve.start_watering, valveid, duration2 ) @patch("requests.Session.request")