Skip to content

Commit

Permalink
Merge pull request #97 from dknowles2/user-name
Browse files Browse the repository at this point in the history
Handle the case where friendlyName is None
  • Loading branch information
dknowles2 committed Sep 19, 2023
2 parents 712c94e + 149fdac commit 943dbb0
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
4 changes: 2 additions & 2 deletions pyschlage/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
class User:
"""A Schlage API user account."""

name: str = ""
name: str | None = None
"""The username associated with the account."""

email: str = ""
Expand All @@ -36,7 +36,7 @@ def from_json(cls, json) -> User:
:meta private:
"""
return User(
name=json["friendlyName"],
name=json.get("friendlyName"),
email=json["email"],
user_id=json["identityId"],
)
4 changes: 3 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from unittest import mock

from pytest import fixture
Expand All @@ -13,7 +15,7 @@ def mock_auth():


@fixture
def lock_users_json():
def lock_users_json() -> list[dict]:
return [
{
"consentRecords": [],
Expand Down
10 changes: 8 additions & 2 deletions tests/test_user.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
from unittest import mock
from __future__ import annotations

from pyschlage.user import User


def test_from_json(lock_users_json):
def test_from_json(lock_users_json: list[dict]):
user = User(
name="asdf",
email="asdf@asdf.com",
user_id="user-uuid",
)
assert User.from_json(lock_users_json[0]) == user


def test_from_json_no_name(lock_users_json: list[dict]):
for user_json in lock_users_json:
user_json.pop("friendlyName")
assert User.from_json(user_json).name is None

0 comments on commit 943dbb0

Please sign in to comment.