Exemplo n.º 1
0
    def test_load(self, mock_load):
        """ to test load method
        Scenarios:
        1. If call with proper name, then it will return success and call the
           function storage.load properly, the loaded list should be the same
           as the test list
        """
        # set the mock_load return value
        mock_load.return_value = dict(self.todo_list)

        # scenario 1 test
        print("test scenario 1: START")

        empty_list = todo.Todo()
        status = empty_list.load("test.pkl")

        err = "load is not run successfully"
        self.assertTrue(status, err)

        # load should be called with proper arguments
        mock_load.assert_called_with("test.pkl")

        err = "the todo_list state should be similar"
        self.assertEqual(empty_list._id, self.todo_list._id, err)
        self.assertDictEqual(empty_list.id_to_todo, self.todo_list.id_to_todo, err)

        print("test scenario 1: PASS")
Exemplo n.º 2
0
    def test_save_load(self):
        """ to test save/load method
        Scenarios:
        1. If I save the list, then a file should exist in the data folder
        2. If I load from saved file, I will receive list with same state
        """
        # scenario 1 test
        print("test scenario 1: START")

        self.todo_list.save("test.pkl")
        self.assertTrue(os.path.exists("data/test.pkl"))

        print("test scenario 1: PASS")

        # scenario 2 test
        print("test scenario 2: START")

        empty_list = todo.Todo()
        empty_list.load("test.pkl")

        err = "the todo_list state should be similar"
        self.assertEqual(empty_list._id, self.todo_list._id, err)
        self.assertDictEqual(empty_list.id_to_todo, self.todo_list.id_to_todo, err)

        print("test scenario 2: PASS")
Exemplo n.º 3
0
def generate_todo_object():
    """ helper method to generate todo object """
    todo_list = todo.Todo()
    todo_list._id = 4
    todo_list.id_to_todo = {1: "I need to think of a scenario",
                            2: "I need to write a test",
                            3: "I need to go sleep"}
    return todo_list
Exemplo n.º 4
0
def add():
    user_id = request.cookies.get('user_id')

    t = request.form['todo']
    # use unicode(), not str(), for Chinese chars
    newTodo = todo.Todo(task=unicode(t), user_id=int(user_id))
    todo.db.session.add(newTodo)
    todo.db.session.commit()

    return redirect(url_for('index'))
Exemplo n.º 5
0
    def test_add_method_checks_if_task_already_added(self):
        td = todo.Todo()
        self.assertEqual([], td.tasks)

        result = td.add("create repository")
        self.assertEqual(None, result)  # check that error was not returned
        self.assertEqual(["create repository"],
                         td.tasks)  # check that tasks was added to list

        result = td.add("create repository")
        self.assertEqual("task already exists",
                         result)  # error should have been returned
        self.assertEqual(["create repository"],
                         td.tasks)  # check that duplicate task was not added
Exemplo n.º 6
0
    def test_remove_method_removes_task_from_array(self):

        # create todos object
        td = todo.Todo()
        # ensure its tasks attribute is empty
        self.assertEqual([], td.tasks)

        # add a task
        td.tasks.append("create repository")
        # ensure task is in list
        self.assertEqual(["create repository"], td.tasks)

        # try remove the task
        td.remove("create repository")
        # task should have been removed
        self.assertEqual([], td.tasks)
Exemplo n.º 7
0
 def test_add_method_adds_task_string_to_task_array(self):
     td = todo.Todo()
     self.assertEqual([], td.tasks)
     td.add("create repository")
     self.assertEqual(["create repository"], td.tasks)
Exemplo n.º 8
0
 def test_it_initializes_a_list_attribute(self):
     td = todo.Todo()
     self.assertEqual([], td.tasks)
Exemplo n.º 9
0
 def test_remove_method_should_return_error_if_product_not_added(self):
     td = todo.Todo()
     error = td.remove("create repository")
     self.assertEqual("task was not added", error)