Skip to content

Commit

Permalink
Fixing up some more unit test things
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelGHSeg committed Oct 2, 2023
1 parent cbe2bf2 commit 1b231e0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
16 changes: 8 additions & 8 deletions segment/analytics/oauth_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ def __init__(self,
client_id,
client_key,
key_id,
auth_server,
scope,
timeout,
max_retries):
auth_server='https://oauth2.segment.io',
scope='tracking_api:write',
timeout=5,
max_retries=3):
self.client_id = client_id
self.client_key = client_key
self.key_id = key_id
Expand All @@ -44,7 +44,7 @@ def get_token(self):
if self.thread and self.thread.is_alive():
self.thread.cancel()
self.thread = threading.Timer(0,self._poller_loop)
self.thread.setDaemon(True)
self.thread.daemon = True
self.thread.start()

while True:
Expand Down Expand Up @@ -106,7 +106,7 @@ def _poller_loop(self):
if self.retry_count < self.max_retries:
self.log.error("OAuth token request encountered an error on attempt {}: {}".format(self.retry_count ,e))
self.thread = threading.Timer(refresh_timer_ms / 1000.0, self._poller_loop)
self.thread.setDaemon(True)
self.thread.daemon = True
self.thread.start()
return
# Too many retries, giving up
Expand All @@ -122,7 +122,7 @@ def _poller_loop(self):
self.retry_count += 1
if self.retry_count < self.max_retries:
self.thread = threading.Timer(refresh_timer_ms / 1000.0, self._poller_loop)
self.thread.setDaemon(True)
self.thread.daemon = True
self.thread.start()
return
# Too many retries, giving up
Expand Down Expand Up @@ -177,5 +177,5 @@ def _poller_loop(self):

# loop
self.thread = threading.Timer(refresh_timer_ms / 1000.0, self._poller_loop)
self.thread.setDaemon(True)
self.thread.daemon = True
self.thread.start()
10 changes: 8 additions & 2 deletions segment/analytics/test/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def test_debug(self):
analytics.debug = False
analytics.flush()
self.assertFalse(analytics.default_client.debug)
analytics.default_client.log.setLevel(0) # reset log level after debug enable

def test_gzip(self):
self.assertIsNone(analytics.default_client)
Expand All @@ -44,9 +45,11 @@ def test_gzip(self):

def test_host(self):
self.assertIsNone(analytics.default_client)
analytics.host = 'test-host'
analytics.host = 'http://test-host'
analytics.flush()
self.assertEqual(analytics.default_client.host, 'test-host')
self.assertEqual(analytics.default_client.host, 'http://test-host')
analytics.host = None
analytics.default_client = None

def test_max_queue_size(self):
self.assertIsNone(analytics.default_client)
Expand Down Expand Up @@ -79,3 +82,6 @@ def test_timeout(self):
def setUp(self):
analytics.write_key = 'test-init'
analytics.default_client = None

if __name__ == '__main__':
unittest.main()
1 change: 1 addition & 0 deletions segment/analytics/test/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ def test_numeric_user_id(self):

def test_debug(self):
Client('bad_key', debug=True)
self.client.log.setLevel(0) # reset log level after debug enable

def test_identify_with_date_object(self):
client = self.client
Expand Down

0 comments on commit 1b231e0

Please sign in to comment.