def test_getting_todays_goals(self): self.byday_goal.delete() self.old_goal.delete() #self.simple_goal.create_scheduled_instances(self.today, 5) today = timezone.now() Goal.create_all_scheduled_instances(today, 5) first_instance = self.simple_goal.scheduledinstance_set.all()[0] self.assertEquals(Goal.goals_for_today(self.user)[0], first_instance) first_instance.completed = True first_instance.save() self.assertEquals(Goal.goals_for_today(self.user), [])
def forwards(self, orm): from django.contrib.auth.models import User from habits.models import UserProfile UserProfile.objects.all().delete() for user in User.objects.all(): print "Creating userprofile for user", user profile = UserProfile() profile.user = user profile.save() from django.utils import timezone orm.ScheduledInstance.objects.filter(date__gt=timezone.now()).delete() today = timezone.now() Goal.create_all_scheduled_instances(today, 5)
def test_generating_all_scheduled_instances(self): """ Tests generating scheduled instances for all goals. """ self.byday_goal.delete() self.assertEquals(Goal.objects.count(), 2) Goal.create_all_scheduled_instances(self.five_days_ago, 5) # 5*2 = 10 self.assertEquals(ScheduledInstance.objects.count(), 10) Goal.create_all_scheduled_instances(self.four_days_ago, 4) self.assertEquals(ScheduledInstance.objects.count(), 10) Goal.create_all_scheduled_instances(self.four_days_ago, 5) # one for the newer goal already exists self.assertEquals(ScheduledInstance.objects.count(), 11)