def test_build__params__same_day_future_ride(self) -> None: """Check that a same day future ride is built from the RideFactory.""" same_day_future_ride: dict = RideFactory.build( same_day_future_ride=True) assert (date.isoformat(date.today() + timedelta(hours=3)) in same_day_future_ride['pickup']['timestamp'])
def test_build__params__future_ride(self) -> None: """Check that a future ride is built from the RideFactory.""" future_ride: dict = RideFactory.build(future_ride=True) expected_pickup: str = future_ride['pickup']['timestamp'] assert date.isoformat(date.today() + timedelta(days=1)) in expected_pickup
def ride(self) -> Generator[dict, None, None]: """Instantiate a ride for RidesAPI method testing.""" service: dict = ServiceFactory() ride: dict = RideFactory(service=service) yield ride self.services_api.delete_service(service)
def test_build__override_default_values(self) -> None: """Check that RideFactory values may be overridden post-build.""" ride: dict = RideFactory.build() default_ride_status: str = ride['status'] ride['status'] = 'In Progress' assert ride['status'] != default_ride_status
class Params: """Optional params which change factory output when True. :param future_recurring_ride: Create a recurring ride for a future date. :param ride_with_note: Create a recurring ride with a driver note. :param same_day_future_recurring_ride: Create a same-day recurring ride for a future time. :example usage: RecurringRideFactory.create(future_recurring_ride=True) """ future_recurring_ride: bool = Trait(ride=RideFactory.build( future_ride=True)) ride_with_note: bool = Trait(ride=LazyAttribute( lambda _: RideFactory.build(ride_with_note=True)), ) same_day_future_recurring_ride: bool = Trait( ride=RideFactory.build(same_day_future_ride=True), )
def test_create__returns_type_dict(self) -> None: """Check that a dictionary is created from the RideFactory create method.""" services_api: ServicesAPI = ServicesAPI() service: dict = ServiceFactory.create() ride = RideFactory.create(service=service) assert type(ride) == dict services_api.delete_service(service)
def test_create_ride__success(self) -> None: """Check that a ride may be created.""" service: dict = ServiceFactory() ride_data: dict = RideFactory.build(service_id=service['service_id']) try: self.rides_api.create_ride(ride_data) self.services_api.delete_service(service) except HTTPError: pytest.fail('Test failed due to HTTPError.')
class RecurringRideFactory(Factory): """Create a new recurring ride for OnDemand testing. This is a factory which can be configured by passing in optional parameters for recurring ride customization via the nested class method. Multiple recurring rides may be created using the factory by calling a batch method. Optional parameters must match fields defined in the RecurringRide data class. :example usage: API: RecurringRideFactory.create() Non-API: RecurringRideFactory.build() RideFactory is a SubFactory of the RecurringRideFactory. Each time RecurringRideFactory is called, the RideFactory will also be called in order to build out a Ride object for the recurring ride. The ride object may be configured in the same manner as the base RideFactory. :example usage: API: RecurringRideFactory.create(ride=RideFactory.build(account_ride=True)) Non-API: RecurringRideFactory.build(ride=RideFactory.build(note='This is a test')) """ class Meta: model = RecurringRide class Params: """Optional params which change factory output when True. :param future_recurring_ride: Create a recurring ride for a future date. :param ride_with_note: Create a recurring ride with a driver note. :param same_day_future_recurring_ride: Create a same-day recurring ride for a future time. :example usage: RecurringRideFactory.create(future_recurring_ride=True) """ future_recurring_ride: bool = Trait(ride=RideFactory.build( future_ride=True)) ride_with_note: bool = Trait(ride=LazyAttribute( lambda _: RideFactory.build(ride_with_note=True)), ) same_day_future_recurring_ride: bool = Trait( ride=RideFactory.build(same_day_future_ride=True), ) _api: RecurringRidesAPI = RecurringRidesAPI() ride: dict = LazyAttribute(lambda _: RideFactory.build()) rides: List[dict] = [ { 'timestamp': date_objects.build_date_string(days=1) }, { 'timestamp': date_objects.build_date_string(days=3) }, { 'timestamp': date_objects.build_date_string(days=5) }, { 'timestamp': date_objects.build_date_string(days=7) }, { 'timestamp': date_objects.build_date_string(days=9) }, { 'timestamp': date_objects.build_date_string(days=11) }, ] @classmethod def _build(cls, model_class: Callable, **kwargs: Any) -> dict: """Override the default _build method to generate Recurring Ride data. :param model_class: The factory model used for generation. :param kwargs: Additional arguments being passed for generation. """ return model_class(**kwargs).__dict__ @classmethod def _create(cls, model_class: Callable, service: dict, **kwargs: Any) -> dict: """Override the default _create method to post against the Rides API. :param model_class: The factory model used for generation. :param service: The intended service for RecurringRide creation. :param kwargs: Additional arguments being passed for generation. """ kwargs['ride']['service_id'] = service['service_id'] _recurring_ride_dict: dict = model_class(**kwargs).__dict__ return cls._api.create_recurring_ride(ride_data=_recurring_ride_dict)
def test_build__subsequent_calls_return_new_ride(self) -> None: """Check that a new Ride is returned from the RideFactory build method.""" ride_one: dict = RideFactory.build() ride_two: dict = RideFactory.build() assert ride_one != ride_two
def test_build__returns_type_dict(self) -> None: """Check that a dictionary type is built from the RideFactory build method.""" ride = RideFactory.build() assert type(ride) == dict
def test_build__params__ride_with_note(self) -> None: """Check that a ride with note is built from the RideFactory.""" ride_with_note: dict = RideFactory.build(ride_with_note=True) assert ride_with_note['note'] is not None
def test_build__params__hub_ride(self) -> None: """Check that a hub ride is built from the RideFactory.""" hub_ride: dict = RideFactory.build(hub_ride=True) assert hub_ride['pickup']['address'] == 'Stop #300 - TransLoc Office'
def test_build__params__account_ride(self) -> None: """Check that an account ride is built from the RideFactory.""" account_ride: dict = RideFactory.build(account_ride=True) assert (account_ride['rider']['username'] == USERS.USERNAME and account_ride['rider']['email'] == USERS.EMAIL)
def test_build__requires_no_params(self) -> None: """Check that the RideFactory build method does not require params.""" ride: dict = RideFactory.build() assert ride is not None
def test_create__requires_service_param(self) -> None: """Check that the RideFactory create method requires a service param.""" with pytest.raises(TypeError) as e: RideFactory.create() # type: ignore assert "required positional argument: 'service'" in str(e.value)