Пример #1
0
    def setUp(self):
        self.todo_service = TodoService(FakeTodoRepository(),
                                        FakeUserRepository())

        self.todo_a = Todo('testing a')
        self.todo_b = Todo('testing b')
        self.user_kalle = User('kalle', 'kalle123')
    def setUp(self):
        todo_repository.delete_all()
        user_repository.delete_all()

        self.todo_a = Todo('testing a')
        self.todo_b = Todo('testing b')
        self.user_kalle = User('kalle', 'kalle123')
        self.user_matti = User('matti', 'matti123')
    def test_find_by_username(self):
        kalle = user_repository.create(self.user_kalle)
        matti = user_repository.create(self.user_matti)

        todo_repository.create(Todo(content='testing a', user=kalle))
        todo_repository.create(Todo(content='testing b', user=matti))

        kalle_todos = todo_repository.find_by_username(
            self.user_kalle.username)

        self.assertEqual(len(kalle_todos), 1)
        self.assertEqual(kalle_todos[0].content, 'testing a')

        matti_todos = todo_repository.find_by_username(
            self.user_matti.username)

        self.assertEqual(len(matti_todos), 1)
        self.assertEqual(matti_todos[0].content, 'testing b')
Пример #4
0
    def create_todo(self, content):
        """Luo uuden tehtävän.

        Args:
            content: Merkkijonoarvo, joka kuvaa tehtävän sisältöä.
        Returns:
            Luotu tehtävä Todo-olion muodossa.
        """

        todo = Todo(content=content, user=self._user)

        return self._todo_repository.create(todo)
    def read(self):
        todos = []

        self.ensure_file_exists()

        with open(self.file_path) as file:
            for row in file:
                row = row.replace('\n', '')
                parts = row.split(';')

                todo_id = parts[0]
                content = parts[1]
                done = parts[2] == '1'
                username = parts[3]

                user = user_repository.find_by_username(
                    username) if username else None

                todos.append(Todo(content, done, user, todo_id))

        return todos