@@ -522,6 +522,8 @@ def test_campaign_totals(self):
522522 self .ad1 .incr (CLICKS , self .publisher )
523523 self .ad1 .incr (CLICKS , self .publisher )
524524
525+ self .flight .refresh_denormalized_totals ()
526+
525527 self .assertAlmostEqual (self .campaign .total_value (), 4.0 )
526528
527529 cpm_flight = get (
@@ -551,6 +553,10 @@ def test_campaign_totals(self):
551553 ad2 .incr (VIEWS , self .publisher )
552554 ad2 .incr (VIEWS , self .publisher )
553555
556+ # Refresh denormalized totals for both flights
557+ self .flight .refresh_denormalized_totals ()
558+ cpm_flight .refresh_denormalized_totals ()
559+
554560 self .assertAlmostEqual (self .campaign .total_value (), 4.3 )
555561
556562 def test_flight_state (self ):
@@ -576,12 +582,12 @@ def test_flight_value_remaining(self):
576582 self .flight .save ()
577583 self .assertAlmostEqual (self .flight .value_remaining (), 100 * 2 )
578584
579- # Each click is worth $2
585+ # Each click is $2
580586 self .ad1 .incr (CLICKS , self .publisher )
581587 self .ad1 .incr (CLICKS , self .publisher )
582588 self .ad1 .incr (CLICKS , self .publisher )
583589
584- self .flight .refresh_from_db ()
590+ self .flight .refresh_denormalized_totals ()
585591 self .assertAlmostEqual (self .flight .value_remaining (), 97 * 2 )
586592
587593 self .flight .cpm = 50.0
@@ -596,7 +602,7 @@ def test_flight_value_remaining(self):
596602 for _ in range (25 ):
597603 self .ad1 .incr (VIEWS , self .publisher )
598604
599- self .flight .refresh_from_db ()
605+ self .flight .refresh_denormalized_totals ()
600606 self .assertAlmostEqual (self .flight .value_remaining (), 5.0 - (25 * 0.05 ))
601607
602608 def test_projected_total_value (self ):
@@ -607,7 +613,7 @@ def test_projected_total_value(self):
607613 self .ad1 .incr (CLICKS , self .publisher )
608614 self .ad1 .incr (CLICKS , self .publisher )
609615
610- self .flight .refresh_from_db ()
616+ self .flight .refresh_denormalized_totals ()
611617 self .assertAlmostEqual (self .flight .projected_total_value (), 1000 * 2 )
612618
613619 self .flight .cpm = 50.0
@@ -727,7 +733,7 @@ def test_refund(self):
727733 for click in (click1 , click2 , click3 ):
728734 self .assertIsNotNone (click )
729735
730- self .flight .refresh_from_db ()
736+ self .flight .refresh_denormalized_totals ()
731737
732738 self .assertEqual (self .flight .total_clicks , 3 )
733739
@@ -760,7 +766,7 @@ def test_refund(self):
760766 self .assertTrue (offer .clicked )
761767
762768 # Reload data from the DB
763- self .flight .refresh_from_db ()
769+ self .flight .refresh_denormalized_totals ()
764770 impression .refresh_from_db ()
765771
766772 self .assertEqual (self .flight .total_clicks , 1 )
0 commit comments