Skip to content

Commit

Permalink
Unitest placed and 0.1.0 final
Browse files Browse the repository at this point in the history
  • Loading branch information
kairoaraujo committed Jan 8, 2020
1 parent 0ad92a6 commit b4c7716
Show file tree
Hide file tree
Showing 6 changed files with 349 additions and 39 deletions.
5 changes: 5 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ dev

- \[Short description of non-trivial change.\]

0.1.0 (09-02-2020)
-----------------
- Initial version


0.0.2-alpha1 (05-02-2020)
-------------------------

Expand Down
2 changes: 1 addition & 1 deletion kodaksmarthome/__version__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
__title__ = "python-kodaksmarthome"
__description__ = "Python Kodak SmartHome API"
__url__ = "https://github.com/kairoaraujo/kodak_smarthome_api"
__version__ = "0.0.2-alpha1"
__version__ = "0.1.0"
__author__ = "Kairo de Araujo"
__author_email__ = "kairo@dearaujo.nl"
__license__ = "Apache 2.0"
Expand Down
23 changes: 14 additions & 9 deletions kodaksmarthome/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ def _http_request(self, method, url, headers=None, data=None, params=None):
http_response = self.http_session.post(
url, headers=headers, data=data, params=params
)

elif method == "OPTIONS":
http_response = self.http_session.options(
url, headers=headers, data=data, params=params
Expand All @@ -67,7 +68,7 @@ def _http_request(self, method, url, headers=None, data=None, params=None):
)

else:
raise AttributeError("Invalid Method")
raise AttributeError(f"Invalid Method {method}")

except requests.exceptions.ConnectionError as err:
raise ConnectionError(str(err))
Expand Down Expand Up @@ -103,7 +104,7 @@ def _http_request(self, method, url, headers=None, data=None, params=None):
self.is_connected = False
raise TypeError("Unexpected response format")

if status_code == HTTP_CODE.UNAUTHORIZED:
elif status_code == HTTP_CODE.UNAUTHORIZED:
if error == "invalid_grant":
self.is_connected = False

Expand All @@ -116,6 +117,7 @@ def _http_request(self, method, url, headers=None, data=None, params=None):
and self.is_connected
):
self.is_connected = False
return True

elif (
type(error) == dict
Expand All @@ -132,24 +134,25 @@ def _http_request(self, method, url, headers=None, data=None, params=None):
and self.is_connected
):
self.is_connected = False
return True

elif (
"msg" in response_json
and "Access Denied" in response_json["msg"]
and self.is_connected is False
):
self.is_connected
raise ConnectionError(response_json["error"])
self.is_connected = False
raise ConnectionError(response_json["msg"])

else:
self.is_connected = False

raise ConnectionError("Unexpected 401 error " + response_text)

else:
self.is_connected
self.is_connected = False
raise ConnectionError(
"Unexpected status_code error " + response_text
"Unexpected HTTP CODE error " + response_text
)

def _options(self):
Expand Down Expand Up @@ -245,7 +248,7 @@ def _get_devices(self):
if self.is_connected is False:
self.connect()

return self.events
return self.devices

self.devices = devices_response["data"]

Expand Down Expand Up @@ -316,7 +319,9 @@ def update(self):
"""
Update the device list and events data
:return: True
:rtype: bool
:exception: ``ConnectionError``
"""
self._get_devices()
self._get_events()
Expand All @@ -328,12 +333,12 @@ def disconnect(self):
:return: None
:exception: ``ConnectionError``
"""
self.http_session.get(self.region_url.URL_LOGOUT)
self._http_request("GET", self.region_url.URL_LOGOUT)
self.http_session.close()
self.is_connected = False

@property
def list_devices(self):
def get_devices(self):
"""
List all registered devices in Kodak Smart Portal and its details.
Expand Down
18 changes: 16 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,32 @@
#
# Copyright 2019, 2020 Kairo de Araujo
#
import json
import pytest
from unittest import mock


class MockRequestsResponse:
def __init__(self, json_data, status_code):
def __init__(self, json_data, status_code, headers):
self._headers = headers
self.json_data = json_data
self.status_code = status_code
self._status_code = status_code

def json(self):
return self.json_data

@property
def text(self):
return json.dumps(self.json_data)

@property
def headers(self):
return self._headers

@property
def status_code(self):
return self._status_code


@pytest.fixture
def requests_session_mock_ok():
Expand Down
Loading

0 comments on commit b4c7716

Please sign in to comment.