Beispiel #1
0
 def update_car_info(self, car_coordinates: dict):
     """Function that updates a car information and throws carStatus events if necessary
     If the car does not exist, it is build and added to the participants.
     Receives carCoordinates object
     """
     if CarCoordinates.validate_car_coordinates(car_coordinates):
         if car_coordinates.get('carIndex') in self.__cars.keys():
             car_to_update = self.__cars.get(car_coordinates.get('carIndex'))
         else:
             car_to_update = Car(float(car_coordinates.get('location').get('lat')),
                                 float(car_coordinates.get('location').get('long')),
                                 float(car_coordinates.get('timestamp')),
                                 int(car_coordinates.get('carIndex')))
             self.__add_car_to_the_race(car_to_update)
         car_to_update.update_car_coordinates(car_coordinates)
         self.__assign_position(float(car_coordinates.get('timestamp')))
         # Reporting
         if car_to_update.get_car_position() != 0:
             self.publish_car_status(car_to_update.generate_position_report())
         self.publish_car_status(car_to_update.generate_speed_report())
     else:
         pass
Beispiel #2
0
 def test_generate_speed_report_when_called__returns_valid_object(self):
     car = Car(0, 0, 0, 1)
     res = car.generate_speed_report()
     assert res
Beispiel #3
0
 def test_generate_speed_report_when_called_result_0_mph(self):
     car = Car(0, 0, 0, 1)
     res = car.generate_speed_report()
     res = json.loads(res)
     assert res['value'] == 0
Beispiel #4
0
 def test_generate_speed_report_when_called_result_has_same_timestamp(self):
     car = Car(0, 0, 0, 1)
     res = car.generate_speed_report()
     res = json.loads(res)
     assert res['timestamp'] == 0
Beispiel #5
0
 def test_generate_speed_report_when_called_result_has_same_car_index(self):
     car = Car(0, 0, 0, 1)
     res = car.generate_speed_report()
     res = json.loads(res)
     assert res['carIndex'] == 1
Beispiel #6
0
 def test_generate_speed_report_when_called__returns_speed_type_report(
         self):
     car = Car(0, 0, 0, 1)
     res = car.generate_speed_report()
     res = json.loads(res)
     assert res['type'] == 'SPEED'