File tree Expand file tree Collapse file tree 3 files changed +13
-5
lines changed Expand file tree Collapse file tree 3 files changed +13
-5
lines changed Original file line number Diff line number Diff line change 9
9
class User :
10
10
"""A Schlage API user account."""
11
11
12
- name : str = ""
12
+ name : str | None = None
13
13
"""The username associated with the account."""
14
14
15
15
email : str = ""
@@ -36,7 +36,7 @@ def from_json(cls, json) -> User:
36
36
:meta private:
37
37
"""
38
38
return User (
39
- name = json [ "friendlyName" ] ,
39
+ name = json . get ( "friendlyName" ) ,
40
40
email = json ["email" ],
41
41
user_id = json ["identityId" ],
42
42
)
Original file line number Diff line number Diff line change
1
+ from __future__ import annotations
2
+
1
3
from unittest import mock
2
4
3
5
from pytest import fixture
@@ -13,7 +15,7 @@ def mock_auth():
13
15
14
16
15
17
@fixture
16
- def lock_users_json ():
18
+ def lock_users_json () -> list [ dict ] :
17
19
return [
18
20
{
19
21
"consentRecords" : [],
Original file line number Diff line number Diff line change 1
- from unittest import mock
1
+ from __future__ import annotations
2
2
3
3
from pyschlage .user import User
4
4
5
5
6
- def test_from_json (lock_users_json ):
6
+ def test_from_json (lock_users_json : list [ dict ] ):
7
7
user = User (
8
8
name = "asdf" ,
9
9
email = "asdf@asdf.com" ,
10
10
user_id = "user-uuid" ,
11
11
)
12
12
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
You can’t perform that action at this time.
0 commit comments