def test_connected_status_after_exception_is_false(self): """ When an exception is thrown the client is no longer connected. """ test_utils.generate_test_config_file() client = PowerTrackClient(_dummy_callback, config_file_path=config_file) client.connect() sleep(2) self.assertFalse(client.connected())
def test_connected_status_true_when_running(self): """ Once the client connect method is called the client reports as connected. """ test_utils.generate_test_config_file() client = PowerTrackClient(_dummy_callback, config_file_path=config_file) client.connect() self.assertTrue(client.connected()) client.disconnect() self.assertFalse(client.connected())
def test_exception_with_callback(self): """ When exception_callback is provided, worker uses it to communicate errors. """ test_utils.generate_test_config_file() exception_callback = mock.Mock() client = PowerTrackClient(_dummy_callback, exception_callback, config_file_path=config_file) client.connect() self.assertTrue(exception_callback.called) actual_exinfo = exception_callback.call_args[0][0] actual_ex = actual_exinfo[1] self.assertIsInstance(actual_ex, Exception) self.assertEqual(actual_ex.message, "This is a test exception")
def test_backfill_value_appended_to_url(self, mocked_requests_get): """When passing a backfill value it is appended to the url call to GNIP""" backfill_minutes = 3 expected_powertrack_url = "{0}?backfillMinutes={1}".format( test_utils.test_powertrack_url, backfill_minutes) test_utils.generate_test_config_file() client = PowerTrackClient(_dummy_callback, config_file_path=config_file) client.connect(backfill_minutes=backfill_minutes) client.disconnect() mocked_requests_get.assert_called_with(expected_powertrack_url, auth=(test_utils.test_username, test_utils.test_password), stream=True)
def test_backfill_value_appended_to_url(self, mocked_requests_get): """When passing a backfill value it is appended to the url call to GNIP""" backfill_minutes = 3 expected_powertrack_url = "{0}?backfillMinutes={1}".format( test_utils.test_powertrack_url, backfill_minutes) test_utils.generate_test_config_file() client = PowerTrackClient(_dummy_callback, config_file_path=config_file) client.connect(backfill_minutes=backfill_minutes) client.disconnect() mocked_requests_get.assert_called_with( expected_powertrack_url, auth=(test_utils.test_username, test_utils.test_password), stream=True )
#!/usr/bin/env python import time from gnippy import PowerTrackClient # Define a callback def callback(activity): print activity # Create the client client = PowerTrackClient( callback, url= "https://stream.gnip.com:443/accounts/{ACCOUNT_NAME}/publishers/twitter/streams/track/{STREAM_LABEL}.json", auth=("*****@*****.**", "nOtMyPaSsWoRd")) print "Connecting..." client.connect() time.sleep(1800) #run for 30 minutes... client.disconnect() #... then disconnet. print "finished streaming, exiting..."
#!/usr/bin/env python import time from gnippy import PowerTrackClient # Define a callback def callback(activity): print activity # Create the client client = PowerTrackClient(callback,url="https://stream.gnip.com:443/accounts/{ACCOUNT_NAME}/publishers/twitter/streams/track/{STREAM_LABEL}.json",auth=("*****@*****.**","nOtMyPaSsWoRd")) print "Connecting..." client.connect() time.sleep(1800) #run for 30 minutes... client.disconnect() #... then disconnet. print "finished streaming, exiting..."