Ejemplo n.º 1
0
    def test_order_count_by_status(self):
        self.cpolicy.SetProbability(1.0)

        def neworder(status, test=False):
            o = model.Order(status=status,
                            price=300.0,
                            create_time=datetime.datetime.now(),
                            coupon_type="test",
                            test=test)
            o.put()

        # Create some orders
        neworder(model.Order.ST_PENDING)
        neworder(model.Order.ST_PENDING)
        neworder(model.Order.ST_PENDING)

        neworder(model.Order.ST_PAID)
        neworder(model.Order.ST_PAID)

        neworder(model.Order.ST_SPAWNED)
        neworder(model.Order.ST_SPAWNED, test=True)
        neworder(model.Order.ST_SPAWNED, test=True)

        # Calculate statistics
        stats = model.order_count_by_status()

        # Verify stats
        self.assertEqual(stats,
                         {model.Order.ST_SPAWNED: 1,
                          model.Order.ST_PAID: 2})
Ejemplo n.º 2
0
    def get(self):
        values = memcache.get('stats')
        if not values:
            byorderstatus = model.order_count_by_status()
            bytype = model.coupon_count_by_type()
            bycouponstatus = model.coupon_count_by_status()

            values = {'orders_by_status': byorderstatus,
                      'coupons_by_type': bytype,
                      'coupons_by_status': bycouponstatus}
            logging.info("Uncached: %s" % values)
            memcache.add('stats', values, 60 * 60 * 24)

        write_template(self.response, "dashboard.html", values)