Skip to content

Commit 943dbb0

Browse files
authored
Merge pull request #97 from dknowles2/user-name
Handle the case where friendlyName is None
2 parents 712c94e + 149fdac commit 943dbb0

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

pyschlage/user.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
class User:
1010
"""A Schlage API user account."""
1111

12-
name: str = ""
12+
name: str | None = None
1313
"""The username associated with the account."""
1414

1515
email: str = ""
@@ -36,7 +36,7 @@ def from_json(cls, json) -> User:
3636
:meta private:
3737
"""
3838
return User(
39-
name=json["friendlyName"],
39+
name=json.get("friendlyName"),
4040
email=json["email"],
4141
user_id=json["identityId"],
4242
)

tests/conftest.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
from unittest import mock
24

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

1416

1517
@fixture
16-
def lock_users_json():
18+
def lock_users_json() -> list[dict]:
1719
return [
1820
{
1921
"consentRecords": [],

tests/test_user.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
1-
from unittest import mock
1+
from __future__ import annotations
22

33
from pyschlage.user import User
44

55

6-
def test_from_json(lock_users_json):
6+
def test_from_json(lock_users_json: list[dict]):
77
user = User(
88
name="asdf",
99
email="asdf@asdf.com",
1010
user_id="user-uuid",
1111
)
1212
assert User.from_json(lock_users_json[0]) == user
13+
14+
15+
def test_from_json_no_name(lock_users_json: list[dict]):
16+
for user_json in lock_users_json:
17+
user_json.pop("friendlyName")
18+
assert User.from_json(user_json).name is None

0 commit comments

Comments
 (0)