Skip to content

Commit

Permalink
Set the UUID at login and load it from cookies.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaraco committed Nov 30, 2022
1 parent 0e8f2ab commit 5a52d41
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
8 changes: 3 additions & 5 deletions jaraco/abode/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,7 @@ def __init__(
self._session = sessions.BaseUrlSession(urls.BASE)

# Create a new cache template
self._cache = {
'uuid': str(uuid.uuid1()),
}
self._cache = {}

# Load and merge an existing cache
if not disable_cache:
Expand Down Expand Up @@ -101,7 +99,7 @@ def login(self, username=None, password=None, mfa_code=None): # noqa: C901
login_data = {
'id': username,
'password': password,
'uuid': self._cache['uuid'],
'uuid': self._session.cookies.get('uuid') or str(uuid.uuid1()),
}

if mfa_code is not None:
Expand Down Expand Up @@ -332,7 +330,7 @@ def events(self):
@property
def uuid(self):
"""Get the UUID."""
return self._cache['uuid']
return self._session.cookies['uuid']

def _get_session(self):
# Perform a generic update so we know we're logged in
Expand Down
13 changes: 6 additions & 7 deletions tests/test_abode.py
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,6 @@ def tests_cookies(self, m):

# Test that our cookies are fully realized prior to login

assert client._cache['uuid'] is not None
assert client._cache['cookies'] is not None

# Test that we now have a cookies file
Expand All @@ -531,7 +530,8 @@ def tests_cookies(self, m):
@pytest.mark.usefixtures('cache_path')
def test_empty_cookies(self, m):
"""Check that empty cookies file is loaded successfully."""
m.post(urls.LOGIN, json=LOGIN.post_response_ok())
cookies = dict(SESSION='COOKIE')
m.post(urls.LOGIN, json=LOGIN.post_response_ok(), cookies=cookies)
m.get(urls.OAUTH_TOKEN, json=OAUTH_CLAIMS.get_response_ok())
m.post(urls.LOGOUT, json=LOGOUT.post_response_ok())
m.get(urls.DEVICES, json=DEVICES.EMPTY_DEVICE_RESPONSE)
Expand All @@ -551,13 +551,13 @@ def test_empty_cookies(self, m):
)

# Test that some cache exists

assert empty_client._cache['uuid'] is not None
assert empty_client._cache['cookies']

@pytest.mark.usefixtures('cache_path')
def test_invalid_cookies(self, m):
"""Check that empty cookies file is loaded successfully."""
m.post(urls.LOGIN, json=LOGIN.post_response_ok())
cookies = dict(SESSION='COOKIE')
m.post(urls.LOGIN, json=LOGIN.post_response_ok(), cookies=cookies)
m.get(urls.OAUTH_TOKEN, json=OAUTH_CLAIMS.get_response_ok())
m.post(urls.LOGOUT, json=LOGOUT.post_response_ok())
m.get(urls.DEVICES, json=DEVICES.EMPTY_DEVICE_RESPONSE)
Expand All @@ -577,5 +577,4 @@ def test_invalid_cookies(self, m):
)

# Test that some cache exists

assert empty_client._cache['uuid'] is not None
assert empty_client._cache['cookies']

0 comments on commit 5a52d41

Please sign in to comment.