Ejemplo n.º 1
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
Ejemplo n.º 2
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)
Ejemplo n.º 3
0
def backgroundHabitDayDeletion(hkey, start_cursor=None):
    hkey = ndb.Key(urlsafe=hkey)
    done = False
    maxit = 50
    its = 0
    while not done and its < maxit:
        hds = HabitDay.All(hkey)
        if hds:
            ndb.delete_multi(hds)
            logging.debug("Deleted %d habit days from hkey=%s" %
                          (len(hds), hkey))
        else:
            done = True
        its += 1