def test_limit(): vehicles = VehicleFactory.create_batch(3) ids = [vehicle.id for vehicle in vehicles] # create location timestamps sequentially for the vehicles base_datetime = timezone.make_aware(datetime(2000, 2, 18, 10, 00)) for i, vehicle in enumerate(vehicles): LocationFactory.create(vehicle=vehicle, timestamp=base_datetime + timedelta(seconds=10 * i)) data = get_list({'limit': 2}) assert {location['id'] for location in data} == {ids[2], ids[1]} # second last and last data = get_list({'limit': 1}) assert {location['id'] for location in data} == {ids[2]} # only last
def test_delay_in_list(settings): settings.STREET_MAINTENANCE_DELAY = TWO_YEARS_IN_SECONDS vehicle_from_2000 = VehicleFactory.create() LocationFactory.create_batch(4, vehicle=vehicle_from_2000, year=2000) vehicle_from_2000.update_last_location() vehicle_from_last_year = VehicleFactory.create() LocationFactory.create_batch(7, vehicle=vehicle_from_last_year, year=timezone.now().year - 1) vehicle_from_last_year.update_last_location() data = get_list() assert {vehicle['id'] for vehicle in data} == {vehicle_from_2000.id}
def test_since_in_list(): old_vehicles = VehicleFactory.create_batch(3) for vehicle in old_vehicles: LocationFactory.create(vehicle=vehicle, year=2000) new_vehicles = VehicleFactory.create_batch(3) new_ids = [vehicle.id for vehicle in new_vehicles] for vehicle in new_vehicles: LocationFactory.create(vehicle=vehicle, year=timezone.now().year - 1) data = get_list({'since': '2years ago'}) assert {location['id'] for location in data} == set(new_ids)
def test_list_and_detail_endpoint(vehicle, locations_for_vehicle): last_location = Location.objects.last() last_location.events.add(EventType.objects.get(identifier='au')) last_location.events.add(EventType.objects.get(identifier='hi')) expected_data = { 'location_history': [], 'id': vehicle.id, 'last_location': get_location_data_from_obj(last_location) } list_data = get_list() assert list_data == [expected_data] detail_data = get_detail(vehicle) assert detail_data == expected_data
def test_default_limit(): LocationFactory.create_batch(15) data = get_list() assert len(data) == 10
def test_cannot_get_location_history_in_list(locations_for_vehicle): data = get_list({'history': 3}) assert data[0]['location_history'] == []