def service(self) -> Generator[dict, None, None]: """Instantiate a recurring ride service.""" services_api: ServicesAPI = ServicesAPI() service: dict = ServiceFactory.create(recurring_ride_service=True) yield service services_api.delete_service(service)
def test_create__returns_type_dict(self) -> None: """Check that a dictionary is created from the ServiceFactory create method.""" api: ServicesAPI = ServicesAPI() service = ServiceFactory.create() assert type(service) == dict api.delete_service(service)
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)
from utilities.factories.users import UserFactory from utilities.factories.vehicles import VehicleFactory register(AddressFactory) register(GroupFactory) register(RecurringRideFactory) register(RegionFactory) register(RideFactory) register(ServiceFactory) register(UserFactory) register(VehicleFactory) _addresses_api: AddressesAPI = AddressesAPI() _groups_api: GroupsAPI = GroupsAPI() _regions_api: RegionsAPI = RegionsAPI() _service_api: ServicesAPI = ServicesAPI() _vehicles_api: VehiclesAPI = VehiclesAPI() @pytest.fixture def address(address_factory: Factory) -> Generator[dict, None, None]: """Instantiate and tear down an address for testing the OnDemand Admin application. :param address_factory: A factory for building addresses via the API or UI. """ address: dict = address_factory.create(rider_address=False) yield address _addresses_api.delete_address(address, rider_address=False)
def set_api(self) -> None: """Instantiate all APIs used in ServicesAPI testing.""" self.api: ServicesAPI = ServicesAPI()
def set_api(self) -> None: """Instantiate all APIs used in RidesAPI testing.""" self.rides_api: RidesAPI = RidesAPI() self.services_api: ServicesAPI = ServicesAPI()
class ServiceFactory(Factory): """Create a new service for OnDemand testing. This is a factory which can be configured by passing in optional parameters for service customization via the nested class method. Multiple services may be created using the factory by calling a batch method. Optional parameters must match fields defined in the Service data class. :example usage: Fare Service: ServiceFactory.create(fare_service=True, in_advance_enabled=True) Non-Fare Service: ServiceFactory.create(in_advance_enabled=True) """ class Meta: model = Service class Params: """Optional boolean params which change factory output when True. :param exception_service_added: Create a service with an add service exception. :param exception_service_removed: Create a service with a remove service exception. :param expired_service: Create a service that has expired. :param fare_service: Create a service with a fare payment. :param future_ride_service: Create a service with future rides enabled. :param hub_address: Create a service with a hub. :param recurring_ride_service: Create a service with recurring rides enabled. :example usage: ServiceFactory.create(expired_service=True) """ exception_service_added: bool = Trait(exceptions=[ { 'end_time': f'{date.today() + timedelta(days=22)}T18:00:00.000Z', 'message': 'Testing Service Addition.', 'start_time': f'{date.today() + timedelta(days=15)}T09:30:00.000Z', 'type': 'service_added', }, ], ) exception_service_removed: bool = Trait(exceptions=[ { 'end_time': f'{date.today() + timedelta(days=7)}T18:00:00.000Z', 'message': 'Testing Service Removal.', 'start_time': f'{date.today() + timedelta(days=3)}T09:30:00.000Z', 'type': 'service_removed', }, ], ) expired_service: bool = Trait( end_date=date.isoformat(date.today() - timedelta(days=5)), start_date=date.isoformat(date.today() - timedelta(days=10)), ) fare_service: bool = Trait( fare_required=True, fare_price=2.0, ) future_ride_service: bool = Trait(in_advance_enabled=True) hub_address: bool = Trait(addresses=[{ 'hub': True, 'pickup': True, 'dropoff': True, 'address_id': '7539' }], ) recurring_ride_service: bool = Trait( in_advance_enabled=True, recurring_rides_enabled=True, ) _api: ServicesAPI = ServicesAPI() name: str = LazyAttribute( lambda _: f'{fake.company()}-{process_time()}-Service') @classmethod def _create(cls, model_class: Callable, **kwargs: Any) -> dict: """Override the default _create method to post against the Services API. :param model_class: The factory model used for generation. :param kwargs: Additional arguments being passed for generation. """ _service_dict: dict = model_class(**kwargs).__dict__ return cls._api.create_service(service_data=_service_dict)
def set_pages(self, selenium: fixture) -> None: """Instantiate all data used in Rides page filter testing.""" self.rides: Rides = Rides(selenium) self.services_API: ServicesAPI = ServicesAPI()
def set_pages(self, selenium: fixture) -> None: self.vehicles: Vehicles = Vehicles(selenium) self.API: VehiclesAPI = VehiclesAPI() self.services_API: ServicesAPI = ServicesAPI()