Skip to content
This repository has been archived by the owner on Oct 4, 2022. It is now read-only.

Commit

Permalink
fix number of rounds bug + test
Browse files Browse the repository at this point in the history
Sum aggregates report None instead of 0
(https://code.djangoproject.com/ticket/10929). Not sure how this bug
hasn't bitten us before, but fixing it along with a test now
  • Loading branch information
alee committed Feb 22, 2015
1 parent 61819db commit 9501fdb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
8 changes: 5 additions & 3 deletions vcweb/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -486,8 +486,9 @@ def is_open(self):
def total_number_of_rounds(self):
number_of_rounds = self.round_configuration_set.count()
repeating_rounds = self.round_configuration_set.filter(repeat__gt=0)
repeated_rounds = repeating_rounds.aggregate(total=Sum('repeat'))
number_of_rounds = number_of_rounds - repeating_rounds.count() + repeated_rounds['total']
if repeating_rounds:
repeated_rounds = repeating_rounds.aggregate(total=Sum('repeat'))
number_of_rounds = number_of_rounds - repeating_rounds.count() + repeated_rounds['total']
return number_of_rounds

@property
Expand Down Expand Up @@ -1051,7 +1052,8 @@ def create_registration_email(self, participant_experiment_relationship, passwor
if from_email is None or not from_email.strip():
from_email = experimenter_email
msg = EmailMultiAlternatives(subject=subject, body=plaintext_content, from_email=from_email,
to=[participant_experiment_relationship.participant.email], bcc=['vcweb@asu.edu'],
to=[participant_experiment_relationship.participant.email],
bcc=[settings.DEFAULT_FROM_EMAIL],
headers={'Reply-To': experimenter_email})
msg.attach_alternative(html_content, "text/html")
return msg
Expand Down
9 changes: 7 additions & 2 deletions vcweb/experiment/lighterprints/tests.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import json
import logging

from datetime import date, timedelta
from django.conf import settings
from django.core.cache import cache
from vcweb.core.tests import BaseVcwebTest
Expand All @@ -26,6 +27,9 @@ def setUp(self, treatment_type='LEVEL_BASED', leaderboard=True, linear_public_go
super(BaseTest, self).setUp(experiment_metadata=get_lighterprints_experiment_metadata(), number_of_rounds=3,
**kwargs)
cache.clear()
e = self.experiment
e.start_date = date.today()
e.save()
ec = self.experiment_configuration
ec.has_daily_rounds = True
ec.set_parameter_value(parameter=get_leaderboard_parameter(), boolean_value=leaderboard)
Expand Down Expand Up @@ -118,6 +122,9 @@ def test_treatment_type(self):
self.assertTrue(is_scheduled_activity_experiment(e))
self.assertFalse(is_high_school_treatment(e))
self.assertTrue(is_community_treatment(e))
today = date.today()
self.assertEqual(e.start_date, today)
self.assertEqual(e.end_date, today + timedelta(e.number_of_rounds))

def test_perform_available_activities(self):
e = self.experiment
Expand Down Expand Up @@ -215,8 +222,6 @@ def test_payment_information(self):
for group in e.groups:
summary_emails = gs.email_generator.generate(group)
for email in summary_emails:
logger.error("recipients: %s", email.recipients())
logger.error("body: %s", email.body)
self.assertTrue(email.recipients())
self.assertTrue("tobacco hornworm" in email.body)

Expand Down

0 comments on commit 9501fdb

Please sign in to comment.