Exemplo n.º 1
0
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'])
Exemplo n.º 2
0
 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)
Exemplo n.º 3
0
 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)
Exemplo n.º 4
0
 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())
Exemplo n.º 5
0
 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)
Exemplo n.º 6
0
 def test_name(self):
     # arrange
     name = "Name"
     task = Task(name=name)
     # act
     # assert
     self.assertEquals(name, task.name)
Exemplo n.º 7
0
    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)
Exemplo n.º 8
0
 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)
Exemplo n.º 9
0
 def test_pending(self):
     # arrange
     task = Task(name="Name")
     # act
     # assert
     self.assertFalse(task.done)