def setUp(self) -> None: self.database_service = mock.MagicMock( spec=DatabaseService) # type: DatabaseService self.session_getter = mock.MagicMock(spec=Session.object_session) self.service = Service(self.database_service, session_getter_for_model=self.session_getter)
async def __anext__(self) -> Awaitable: if self._last_served_index < len(self.services): service = self._AsyncServiceFuture( Service(self.services[self._last_served_index])) self._last_served_index += 1 else: raise StopAsyncIteration() return service
def test_get_id(self, db_service: DatabaseService) -> None: """ Tests that a service model takes on the ID of its database model :param db_service: A randomly-generated DatabaseService """ service = Service(db_service) self.assertEqual(service.id, db_service.id)
def test_getitem(self) -> None: """ Test that the model is queried correctly, and """ service = self.service_list[self.service_id] self.assertEqual( service, Service(self.db_model) )
def services(draw, db_services=service_generator()) -> Service: """ :param draw: A function provided by hypothesis, that explains how to draw from hypothesis strategies :param db_services: The strategy used to generate database models representing services :return: An instance of the model service """ return Service(draw(db_services))
def setUp(self) -> None: """ Overload the getter for SQLAlchemy sessions for a given database model with a mock. This method should work similarly to ``Session.object_session``, which returns the SQLAlchemy ORM session to which the model class is bound """ TestService.setUp(self) self.session_getter = mock.MagicMock(spec=Session.object_session) self.service = Service(self.database_service, session_getter_for_model=self.session_getter)
def test_setting_description_changes_models( self, description: str, db_service: DatabaseService) -> None: """ Tests that setting the description on the service model class will also set the description on the underlying database service :param description: The description to set :param db_service: The randomly-generated database service """ service = Service(db_service) service.description = description self.assertEqual(description, service.description) self.assertEqual(description, db_service.description)
def test_setting_name_changes_the_models( self, name: str, db_service: DatabaseService) -> None: """ Tests that setting a name on the service changes the name on the underlying database service :param name: The new name :param db_service: The new database service """ service = Service(db_service) service.name = name self.assertEqual(name, service.name) self.assertEqual(name, db_service.name)
def new(self, name: str, description: str, registration_schema: JSON, result_schema: JSON) -> Service: service = DatabaseService.new(name, description, registration_schema, result_schema) self.session.add(service) return Service(service)
def __iter__(self) -> Iterator[Service]: return (Service(db_service) for db_service in self.session.query(DatabaseService).all())
def __getitem__(self, service_id: UUID) -> Service: db_model = self._get_db_model_by_id(self.session, service_id) return Service(db_model)
def test_job_registration_schema(self, db_service: DatabaseService) -> None: service = Service(db_service) self.assertEqual(service.job_registration_schema, db_service.job_registration_schema)