def test_calc_streak_broken(self): e = Entry( parent=self.task, date=timezone.now() + timedelta(days=30), value=10 ) eq_(e._calc_streak(), 1)
def create_task_entry(request): """Creates an entry for a focus task.""" response = {} payload = request.POST task_name = payload['task_name'] val = payload['value'] date = parse(payload['date']) ref = payload['reference'] user = authenticate_to_user(request) try: t = Task.objects.get(owner=user, name=task_name) except ObjectDoesNotExist: response['error'] = 'Task does not exist.' return response try: e = Entry.objects.get(parent=t, value=val, date=date, reference=ref) except ObjectDoesNotExist: e = Entry(parent=t, value=val, date=date, reference=ref) e.save() response['success'] = 'Entry created successfully.' except MultipleObjectsReturned: entries = Entry.objects.filter( parent=t, value=val, date=date, reference=ref ) response['error'] = 'Entry exists multiple times: %s' % entries else: response['info'] = 'Entry already exists.' return response
def test_parent_entries(self): e = Entry(parent=self.task, date=timezone.now(), value=1.) assert e in e._parent_entries()
def test_calc_streak_dedupe(self): total = len(self.entries) midway = self.entries[int(total/2)] e = Entry(parent=self.task, date=midway.date, value=10) e.save() eq_(self.entries[-1]._calc_streak(), total)