def test_Connection_to_Intersection_Sub_API(self): self.config = testRunnerHelper.parse_config_file( os.path.join('.', 'test_config_files', 'testCase_3_config.ini')) self.createClient() request = testRunnerHelper.build_subscription_request(self.config) self.run_subscription_test(request, dataType=u'isd') # TODO change to 'int'
def test_Connection_to_Vehicle_Sub_API(self): self.config = testRunnerHelper.parse_config_file( os.path.join('.', 'test_config_files', 'testCase_1_config.ini')) self.createClient() request = testRunnerHelper.build_subscription_request(self.config) self.run_subscription_test(request, timeOut=self.config['SUBSCRIPTION_TIMEOUT'])
def initialize(self, full_config_path): self.config = config = testRunnerHelper.parse_config_file( full_config_path) self.config['START_DATE'] = "2014-01-13T19:52:45.500Z" self.config['END_DATE'] = "2015-09-17T17:52:45.500Z" self.logger.info(config['TEST_NAME']) ode = client.ODEClient(self.config['HOST']) ode.get_token(self.config['USERNAME'], self.config['PASSWORD']) self.client = None self.client = client.AsyncODEClient(odeClient=ode) self.config['TEST_REQUEST'] = None
class ODE_Client_Authentication_REST_API(unittest.TestCase): config = testRunnerHelper.parse_config_file( os.path.join('.', 'test_config_files', 'test_Authentication_config.ini')) end = datetime.datetime.utcnow() start = end - dateutil.relativedelta.relativedelta(months=6) config['START_DATE'] = start.isoformat()[:-3] + 'Z' config['END_DATE'] = end.isoformat()[:-3] + 'Z' userName = config['USERNAME'] password = config['PASSWORD'] host = config['HOST'] def test_access_token_with_valid_UserName_Password(self): ode = client.ODEClient(self.host, self.userName, self.password) self.assertIsNotNone(ode.token) def test_exception_returned_with_invalid_Password(self): ode = client.ODEClient(self.host, self.userName, "Wrong Password") self.assertRaises(exceptions.ODEConnectionException, ode.connect, None) def test_exception_returned_with_invalid_UserName(self): ode = client.ODEClient(self.host, "*****@*****.**", self.password) self.assertRaises(exceptions.ODEConnectionException, ode.connect, None) def test_restAPI_log_in(self): self.assertIsNotNone( restApi.login(self.host, self.userName, self.password)) def test_restAPI_log_out(self): token = restApi.login(self.host, self.userName, self.password) self.assertIsNotNone(token) self.assertIsNone(restApi.logout(self.host, token))
class ODE_Basic_Subscription_Multiple_Clients_Tests(unittest.TestCase): __metaclass__ = LogThisTestCase logger = logging.getLogger("ODE_Multiple_Clients_Tests") logger.propagate = False logger.setLevel(logging.DEBUG) config1 = testRunnerHelper.parse_config_file( os.path.join('.', 'test_config_files', 'test_Basic_Multiple_Clients_config_1.ini')) config2 = testRunnerHelper.parse_config_file( os.path.join('.', 'test_config_files', 'test_Basic_Multiple_Clients_config_2.ini')) client1 = client2 = None def create_asyncClient_and_request(self, the_config, **kwargs): ode = client.ODEClient(the_config['HOST']) ode.get_token(the_config['USERNAME'], the_config['PASSWORD']) asycODE = client.AsyncODEClient(odeClient=ode) if the_config['REQUEST_TYPE'] in [ 'sub', ]: request = testRunnerHelper.build_subscription_request( the_config, **kwargs) else: request = testRunnerHelper.build_query_request( the_config, **kwargs) self.logger.info("Request: %s", request.toJson()) asycODE.setRequest(request) return asycODE def stop_client(self, client): client.client.destroy_token() client.stop() def setUp(self): pass def tearDown(self): try: self.stop_client(self.client1) self.stop_client(self.client2) except Exception as e: pass time.sleep(3) def test_Connection_to_Vehicle_Query_API(self): dataType = 'veh' requestType = 'qry' self.config1['DATA'] = dataType self.config2['DATA'] = dataType self.config1['REQUEST_TYPE'] = requestType self.config2['REQUEST_TYPE'] = requestType self.client1 = self.create_asyncClient_and_request(self.config1) self.client2 = self.create_asyncClient_and_request(self.config2) start_time = datetime.datetime.utcnow() self.client1.start() self.client2.start() time_out = 180 time.sleep(time_out) # TODO Assert Something # Assert Location and Date time is correct # assert msg1 = self.client1.get_all_messages() self.logger.info("Processing Client 1 Messages") for m in msg1: # self.logger.info( m.toJson() ) if m.get_payload_type() in ('veh', ): self.assertTrue( testRunnerHelper.validate_datetime(m.payload, self.config1)) self.assertTrue( testRunnerHelper.validate_location(m.payload, self.config1)) msg2 = self.client2.get_all_messages() self.logger.info("Processing Client 2 Messages") for m in msg2: # self.logger.info( m.toJson()) if m.get_payload_type() in ('veh', ): self.assertTrue( testRunnerHelper.validate_datetime(m.payload, self.config2)) self.assertTrue( testRunnerHelper.validate_location(m.payload, self.config2)) self.logger.info('Records Received: %d', len(msg1)) self.logger.info('Records Received: %d', len(msg2)) self.assertGreaterEqual(len(msg1), 100) self.assertGreaterEqual(len(msg2), 100) self.logger.info( "All Records Validated against spatial and temporal parameters") def test_Connection_to_Vehicle_Subscription_API(self): dataType = 'veh' requestType = 'sub' self.config1['DATA'] = dataType self.config2['DATA'] = dataType self.config1['REQUEST_TYPE'] = requestType self.config2['REQUEST_TYPE'] = requestType self.client1 = self.create_asyncClient_and_request(self.config1) self.client2 = self.create_asyncClient_and_request(self.config2) start_time = datetime.datetime.utcnow() self.client1.start() self.client2.start() time_out = 180 time.sleep(time_out) # TODO Assert Something # Assert Location and Date time is correct # assert msg1 = self.client1.get_all_messages() self.logger.info("Processing Client 1 Messages") for m in msg1: # self.logger.info( m.toJson() ) if m.get_payload_type() in ('veh', ): self.assertTrue( testRunnerHelper.validate_location(m.payload, self.config1)) msg2 = self.client2.get_all_messages() self.logger.info("Processing Client 2 Messages") for m in msg2: # self.logger.info( m.toJson()) if m.get_payload_type() in ('veh', ): self.assertTrue( testRunnerHelper.validate_location(m.payload, self.config2)) self.logger.info('Records Received: %d', len(msg1)) self.logger.info('Records Received: %d', len(msg2)) # self.assertGreaterEqual(len(msg1), 50) # self.assertGreaterEqual(len(msg2), 50) self.logger.info("All Records Validated against temporal parameters")
class ODE_Query_Downloads_Tests(unittest.TestCase): """ Test 2 - Query VSD Data ODE-153 Test 4 - Query ISD Data ODE-155 Test 5 - Query ASD Data ODE-154 """ __metaclass__ = LogThisTestCase logger = logging.getLogger("QueryTests") logger.setLevel(logging.INFO) l2 = logging.getLogger('odeClient') l2.setLevel(logging.DEBUG) l2.addHandler(logging.StreamHandler()) logger.addHandler( logging.FileHandler( os.path.join('.', 'log_outputs', 'ODE_Query_Downloads_Tests.log'))) # l2.addHandler(logging.FileHandler(os.path.join('.','log_outputs','ODE_Query_Downloads_Tests.log'))) config = testRunnerHelper.parse_config_file( os.path.join('.', 'test_config_files', 'test_Basic_Query_API_config.ini')) end = datetime.datetime.utcnow() start = end - dateutil.relativedelta.relativedelta(months=6) config['START_DATE'] = start.isoformat()[:-3] + 'Z' config['END_DATE'] = end.isoformat()[:-3] + 'Z' def setUp(self): self.logger.addHandler( logging.FileHandler( os.path.join('.', 'log_outputs', 'ODE_Query_Downloads_Tests.log'))) self.l2.addHandler( logging.FileHandler( os.path.join('.', 'log_outputs', 'ODE_Query_Downloads_Tests.log'))) ode = client.ODEClient(self.config['HOST']) ode.get_token(self.config['USERNAME'], self.config['PASSWORD']) date_format = timehelpers.date_format dateTime_now = datetime.datetime.now(timehelpers.ZULU()) dateTime_prev = dateTime_now - datetime.timedelta(weeks=52) self.config['START_DATE'] = dateTime_prev.strftime( timehelpers.date_format) self.config['END_DATE'] = dateTime_now.strftime( timehelpers.date_format) self.client = None self.client = client.AsyncODEClient(odeClient=ode) def tearDown(self): try: self.client.stop() self.client.client.destroy_token() self.client = None except Exception as e: pass time.sleep(1) def test_Connection_to_Vehicle_Query_API(self): self.config['DATA'] = 'veh' request = testRunnerHelper.build_query_request(self.config) self.run_query_test(request, min_queue=5, min_records=5, limit=250) def test_Connection_to_Vehicle_Query_API_SDW(self): self.config['DATA'] = 'veh' request = testRunnerHelper.build_query_request(self.config, dataSource="SDW") self.run_query_test(request, min_queue=5, min_records=5, limit=250) # TODO Change DataType to int def test_Connection_to_Intersection_Query_API(self): self.config['DATA'] = 'int' request = testRunnerHelper.build_query_request(self.config) self.run_query_test(request, dataType='isd', min_queue=5, min_records=5) def test_Connection_to_Intersection_Query_API_SDW(self): self.config['DATA'] = 'int' request = testRunnerHelper.build_query_request(self.config, dataSource="SDW") self.run_query_test(request, dataType='isd', min_queue=5, min_records=5, timeOut=90) @unittest.skip("Aggregate Query Test Not Implemented Yet") def test_Connection_to_Aggregate_Query_API(self): self.config['DATA'] = 'agg' self.config['LIMIT'] = 25 request = testRunnerHelper.build_query_request(self.config) testRunnerHelper.build_road_Segment(request, self.config) self.run_query_test(request, min_queue=4, min_records=3, limit=self.config['LIMIT']) @unittest.skip("Aggregate Query Test SDW Not Implemented Yet") def test_Connection_to_Aggregate_Query_API_SDW(self): self.config['DATA'] = 'agg' self.config['LIMIT'] = 25 request = testRunnerHelper.build_query_request(self.config, dataSource="SDW") testRunnerHelper.build_road_Segment(request, self.config) self.run_query_test(request, min_queue=4, min_records=3, limit=self.config['LIMIT']) @unittest.skip("SPAT Query Test Not Implemented Yet") def test_Connection_to_SPAT_Query_API(self): self.config['DATA'] = 'spat' request = testRunnerHelper.build_query_request(self.config) self.run_query_test(request, dataType='isd', min_queue=25, min_records=25) @unittest.skip("SPAT Query Test SWD Not Implemented Yet") def test_Connection_to_SPAT_Query_API_SWD(self): self.config['DATA'] = 'spat' request = testRunnerHelper.build_query_request(self.config, dataSource="SDW") self.run_query_test(request, dataType='isd', min_queue=25, min_records=25) #@unittest.skip("MAP Query Test Not Implemented Yet") def test_Connection_to_MAP_Query_API(self): self.config['DATA'] = 'map' request = testRunnerHelper.build_query_request(self.config) self.run_query_test(request, dataType='isd', min_queue=25, min_records=25) #@unittest.skip("MAP Query SDW Test Not Implemented Yet") def test_Connection_to_MAP_Query_API(self): self.config['DATA'] = 'map' request = testRunnerHelper.build_query_request(self.config, dataSource="SDW") self.run_query_test(request, dataType='isd', min_queue=25, min_records=25) @unittest.skip("Advisory Query Test Not Implemented Yet") def test_Connection_to_ADV_Query_API(self): self.config['DATA'] = 'adv' request = testRunnerHelper.build_query_request(self.config) self.run_query_test(request, dataType='isd', min_queue=25, min_records=25) #@unittest.skip("MAP Query SDW Test Not Implemented Yet") def test_Connection_to_ADV_Query_SDW_API(self): self.config['DATA'] = 'adv' request = testRunnerHelper.build_query_request(self.config, dataSource="SDW") self.run_query_test(request, min_queue=15, min_records=15) def run_query_test(self, request, **kwargs): self.client.client.setRequest(request) self.client.start() if kwargs is None: kwargs = {} record_count = 0 time.sleep(5) self.logger.info(request.toJson()) start_time = datetime.datetime.utcnow() while self.client.queue.qsize() <= kwargs.get('min_queue', 10): current_time = datetime.datetime.utcnow() time_delta = current_time - start_time if time_delta.total_seconds() >= kwargs.get('timeOut', 60): self.logger.info("TImeout reached") break else: time.sleep(3) self.logger.info('validating all returned records to ensure spatial and/or temporal consistency - outliers will be displayed on the screen' \ + 'exception processing same thing with expected result') exception_list = [] while not (self.client.is_buffer_empty() and record_count != 0): responses = self.client.get_messages(25) for msg in responses: self.logger.info(msg) if msg.get_payload_type() in kwargs.get( 'dataType', request.dataType): self.assertEquals(msg.get_payload_type(), kwargs.get('dataType', request.dataType)) record_count += 1 # TODO Change assertion as more data types support Lat / Long Keys # TODO Change assertion as more data types have their created date elif msg.get_payload_type() in ('veh', ): self.assertEqual(msg.get_payload_value('dataType', None), 'veh') record_count += 1 try: self.assertIsNotNone( msg.get_payload_value('serialId', None)) self.assertTrue( testRunnerHelper.validate_datetime( msg.payload, self.config), msg= "Error Date Time of SerialID: {1} Lat: {0} Long: {1}" .format(msg.get_payload_value("dateTime"), msg.get_payload_value("serialId"))) self.assertTrue( testRunnerHelper.validate_location( msg.payload, self.config), msg= "Error Validating Spatial Region Record SerialID: {2} Lat: {0} Long: {1}" .format(msg.get_payload_value("latitude"), msg.get_payload_value("longitude"), msg.get_payload_value("serialId"))) self.assertIsNotNone( msg.get_payload_value('serialId', None), msg="Vehicle Record Serial ID is Missing") except AssertionError as e: self.logger.warn(e.message) exception_list.append(e) # self.assertTrue(testRunnerHelper.validate_location(msg.payload,self.config), "Location Validation Issue") # self.assertTrue(testRunnerHelper.validate_datetime(msg.payload,self.config), "Temporal Validation Issue") else: record_count += 1 self.logger.info('Received %d results', record_count) self.assertGreaterEqual( record_count, kwargs.get('min_records', 5), "Did Not receive at least {} records from the ODE".format( kwargs.get('min_records', 5))) self.assertLessEqual( record_count, kwargs.get('limit', 100), "Received more than the requested amount of records. Request at most {} records" .format(kwargs.get('limit', 100))) self.assertEqual(len(exception_list), 0, "Encountered More than expected Validation Errors")
class ODE_Streaming_API_Authentication_Tests(unittest.TestCase): __metaclass__ = LogThisTestCase logger = logging.getLogger("unitTest") logger.setLevel(logging.INFO) config = testRunnerHelper.parse_config_file( os.path.join('.', 'test_config_files', 'test_Authentication_config.ini')) userName = config['USERNAME'] password = config['PASSWORD'] host = config['HOST'] service_region = config['SERVICE_REGION'] # {'nwLat': '45.33', 'seLat': '37.0', 'seLon': '-75.1', 'nwLon': '-86.0'} start_date = config['START_DATE'] # '2014-01-13T19:52:45.500Z' end_date = config['END_DATE'] #'2015-05-17T17:52:45.500Z' skip = config['SKIP'] limit = config['LIMIT'] invalid_token = "ZZZZZXXXXXXXbGciOiJkaXIiLCJlbmMiOiJBMTI4Q0JDLUhTMjU2In0..jhHij4fTNtDbe38qkiPqjQ.gP82_DfoqGHeGMILhTkjCvIVK9Hn_BE9a8LyoQ_SSZ2wuax3cQgcF0HVVTPxLlcoNGfGorwelfm06idRqzeQT-4aHd5YWSWVfGpDotuIehAYYde9Xksw3NosKjk2h8gKj__gC6OzEYjNZNeYReC89OFuFms5QXoLBwzBLDAZDn02EyFPRlXTR_lpCsZ6HaSGXGFET4t3qvGhniBE63WdvEbXry5PGxIFC76zqUT3roq8rcxWCwwFRTRUrHhHmlU0ouqeYZea26euw9Y0NVw7BMilwR1p5SW4yp5vGM0NmMrld4t03T33JBQh0LSMMfbKOnZqFMIis01JBM2beAt85FGj9giGgExL2RFuxbHtMnSUYTsrCZSvvILWuxw7VbAlnqKIsIEofqNxyj6kk2duSVKW8q23N7cjzDEfj3r2mbIb5NMSHYMJkTidYKIquR7c-KV85Q-4YEby24DfxGfrBqg0U27ebl5NjVEO36-gtLfQUELAQhfjycNc1FHuwAWhuBkHAa92X-6q8XEgYX4XQOD3lQHZOt-4MPG5ZiqAcA--5VonPc8N44sU9nkK1bXQCT6DgM_8GMIrfnkFaebrzEBMR2LJ6Ui_2Ol2oIYygqfzC7D8TkEUsJcXpiztJUPsF5slY4KgqJaqNAoaTJ3VyugeEDhlk02kYKkRczlGLyfasRWOH8zvTmRVYYrTysA5c_7tvcO_XHACTf17xTnWtqTcy2V5TsP5MxfONxBUSwtcPrkmyh9XCPW1OPTLiKTiObFSke8GFWawL15QK_oUkaOVCMHY4aFME_gliw8mgzRQhWW59PNpycgUEgb6xHBLJisu6QZnJ2VvYgQa_GsmxA.fWMsegYMRbdfVqDEKjbInQ" def logPoint(self): pass def setUp(self): # Does Not send a Request (Send data) to ODE. # Just Connects to ODE & processes the message received in # in the client On_message handler ode = client.ODEClient(self.host, on_open=lambda ws: None) ode.get_token(self.userName, self.password) self.client = None self.client = client.AsyncODEClient(odeClient=ode) self.region = testRunnerHelper.build_region(self.service_region) def tearDown(self): try: self.client.stop() self.client.client.destroy_token() self.client = None except Exception as e: pass time.sleep(1) def build_qry_request(self, data_type): return client.QueryRequest(data_type, self.region, self.start_date, self.end_date, self.skip, self.limit) def build_sub_request(self, data_type): return client.SubscriptionRequest(data_type, self.region) def test_Authentication_to_Int_Qry_API(self): """ Will Return ISD Data and not ODE Specific INT Data """ data_type = 'int' request = self.build_qry_request(data_type) self.client.setRequest(request) self.client.start() time.sleep(2) break_loop = False while not self.client.is_buffer_empty() and not break_loop: responses = self.client.get_messages(1) for msg in responses: self.logger.info("Response: %s", msg.toJson()) if msg.get_payload_type() in dataType.Status: self.assertIsNotNone(msg.get_payload_value('code', None)) self.assertEqual(msg.get_payload_value('code'), 'SUCCESS', msg) break_loop = True def test_Authentication_to_Veh_Qry_API(self): data_type = 'veh' request = self.build_qry_request(data_type) self.client.setRequest(request) self.client.start() time.sleep(2) break_loop = False while not self.client.is_buffer_empty() and not break_loop: responses = self.client.get_messages(1) for msg in responses: self.logger.info("Response: %s", msg.toJson()) if msg.get_payload_type() in dataType.Status: self.assertIsNotNone(msg.get_payload_value('code', None)) self.assertEqual(msg.get_payload_value('code'), 'SUCCESS', msg) beak_loop = True def test_Authentication_to_Adv_Qry_API(self): data_type = 'adv' request = self.build_qry_request(data_type) self.client.setRequest(request) self.client.start() time.sleep(2) break_loop = False while not self.client.is_buffer_empty() and not break_loop: responses = self.client.get_messages(1) for msg in responses: self.logger.info("Response: %s", msg.toJson()) if msg.get_payload_type() in dataType.Status: self.assertIsNotNone(msg.get_payload_value('code', None)) self.assertEqual(msg.get_payload_value('code'), u'SUCCESS', msg) break_loop = True def test_Authentication_to_Int_Sub_API(self): data_type = 'int' request = self.build_sub_request(data_type) self.run_valid_authentication_test(request) def test_Authentication_to_Veh_Sub_API(self): data_type = 'veh' request = self.build_sub_request(data_type) self.run_valid_authentication_test(request) def test_Authentication_to_Agg_Sub_API(self): data_type = 'agg' request = self.build_sub_request(data_type) self.run_valid_authentication_test(request) def test_revoked_token_Authentication_to_Int_Qry_API(self): data_type = 'int' request = self.build_qry_request(data_type) self.run_revoked_token_authentication_test(request) def test_revoked_token_Authentication_to_Veh_Qry_API(self): data_type = 'veh' request = self.build_qry_request(data_type) self.run_revoked_token_authentication_test(request) def test_revoked_token_Authentication_to_Adv_Qry_API(self): data_type = 'adv' request = self.build_qry_request(data_type) self.run_revoked_token_authentication_test(request) def test_revoked_token_Authentication_to_Int_Sub_API(self): data_type = 'int' request = self.build_sub_request(data_type) self.run_revoked_token_authentication_test(request) def test_revoked_token_Authentication_to_Veh_Sub_API(self): data_type = 'veh' request = self.build_sub_request(data_type) self.run_revoked_token_authentication_test(request) def test_revoked_token_Authentication_to_Agg_Sub_API(self): data_type = 'agg' request = self.build_sub_request(data_type) self.run_revoked_token_authentication_test(request) def test_revoked_token_Authentication_to_Int_Qry_API(self): data_type = 'int' request = self.build_qry_request(data_type) self.run_revoked_token_authentication_test(request) def test_Invalid_Authentication_to_Int_Veh_API(self): data_type = 'veh' request = self.build_qry_request(data_type) self.client.client.token = self.invalid_token self.client.setRequest(request) self.run_invalid_token_authentication_test() def test_Invalid_Authentication_to_Int_Adv_API(self): data_type = 'adv' request = self.build_qry_request(data_type) self.client.client.token = self.invalid_token self.client.setRequest(request) self.run_invalid_token_authentication_test() def test_Invalid_Authentication_to_Int_Sub_API(self): data_type = 'int' request = self.build_qry_request(data_type) self.client.client.token = self.invalid_token self.client.setRequest(request) self.run_invalid_token_authentication_test() def test_Invalid_Authentication_to_Veh_Sub_API(self): data_type = 'veh' request = self.build_qry_request(data_type) self.client.client.token = self.invalid_token self.client.setRequest(request) self.run_invalid_token_authentication_test() def test_Invalid_Authentication_to_Agg_Sub_API(self): data_type = 'agg' request = self.build_qry_request(data_type) self.client.client.token = self.invalid_token self.client.setRequest(request) self.run_invalid_token_authentication_test() def run_valid_authentication_test(self, request): self.client.setRequest(request) self.client.start() time.sleep(2) break_loop = False while not self.client.is_buffer_empty() and not break_loop: responses = self.client.get_messages(1) for msg in responses: self.logger.info("Response: %s", msg.toJson()) if msg.get_payload_type() in dataType.Status: self.assertIsNotNone(msg.get_payload_value('code', None)) self.assertEqual(msg.get_payload_value('code'), 'SUCCESS', msg) break_loop = True def run_revoked_token_authentication_test(self, request, destroy_token=False): self.client.setRequest(request) self.assertIsNone(self.client.client.destroy_token()) self.run_invalid_token_authentication_test() def run_invalid_token_authentication_test(self): self.logger.info("Using Invalid Token") self.client.start() time.sleep(2) break_loop = False while not self.client.is_buffer_empty() and not break_loop: responses = self.client.get_messages(1) for msg in responses: self.logger.info("Response: %s", msg.toJson()) if msg.get_payload_type() in dataType.Status: self.assertIsNotNone(msg.get_payload_value('code', None)) self.assertEquals(msg.get_payload_value('code'), 'FAILURE') self.assertIn(unicode('Invalid or missing token'), msg.get_payload_value('message', '')) break_loop = True
def test_Connection_to_MAP_Sub_API(self): self.config = testRunnerHelper.parse_config_file( os.path.join('.', 'test_config_files', 'testCase_20_config.ini')) self.createClient() request = testRunnerHelper.build_subscription_request(self.config) self.run_subscription_test(request, dataType=u'isd', timeOut=90)