Skip to content

Commit

Permalink
Merge pull request #81 from dknowles2/api-tests-and-fix
Browse files Browse the repository at this point in the history
Fix a bug in the locks() method; add a regression test
  • Loading branch information
dknowles2 committed Aug 6, 2023
2 parents c28591e + 9e301cd commit ebfb620
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
1 change: 1 addition & 0 deletions pyschlage/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def locks(self) -> list[Lock]:
for lock_json in response.json():
lock = Lock.from_json(self._auth, lock_json)
lock.refresh_access_codes()
locks.append(lock)
return locks

def users(self) -> list[User]:
Expand Down
32 changes: 32 additions & 0 deletions tests/test_api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from __future__ import annotations

from unittest import mock

from pyschlage import api


def test_locks(mock_auth: mock.Mock, lock_json: dict, access_code_json: dict) -> None:
schlage = api.Schlage(mock_auth)
mock_auth.request.side_effect = [
mock.Mock(json=mock.Mock(return_value=[lock_json])),
mock.Mock(json=mock.Mock(return_value=[access_code_json])),
]
locks = schlage.locks()
assert len(locks) == 1
mock_auth.request.assert_has_calls(
[
mock.call("get", "devices", params={"archetype": "lock"}),
mock.call("get", "devices/__wifi_uuid__/storage/accesscode"),
]
)


def test_users(mock_auth: mock.Mock, lock_users_json: list[dict]) -> None:
schlage = api.Schlage(mock_auth)
mock_auth.request.return_value = mock.Mock(
json=mock.Mock(return_value=lock_users_json)
)

users = schlage.users()
assert len(users) == 2
mock_auth.request.assert_called_once_with("get", "users")

0 comments on commit ebfb620

Please sign in to comment.