@@ -0,0 +1,2802 @@
+from decimal import Decimal%0Aimport sqlalchemy as sa%0Afrom sqlalchemy_utils.aggregates import aggregated%0Afrom tests import TestCase%0A%0A%0Aclass TestLazyEvaluatedSelectExpressionsForAggregates(TestCase):%0A    dns = 'postgres://postgres@localhost/sqlalchemy_utils_test'%0A%0A    def create_models(self):%0A        class Catalog(self.Base):%0A            __tablename__ = 'catalog'%0A            id = sa.Column(sa.Integer, primary_key=True)%0A            name = sa.Column(sa.Unicode(255))%0A            type = sa.Column(sa.Unicode(255))%0A%0A            __mapper_args__ = %7B%0A                'polymorphic_on': type%0A            %7D%0A%0A            @aggregated('products', sa.Column(sa.Numeric, default=0))%0A            def net_worth(self):%0A                return sa.func.sum(Product.price)%0A%0A            products = sa.orm.relationship('Product', backref='catalog')%0A%0A        class CostumeCatalog(Catalog):%0A            __tablename__ = 'costume_catalog'%0A            id = sa.Column(%0A                sa.Integer, sa.ForeignKey(Catalog.id), primary_key=True%0A            )%0A%0A            __mapper_args__ = %7B%0A                'polymorphic_identity': 'costumes',%0A            %7D%0A%0A        class CarCatalog(Catalog):%0A            __tablename__ = 'car_catalog'%0A            id = sa.Column(%0A                sa.Integer, sa.ForeignKey(Catalog.id), primary_key=True%0A            )%0A%0A            __mapper_args__ = %7B%0A                'polymorphic_identity': 'cars',%0A            %7D%0A%0A        class Product(self.Base):%0A            __tablename__ = 'product'%0A            id = sa.Column(sa.Integer, primary_key=True)%0A            name = sa.Column(sa.Unicode(255))%0A            price = sa.Column(sa.Numeric)%0A%0A            catalog_id = sa.Column(sa.Integer, sa.ForeignKey('catalog.id'))%0A%0A        self.Catalog = Catalog%0A        self.Product = Product%0A%0A    def test_assigns_aggregates_on_insert(self):%0A        catalog = self.Catalog(%0A            name=u'Some catalog'%0A        )%0A        self.session.add(catalog)%0A        self.session.commit()%0A        product = self.Product(%0A            name=u'Some product',%0A            price=Decimal('1000'),%0A            catalog=catalog%0A        )%0A        self.session.add(product)%0A        self.session.commit()%0A        self.session.refresh(catalog)%0A        assert catalog.net_worth == Decimal('1000')%0A%0A    def test_assigns_aggregates_on_update(self):%0A        catalog = self.Catalog(%0A            name=u'Some catalog'%0A        )%0A        self.session.add(catalog)%0A        self.session.commit()%0A        product = self.Product(%0A            name=u'Some product',%0A            price=Decimal('1000'),%0A            catalog=catalog%0A        )%0A        self.session.add(product)%0A        self.session.commit()%0A        product.price = Decimal('500')%0A        self.session.commit()%0A        self.session.refresh(catalog)%0A        assert catalog.net_worth == Decimal('500')%0A

Add tests for aggregates with inheritance