diff --git a/segment/analytics/oauth_manager.py b/segment/analytics/oauth_manager.py index 6d078e4..ab10350 100644 --- a/segment/analytics/oauth_manager.py +++ b/segment/analytics/oauth_manager.py @@ -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 @@ -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: @@ -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 @@ -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 @@ -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() diff --git a/segment/analytics/test/__init__.py b/segment/analytics/test/__init__.py index 4103ff5..98ad6aa 100644 --- a/segment/analytics/test/__init__.py +++ b/segment/analytics/test/__init__.py @@ -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) @@ -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) @@ -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() \ No newline at end of file diff --git a/segment/analytics/test/client.py b/segment/analytics/test/client.py index 20bdd9f..bffdb1e 100644 --- a/segment/analytics/test/client.py +++ b/segment/analytics/test/client.py @@ -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