def test_stupid(self): qp = QueryProperty(db, Vehicle) class Dummy(object): vehicles = qp qp.model = object self.assertIsNone(Dummy.vehicles)
def test_bad_attr(self): with self.assertRaises(AttributeError) as ctx: QueryProperty(db, Vehicle).dummy(db.joinedload(Vehicle.owner)) self.assertEqual( ctx.exception.args, ( "<QueryProperty db=<SQLAlchemy engine=postgresql://postgres@localhost/test>, model='Vehicle'> object has no attribute 'dummy'", ), )
def test_bad_attr(self): with self.assertRaises(AttributeError) as ctx: QueryProperty(db, Vehicle).dummy(db.joinedload(Vehicle.owner)) self.assertEqual( ctx.exception.args, (f"<QueryProperty db=<SQLAlchemy engine=postgresql://postgres:***@{settings.DB_URL.host}/test>, " "model='Vehicle'> " "object has no attribute 'dummy'", ), )
class Dummy(object): vehicles = QueryProperty(db, None)
class Dummy(object): vehicles = QueryProperty(db, Vehicle).options(db.joinedload(Vehicle.owner)) used_vehicles = QueryProperty(db, Vehicle, Vehicle.is_used.is_(True)) new_vehicles = QueryProperty(db, Vehicle, is_used=False)
class Dummy: vehicles = QueryProperty(db, None)