Skip to content

Commit

Permalink
Merge pull request #45 from rfverbruggen/1.0.2
Browse files Browse the repository at this point in the history
1.0.2
  • Loading branch information
rfverbruggen authored Oct 7, 2020
2 parents 1dd8522 + 54b9fe3 commit 00a74be
Show file tree
Hide file tree
Showing 9 changed files with 110 additions and 71 deletions.
2 changes: 1 addition & 1 deletion .hound.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
fail_on_violations: true
fail_on_violations: false

python:
enabled: true
2 changes: 2 additions & 0 deletions .pylintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[MESSAGES CONTROL]
disable=R0801
2 changes: 1 addition & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Dependencies
============

- Python 3.6+
- httplib2
- requests

Authors and License
===================
Expand Down
4 changes: 4 additions & 0 deletions rachiopy/rachioobject.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""RachioObject module containing a helper class for all API calls."""
import json

from requests import Session

Expand Down Expand Up @@ -33,6 +34,9 @@ def _request(self, path: str, method: str, body=None):
object if it contains JSON).
:rtype: tuple
"""
if body is not None:
body = json.dumps(body)

url = f"{_API_URL}/{path}"
response = self._http_session.request(
method, url, headers=self._headers, data=body
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Rachiopy setup script."""
from setuptools import find_packages, setup

VERSION = "1.0.1"
VERSION = "1.0.2"

GITHUB_USERNAME = "rfverbruggen"
GITHUB_REPOSITORY = "rachiopy"
Expand All @@ -28,7 +28,7 @@
description="A Python module for the Rachio API.",
platforms="Cross Platform",
classifiers=[
"Development Status :: 4 - Beta",
"Development Status :: 5 - Production/Stable",
"Intended Audience :: Developers",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
Expand Down
33 changes: 17 additions & 16 deletions tests/test_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import unittest
import uuid
import json
from unittest.mock import patch
from random import randrange

Expand All @@ -24,7 +25,7 @@ def test_get(self, mock):
"""Test if the get method works as expected."""
mock.return_value = RESPONSE200

deviceid = uuid.uuid4()
deviceid = str(uuid.uuid4())

self.device.get(deviceid)

Expand All @@ -42,7 +43,7 @@ def test_current_schedule(self, mock):
"""Test if the current schedule method works as expected."""
mock.return_value = RESPONSE200

deviceid = uuid.uuid4()
deviceid = str(uuid.uuid4())

self.device.current_schedule(deviceid)

Expand All @@ -60,7 +61,7 @@ def test_event(self, mock):
"""Test if the event method works as expected."""
mock.return_value = RESPONSE200

deviceid = uuid.uuid4()
deviceid = str(uuid.uuid4())
starttime = 1414818000000
endtime = 1415739608103

Expand All @@ -84,7 +85,7 @@ def test_forecast(self, mock):
"""Test if the forecast method works as expected."""
mock.return_value = RESPONSE200

deviceid = uuid.uuid4()
deviceid = str(uuid.uuid4())

self.device.forecast(deviceid)

Expand Down Expand Up @@ -128,7 +129,7 @@ def test_stop_water(self, mock):
"""Test if the stop water method works as expected."""
mock.return_value = RESPONSE204

deviceid = uuid.uuid4()
deviceid = str(uuid.uuid4())

self.device.stop_water(deviceid)

Expand All @@ -139,14 +140,14 @@ def test_stop_water(self, mock):
args[1], f"{BASE_API_URL}/device/stop_water",
)
self.assertEqual(args[0], "PUT")
self.assertEqual(kwargs["data"], {"id": deviceid})
self.assertEqual(kwargs["data"], json.dumps({"id": deviceid}))

@patch("requests.Session.request")
def test_rain_delay(self, mock):
"""Test if the rain delay method works as expected."""
mock.return_value = RESPONSE204

deviceid = uuid.uuid4()
deviceid = str(uuid.uuid4())
duration = randrange(604800)

self.device.rain_delay(deviceid, duration)
Expand All @@ -159,7 +160,7 @@ def test_rain_delay(self, mock):
)
self.assertEqual(args[0], "PUT")
self.assertEqual(
kwargs["data"], {"id": deviceid, "duration": duration}
kwargs["data"], json.dumps({"id": deviceid, "duration": duration})
)

# Check that values should be within range.
Expand All @@ -173,7 +174,7 @@ def test_turn_on(self, mock):
"""Test if the turn on method works as expected."""
mock.return_value = RESPONSE204

deviceid = uuid.uuid4()
deviceid = str(uuid.uuid4())

self.device.turn_on(deviceid)

Expand All @@ -184,14 +185,14 @@ def test_turn_on(self, mock):
args[1], f"{BASE_API_URL}/device/on",
)
self.assertEqual(args[0], "PUT")
self.assertEqual(kwargs["data"], {"id": deviceid})
self.assertEqual(kwargs["data"], json.dumps({"id": deviceid}))

@patch("requests.Session.request")
def test_turn_off(self, mock):
"""Test if the turn off method works as expected."""
mock.return_value = RESPONSE204

deviceid = uuid.uuid4()
deviceid = str(uuid.uuid4())

self.device.turn_off(deviceid)

Expand All @@ -202,14 +203,14 @@ def test_turn_off(self, mock):
args[1], f"{BASE_API_URL}/device/off",
)
self.assertEqual(args[0], "PUT")
self.assertEqual(kwargs["data"], {"id": deviceid})
self.assertEqual(kwargs["data"], json.dumps({"id": deviceid}))

@patch("requests.Session.request")
def test_pause_zone_run(self, mock):
"""Test if the pause zone run method works as expected."""
mock.return_value = RESPONSE204

deviceid = uuid.uuid4()
deviceid = str(uuid.uuid4())
duration = randrange(3600)

self.device.pause_zone_run(deviceid, duration)
Expand All @@ -222,7 +223,7 @@ def test_pause_zone_run(self, mock):
)
self.assertEqual(args[0], "PUT")
self.assertEqual(
kwargs["data"], {"id": deviceid, "duration": duration}
kwargs["data"], json.dumps({"id": deviceid, "duration": duration})
)

# Check that values should be within range.
Expand All @@ -238,7 +239,7 @@ def test_resume_zone_run(self, mock):
"""Test if the resume zone run method works as expected."""
mock.return_value = RESPONSE204

deviceid = uuid.uuid4()
deviceid = str(uuid.uuid4())

self.device.resume_zone_run(deviceid)

Expand All @@ -249,4 +250,4 @@ def test_resume_zone_run(self, mock):
args[1], f"{BASE_API_URL}/device/resume_zone_run",
)
self.assertEqual(args[0], "PUT")
self.assertEqual(kwargs["data"], {"id": deviceid})
self.assertEqual(kwargs["data"], json.dumps({"id": deviceid}))
39 changes: 22 additions & 17 deletions tests/test_notification.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import unittest
from unittest.mock import patch
import uuid
import json

from rachiopy import Notification
from tests.constants import BASE_API_URL, AUTHTOKEN, RESPONSE200, RESPONSE204
Expand Down Expand Up @@ -39,7 +40,7 @@ def test_get_device_webhook(self, mock):
"""Test if the get device webhook method works as expected."""
mock.return_value = RESPONSE200

deviceid = uuid.uuid4()
deviceid = str(uuid.uuid4())

self.notification.get_device_webhook(deviceid)

Expand All @@ -57,7 +58,7 @@ def test_add(self, mock):
"""Test if the add method works as expected."""
mock.return_value = RESPONSE200

deviceid = uuid.uuid4()
deviceid = str(uuid.uuid4())
externalid = "Test ID"
url = "https://www.mydomain.com/another_webhook_new_url"
eventtypes = [{"id": "1"}, {"id": "2"}]
Expand All @@ -71,20 +72,22 @@ def test_add(self, mock):
self.assertEqual(args[0], "POST")
self.assertEqual(
kwargs["data"],
{
"device": {"id": deviceid},
"externalId": externalid,
"url": url,
"eventTypes": eventtypes,
},
json.dumps(
{
"device": {"id": deviceid},
"externalId": externalid,
"url": url,
"eventTypes": eventtypes,
}
),
)

@patch("requests.Session.request")
def test_update(self, mock):
"""Test if the update method works as expected."""
mock.return_value = RESPONSE200

hookid = uuid.uuid4()
hookid = str(uuid.uuid4())
externalid = "Test ID"
url = "https://www.mydomain.com/another_webhook_new_url"
eventtypes = [{"id": "1"}, {"id": "2"}]
Expand All @@ -98,20 +101,22 @@ def test_update(self, mock):
self.assertEqual(args[0], "PUT")
self.assertEqual(
kwargs["data"],
{
"id": hookid,
"externalId": externalid,
"url": url,
"eventTypes": eventtypes,
},
json.dumps(
{
"id": hookid,
"externalId": externalid,
"url": url,
"eventTypes": eventtypes,
}
),
)

@patch("requests.Session.request")
def test_delete(self, mock):
"""Test if the delete method works as expected."""
mock.return_value = RESPONSE204

hookid = uuid.uuid4()
hookid = str(uuid.uuid4())

self.notification.delete(hookid)

Expand All @@ -129,7 +134,7 @@ def test_get(self, mock):
"""Test if the get method works as expected."""
mock.return_value = RESPONSE200

hookid = uuid.uuid4()
hookid = str(uuid.uuid4())

self.notification.get(hookid)

Expand Down
16 changes: 9 additions & 7 deletions tests/test_schedulerule.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import unittest
from unittest.mock import patch
import uuid
import json

from rachiopy import Schedulerule
from tests.constants import BASE_API_URL, AUTHTOKEN, RESPONSE200, RESPONSE204
Expand All @@ -23,7 +24,7 @@ def test_get(self, mock):
"""Test if the get method works as expected."""
mock.return_value = RESPONSE200

scheduleruleid = uuid.uuid4()
scheduleruleid = str(uuid.uuid4())

self.schedulerule.get(scheduleruleid)

Expand All @@ -41,7 +42,7 @@ def test_skip(self, mock):
"""Test if the skip method works as expected."""
mock.return_value = RESPONSE204

scheduleruleid = uuid.uuid4()
scheduleruleid = str(uuid.uuid4())

self.schedulerule.skip(scheduleruleid)

Expand All @@ -50,14 +51,14 @@ def test_skip(self, mock):
# Check that the mock function is called with the rights args.
self.assertEqual(args[1], f"{BASE_API_URL}/schedulerule/skip")
self.assertEqual(args[0], "PUT")
self.assertEqual(kwargs["data"], {"id": scheduleruleid})
self.assertEqual(kwargs["data"], json.dumps({"id": scheduleruleid}))

@patch("requests.Session.request")
def test_start(self, mock):
"""Test if the start method works as expected."""
mock.return_value = RESPONSE204

scheduleruleid = uuid.uuid4()
scheduleruleid = str(uuid.uuid4())

self.schedulerule.start(scheduleruleid)

Expand All @@ -66,14 +67,14 @@ def test_start(self, mock):
# Check that the mock function is called with the rights args.
self.assertEqual(args[1], f"{BASE_API_URL}/schedulerule/start")
self.assertEqual(args[0], "PUT")
self.assertEqual(kwargs["data"], {"id": scheduleruleid})
self.assertEqual(kwargs["data"], json.dumps({"id": scheduleruleid}))

@patch("requests.Session.request")
def test_seasonal_adjustment(self, mock):
"""Test if the seasonal adjustment method works as expected."""
mock.return_value = RESPONSE200

scheduleruleid = uuid.uuid4()
scheduleruleid = str(uuid.uuid4())
adjustment = 0.2

self.schedulerule.seasonal_adjustment(scheduleruleid, adjustment)
Expand All @@ -86,5 +87,6 @@ def test_seasonal_adjustment(self, mock):
)
self.assertEqual(args[0], "PUT")
self.assertEqual(
kwargs["data"], {"id": scheduleruleid, "adjustment": adjustment}
kwargs["data"],
json.dumps({"id": scheduleruleid, "adjustment": adjustment}),
)
Loading

0 comments on commit 00a74be

Please sign in to comment.