Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
brg468 committed Dec 30, 2023
1 parent c92fd1d commit 04562d3
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
4 changes: 2 additions & 2 deletions rachiopy/rachioobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
26 changes: 22 additions & 4 deletions tests/test_valve.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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")
Expand Down

0 comments on commit 04562d3

Please sign in to comment.