Exemple #1
0
 async def test_true_aggregate_avg(self):
     await testmodels.DecimalFields.create(decimal=Decimal("0"),
                                           decimal_nodec=1)
     await testmodels.DecimalFields.create(decimal=Decimal("9.99"),
                                           decimal_nodec=1)
     await testmodels.DecimalFields.create(decimal=Decimal("27.27"),
                                           decimal_nodec=1)
     values = await testmodels.DecimalFields.all().aggregate(Avg("decimal"))
     self.assertEqual(
         values,
         {"decimal__avg": Decimal("12.42")},
     )
Exemple #2
0
 async def test_aggregate_avg(self):
     await testmodels.DecimalFields.create(decimal=Decimal("0"),
                                           decimal_nodec=1)
     await testmodels.DecimalFields.create(decimal=Decimal("9.99"),
                                           decimal_nodec=1)
     await testmodels.DecimalFields.create(decimal=Decimal("27.27"),
                                           decimal_nodec=1)
     values = (await testmodels.DecimalFields.all().annotate(
         avg_decimal=Avg("decimal")).values("avg_decimal"))
     self.assertEqual(values, [{
         "avg_decimal": Decimal("0")
     }, {
         "avg_decimal": Decimal("9.99")
     }, {
         "avg_decimal": Decimal("27.27")
     }])
Exemple #3
0
 def test_insert_returning_aggregate(self):
     with self.assertRaises(QueryException):
         PostgreSQLQuery.into(self.table_abc).insert(1).returning(
             Avg(self.table_abc.views))