Skip to content

Commit

Permalink
bring coverage back to 100%
Browse files Browse the repository at this point in the history
  • Loading branch information
brad committed Aug 20, 2018
1 parent 8a9444b commit f4de884
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
5 changes: 4 additions & 1 deletion nokia/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ def is_date(key):
def is_date_class(val):
return isinstance(val, (datetime.date, datetime.datetime, arrow.Arrow, ))


# Calculate seconds since 1970-01-01 (timestamp) in a way that works in
# Python 2 and Python3
# https://docs.python.org/3/library/datetime.html#datetime.datetime.timestamp
Expand Down Expand Up @@ -139,7 +140,9 @@ def get_credentials(self):

def set_token(self, token):
self.token = token
self.credentials.token_expiry = str(ts()+int(self.token['expires_in']))
self.credentials.token_expiry = str(
ts() + int(self.token['expires_in'])
)
self.credentials.access_token = self.token['access_token']
self.credentials.refresh_token = self.token['refresh_token']

Expand Down
35 changes: 35 additions & 0 deletions tests/test_nokia_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,41 @@ def test_attribute_defaults(self):
self.assertEqual(api.client.params, {})
self.assertEqual(api.client.token, api.token)

def test_get_credentials(self):
"""
Make sure NokiaApi returns the credentials as expected
"""
creds = NokiaCredentials(token_expiry=0)
api = NokiaApi(creds)

def test_set_token(self):
"""
Make sure NokiaApi.set_token makes the expected changes
"""
timestamp = int((
datetime.datetime.utcnow() - datetime.datetime(1970, 1, 1)
).total_seconds())
creds = NokiaCredentials(token_expiry=timestamp)
api = NokiaApi(creds)
token = {
'access_token': 'fakeat',
'refresh_token': 'fakert',
'expires_in': 100,
}

api.set_token(token)

self.assertEqual(api.token, token)
self.assertEqual(api.get_credentials().access_token, 'fakeat')
self.assertEqual(api.get_credentials().refresh_token, 'fakert')
self.assertEqual(
True,
# Need to check 100 or 101 in case a second ticked over during
# testing
int(api.credentials.token_expiry) == (timestamp + 100) or
int(api.credentials.token_expiry) == (timestamp + 101)
)

def test_request(self):
"""
Make sure the request method builds the proper URI and returns the
Expand Down

0 comments on commit f4de884

Please sign in to comment.