def delete(self, d): id = self.request.get_range('id') habit = self.user.get(Habit, id=id) if habit: habit = Habit.get_by_id(int(id), parent=self.user.key) habit.key.delete() self.success = True self.set_response()
def test_habit_calls(self): # List response = self.get_json("/api/habit", {}, headers=self.api_headers) h = response.get('habits')[0] self.assertEqual(h.get('name'), "Run") # Update response = self.post_json("/api/habit", { 'id': h.get('id'), 'name': 'Walk' }, headers=self.api_headers) h = response.get('habit') self.assertEqual(h.get('name'), 'Walk') # Actions today = datetime.now() DAY = tools.iso_date(today - timedelta(days=1)) hid = h.get('id') actions = [{ 'action': 'commit', 'expected_prop': 'committed' }, { 'action': 'toggle', 'expected_prop': 'done' }] for act in actions: params = {'habit_id': hid, 'date': DAY} response = self.post_json("/api/habit/%s" % act.get('action'), params, headers=self.api_headers) hd = response.get('habitday') prop = act.get('expected_prop') self.assertTrue(hd.get(prop)) # Recent response = self.get_json("/api/habit/recent", {'days': 3}, headers=self.api_headers) habitdays = response.get('habitdays') self.assertTrue(hd.get('id') in habitdays) # Recent params = { 'start_date': tools.iso_date(today - timedelta(days=2)), 'end_date': tools.iso_date(today) } response = self.get_json("/api/habit/range", params, headers=self.api_headers) habitdays = response.get('habitdays') self.assertTrue(hd.get('id') in habitdays) # Delete response = self.post_json("/api/habit/delete", {'id': h.get('id')}, headers=self.api_headers) h = Habit.get_by_id(h.get('id'), parent=self.u.key) self.assertIsNone(h) # Confirm deletion
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})
def test_habit_calls(self): # List response = self.get_json("/api/habit", {}, headers=self.api_headers) h = response.get('habits')[0] self.assertEqual(h.get('name'), "Run") # Update response = self.post_json("/api/habit", {'id': h.get('id'), 'name': 'Walk'}, headers=self.api_headers) h = response.get('habit') self.assertEqual(h.get('name'), 'Walk') # Actions today = datetime.now() DAY = tools.iso_date(today - timedelta(days=1)) hid = h.get('id') actions = [ {'action': 'commit', 'expected_prop': 'committed'}, {'action': 'toggle', 'expected_prop': 'done'} ] for act in actions: params = { 'habit_id': hid, 'date': DAY } response = self.post_json("/api/habit/%s" % act.get('action'), params, headers=self.api_headers) hd = response.get('habitday') prop = act.get('expected_prop') self.assertTrue(hd.get(prop)) # Recent response = self.get_json("/api/habit/recent", {'days': 3}, headers=self.api_headers) habitdays = response.get('habitdays') self.assertTrue(hd.get('id') in habitdays) # Recent params = { 'start_date': tools.iso_date(today - timedelta(days=2)), 'end_date': tools.iso_date(today) } response = self.get_json("/api/habit/range", params, headers=self.api_headers) habitdays = response.get('habitdays') self.assertTrue(hd.get('id') in habitdays) # Delete response = self.post_json("/api/habit/delete", {'id': h.get('id')}, headers=self.api_headers) h = Habit.get_by_id(h.get('id'), parent=self.u.key) self.assertIsNone(h) # Confirm deletion
def test_habit_calls(self): # List response = self.get_json("/api/habit", {}, headers=self.api_headers) h = response.get('habits')[0] self.assertEqual(h.get('name'), "Run") # Update response = self.post_json("/api/habit", { 'id': h.get('id'), 'name': 'Walk' }, headers=self.api_headers) h = response.get('habit') self.assertEqual(h.get('name'), 'Walk') # Actions DAY = '2017-01-02' hid = h.get('id') actions = [{ 'action': 'commit', 'expected_prop': 'committed' }, { 'action': 'toggle', 'expected_prop': 'done' }] for act in actions: params = {'habit_id': hid, 'date': DAY} response = self.post_json("/api/habit/%s" % act.get('action'), params, headers=self.api_headers) hd = response.get('habitday') prop = act.get('expected_prop') self.assertTrue(hd.get(prop)) # Delete response = self.post_json("/api/habit/delete", {'id': h.get('id')}, headers=self.api_headers) h = Habit.get_by_id(h.get('id'), parent=self.u.key) self.assertIsNone(h) # Confirm deletion