def test_Veh_Subscription_with_Upload_Test_Data(self): self.config['DATA'] = "veh" self.config['VALIDATION_FILE'] = os.path.join('.', 'test_json', 'sub_veh_200_records.json') self.config['INPUT_FILE'] = os.path.join('.', 'test_json', 'sub_veh_200_records.json') simulatedclient2.config.update(self.config) request = client.BaseRequest("tst", self.config['DATA'], simulatedclient2.build_region(self.config['SERVICE_REGION'])) self.client.setRequest(request) self.client.start() time.sleep(5) self.config['TEST_REQUEST'] = None while not self.client.is_buffer_empty() and self.config['TEST_REQUEST'] is None: responses = self.client.get_messages(1) for msg in responses: if msg.get_payload_type() in dataType.Status and msg.get_payload_value('requestId', False): self.config['TEST_REQUEST'] = msg.get_payload_value('requestId') depositClient.update_config(self.config) thread.start_new_thread(depositClient._run_main, (self.config,)) # Pause to allow data upload to commence # in separate thread, and to allow spark to process the data. # Spark may introduce some unknown delay. time.sleep(15) while not self.client.is_buffer_empty(): responses = self.client.get_all_messages() for msg in responses: print msg if msg.get_payload_type() in dataType.Status: self.assertIsNotNone(msg.get_payload_value('code', None)) self.assertEqual(msg.get_payload_value('code'), 'SUCCESS') if msg.get_payload_type() in dataType.VehicleData: self.assertEqual(msg.get_payload_value('dataType', None), 'veh') self.assertTrue(simulatedclient2.validate_location(msg.payload), msg="Error Validating Spatial Region Lat: {0} Long: {0}".format( msg.get_payload_value("latitude"), msg.get_payload_value("longitude"))) time.sleep(5)
def test_latitude_outside_requested_region(self): msg = json.loads(self.veh_json) msg['latitude'] = 0.00 simulatedclient2.config['SERVICE_REGION'] = self.service_region self.assertFalse(simulatedclient2.validate_location(msg))
def test_latitude_and_longitude_within_requested_region(self): msg = json.loads(self.veh_json) msg['longitude'] = 51.5072 msg['latitude'] = 0.1275 simulatedclient2.config['SERVICE_REGION'] = self.service_region self.assertFalse(simulatedclient2.validate_location(msg))
def test_longitude_equals_seLat_validates_true(self): msg = json.loads(self.veh_json) simulatedclient2.config['SERVICE_REGION'] = self.service_region msg['longitude'] = float(self.service_region['seLon']) self.assertTrue(simulatedclient2.validate_location(msg))