예제 #1
0
 def test_retrieve_history(self):
     # Toggle today and yesterday (create 2 habitdays)
     marked_done, hd = HabitDay.Toggle(self.habit_read, datetime.today())
     marked_done, hd = HabitDay.Toggle(self.habit_read,
                                       datetime.today() - timedelta(days=1))
     hd_keys = HabitDay.All(self.habit_read.key)
     self.assertEqual(len(hd_keys), 2)
예제 #2
0
    def test_toggle(self):
        # Mark done (creating new habit day)
        marked_done, hd = HabitDay.Toggle(self.habit_run, datetime.today())
        self.assertTrue(marked_done)
        self.assertIsNotNone(hd)
        self.assertTrue(hd.done)

        # Mark not done
        marked_done, hd = HabitDay.Toggle(self.habit_run, datetime.today())
        self.assertFalse(marked_done)
        self.assertIsNotNone(hd)
        self.assertFalse(hd.done)
예제 #3
0
    def test_delete_history(self):
        marked_done, hd = HabitDay.Toggle(self.habit_read, datetime.today())
        marked_done, hd = HabitDay.Toggle(self.habit_run, datetime.today())

        self.habit_read.delete_history()  # Schedules background task
        self.execute_tasks_until_empty()
        hd_keys = HabitDay.All(self.habit_read.key)
        self.assertEqual(len(hd_keys), 0)  # Confirm both deleted

        # Confirm habit_run not affected
        hd_keys = HabitDay.All(self.habit_run.key)
        self.assertEqual(len(hd_keys), 1)  # Confirm still in db
예제 #4
0
    def _habit_or_task_report(self, item_name):
        '''
        Mark a habit or a task as complete
        '''
        handled = False
        speech = None
        if item_name:
            habits = Habit.Active(self.user)
            for h in habits:
                if item_name.lower() in h.name.lower():
                    # TODO: Timezone?
                    done, hd = HabitDay.Toggle(h,
                                               datetime.today().date(),
                                               force_done=True)
                    encourage = random.choice(HABIT_DONE_REPLIES)
                    speech = "%s '%s' is marked as complete." % (encourage,
                                                                 h.name)
                    handled = True
                    break
            if not handled:
                # Check tasks
                tasks = Task.Recent(self.user)
                for t in tasks:
                    if item_name.lower() in t.title.lower():
                        t.mark_done()
                        t.put()
                        speech = "Task '%s' is marked as complete." % (t.title)
                        handled = True
                        break

            if not handled:
                speech = "I'm not sure what you mean by '%s'." % item_name
        else:
            speech = "I couldn't tell what habit or task you completed."
        return speech
예제 #5
0
    def test_habit_report(self):
        habit_run = Habit.Create(self.u)
        habit_run.Update(name="Run")
        habit_run.put()
        marked_done, hd = HabitDay.Toggle(habit_run, datetime.today())

        self._test_report(
            {'type': REPORT.HABIT_REPORT},
            [["Created", "Updated", "Date", "Habit", "Done", "Committed"],
             [
                 tools.sdatetime(hd.dt_created, fmt="%Y-%m-%d %H:%M:%S %Z"),
                 tools.sdatetime(hd.dt_updated, fmt="%Y-%m-%d %H:%M:%S %Z"),
                 tools.iso_date(datetime.now()), "Run", "1", "0"
             ]])
예제 #6
0
 def toggle(self, d):
     '''
     Mark done/not-done for a habit day
     '''
     from constants import HABIT_DONE_REPLIES
     habit_id = self.request.get_range('habit_id')
     day_iso = self.request.get('date')
     habit = Habit.get_by_id(habit_id, parent=self.user.key)
     hd = None
     if habit:
         marked_done, hd = HabitDay.Toggle(habit,
                                           tools.fromISODate(day_iso))
         if marked_done:
             self.message = random.choice(HABIT_DONE_REPLIES)
         self.success = True
     self.set_response({'habitday': hd.json() if hd else None})
예제 #7
0
    def _habit_or_task_report(self, item_name):
        '''
        Mark a habit or a task as complete
        '''
        handled = False
        speech = None
        if item_name:
            habits = Habit.Active(self.user)
            for h in habits:
                if item_name.lower() in h.name.lower():
                    d = self.user.local_time().date()
                    encourage = random.choice(HABIT_DONE_REPLIES)
                    if h.has_daily_count():
                        done, hd = HabitDay.Increment(h, d)
                        speech = "%s The count of '%s' has been increased to %d " % (
                            encourage, h.name, hd.count)
                        remaining = h.tgt_daily - hd.count
                        speech += "(habit complete!)" if not remaining else "(%d to go)" % remaining
                    else:
                        done, hd = HabitDay.Toggle(h, d, force_done=True)
                        speech = "%s '%s' is marked as complete." % (encourage,
                                                                     h.name)
                    handled = True
                    break
            if not handled:
                # Check tasks
                tasks = Task.Recent(self.user)
                for t in tasks:
                    if item_name.lower() in t.title.lower():
                        t.mark_done()
                        t.put()
                        speech = "Task '%s' is marked as complete." % (t.title)
                        handled = True
                        break

            if not handled:
                speech = "I'm not sure what you mean by '%s'." % item_name
        else:
            speech = "I couldn't tell what habit or task you completed."
        return speech
예제 #8
0
    def setUp(self):
        self.set_application(tst_app)
        self.setup_testbed()
        self.init_datastore_stub()
        self.init_memcache_stub()
        self.init_taskqueue_stub()
        self.init_mail_stub()
        self.register_search_api_stub()
        self.init_app_basics()

        self.u = u = self.users[0]
        self.u.Update(name="George")
        self.u.put()
        h = Habit.Create(u)
        h.Update(name="Run")
        h.put()
        done, hd = HabitDay.Toggle(h, datetime.today())
        t = Task.Create(u, "Dont forget the milk")
        t.put()
        g = Goal.CreateMonthly(u, date=datetime.today().date())
        g.Update(text=["Get it done", "Also get exercise"])
        g.put()