def add_task(request): if request.method == 'POST': if request.POST.get('name'): task = Task(name=request.POST.get('name')) task.save() return redirect('tasks:get_tasks') else: return HttpResponseNotAllowed(['POST'])
def test_view_delete_task(self): # arrange client = Client() task = Task(name='namename') task.save() # act post_response = client.post('/tasks/delete', {'id': task.id}) # assert self.assertRaises(Task.DoesNotExist, Task.objects.get, pk=task.id)
def test_view_change_state(self): # arrange client = Client() task = Task(name="namename") task.save() state_prev = task.done # act post_response = client.post('/tasks/change-state', {"id": task.id}) task = Task.objects.filter(name="namename").first() # assert self.assertNotEquals(state_prev, task.done)
def test_add_task(self): ''' add task, is empty, ''' # arrange tasks_list = TaskList() tasks_list.save() task = Task(name="name!!") task.save() #act tasks_list.add_task(task) # assert self.assertFalse(tasks_list.is_empty())
def test_view_edit_name(self): # arrange client = Client() pre_name = 'name' post_name = 'post' task = Task(name=pre_name) task.save() # act post_response = client.post('/tasks/edit-name', { 'id': task.id, 'name': post_name }) task = Task.objects.get(pk=task.id) # assert self.assertEquals(post_name, task.name)
def test_name(self): # arrange name = "Name" task = Task(name=name) # act # assert self.assertEquals(name, task.name)
def test_list(self): # arrange task_list = TaskList(name="Lista") task_list.save() task1 = Task(name="Tarea1") task1.save() task_list.add_task(task1) task2 = Task(name="Tarea2") task2.save() task_list.add_task(task2) # act t_list = task_list.get_tasks() # assert self.assertTrue(task1 in t_list) self.assertTrue(task2 in t_list)
def test_change_state(self): # arrange task = Task(name="Name") # act prev_state = task.done task.change_state() curr_state = task.done task.change_state() # assert self.assertFalse(prev_state) self.assertTrue(curr_state) self.assertFalse(task.done)
def test_pending(self): # arrange task = Task(name="Name") # act # assert self.assertFalse(task.done)