def test_remove_task(self): """Should remove and specific task""" task_redis_id = self.rd.keys("task:*")[0] Task.remove(task_redis_id.replace('task:', '')) tasks = self.rd.keys("task:*") self.assertEqual(len(tasks), len(TASK_FIXTURES) - 1) self.assertFalse(self.rd.keys(task_redis_id))
def edit_task_title(): next = request.args.get('next', '/') Task.edit_field(current_user.get_id(), request.form['task_id'], 'title', request.form['title']) return redirect(next)
def edit_task_status(): next = request.args.get('next', '/') if request.form['status'] in ['True', 'true', 'TRUE']: status = 'completed' else: status = 'uncompleted' Task.edit_field(current_user.get_id(), request.form['task_id'], 'status', status) return redirect(next)
def test_edit_field(self): """Should change the value of a specific field""" task_redis_id = self.rd.keys("task:*")[0] old_task_data = self.rd.hgetall(task_redis_id) task_id = task_redis_id.replace('task:', '') Task.edit_field(task_id, 'title', 'New title') Task.edit_field(task_id, 'status', 'completed') new_task_data = self.rd.hgetall(task_redis_id) self.assertNotEqual(old_task_data['title'], 'New title') self.assertNotEqual(old_task_data['status'], 'completed') self.assertEqual('New title', new_task_data['title']) self.assertEqual('completed', new_task_data['status'])
def test_get_all_tasks(self): """Should get all the tasks for the given username""" tasks = Task.get_tasks(USER['username']) self.assertEqual(len(tasks), len(TASK_FIXTURES)) for task in tasks: self.assertTrue(task['title'] in TASK_FIXTURES) self.assertEqual(task['status'], 'uncompleted')
def day_tasks(): day_tasks = {} tasks = Task.get_tasks(current_user.get_id()) for task in tasks: day_tasks.setdefault(task['timestamp'], []).append(task) return render_template( 'tasks_day.html', day_tasks=day_tasks )
def setUp(self): super(TaskTestCase, self).setUp() for task in TASK_FIXTURES: t = Task(USER['username'], task) t.save()
def delete_task(): next = request.args.get('next', '/') Task.remove(request.form['task_id']) return redirect(next)
def create_task(): next = request.args.get('next', '/') t = Task(current_user.get_id(), request.form['task']) t.save() return redirect(next)
def uncompleted_tasks(): return render_template( 'tasks_completed.html', uncompleted_tasks=Task.get_tasks(current_user.get_id(), status='uncompleted') )
def week_tasks(): week_tasks = Task.get_tasks(current_user.get_id()) return render_template( 'tasks_week.html', week_tasks=week_tasks )