Beispiel #1
0
    def setUp(self):
        self.client = Redis(decode_responses=True)
        self.client.flushdb()

        self.todolist = TodoList(self.client, "peter")

        self.events = [
            "buy some milk", "have lunch", "watch tv", "finish homework",
            "go to sleep"
        ]
Beispiel #2
0
def queue_todo(target, type):
    """Check todo list, queue to todo list if not exists"""
    if isinstance(target, str): # one target
        exists = session.query(TodoList).filter(TodoList.name == target).first()
        if not exists:
            session.add(TodoList(name=target, type=type, status=NEW))
    
    elif isinstance(target, list): #multiple targets
        to_add = []
        for each in target:
            exists = session.query(TodoList).filter(TodoList.name == each['name']).first()
            if not exists:
                to_add.append(TodoList(name=each['name'], type=type, status=NEW))
        session.add_all(to_add)

    session.commit()
    def test_sortTodos(self):
        todo_list = TodoList()
        todo_list.create_todo('Day 2', datetime.now() + timedelta(days=2))
        todo_list.create_todo('Day 1', datetime.now() + timedelta(days=1))
        todo_list.sort_todos()

        self.assertEqual(
            list(map(lambda todo: todo['content'], todo_list.get_todos())),
            ['Day 1', 'Day 2'],
        )
    def test_getTodosWithTag(self):
        todo_list = TodoList()
        todo_list.create_todo('テスト 1', datetime.now() + timedelta(days=1))
        todo_list.create_todo('テスト 2', datetime.now() + timedelta(days=2))

        def editor(todo):
            return {
                **todo,
                'tags': set(['プライベート']),
            }

        todo_list.edit_todo(0, editor)

        self.assertEqual(len(todo_list.get_todos('プライベート')), 1)
    def test_editTodo(self):
        todo_list = TodoList()
        todo_list.create_todo('テスト', datetime.now() + timedelta(days=1))

        def editor(todo):
            return {
                **todo,
                'content': 'テスト (編集済み)',
            }

        todo_list.edit_todo(0, editor)

        self.assertEqual(
            todo_list.get_todos()[0]['content'],  # *1
            'テスト (編集済み)',
        )
Beispiel #6
0
def add_tasks(mail_titles, list_name, mailbox):
    todo = TodoList(list_name)

    tasks_with_notes = [t for t in todo.get_tasks(True) if 'notes' in t]
    gmail_tasks = [t['title'] for t in tasks_with_notes if 'gmail' in t['notes']]
    finished_tasks = [t for t in tasks_with_notes if t['status'] == 'completed']
    finished_gmail_tasks = [t['title'] for t in finished_tasks if 'gmail' in t['notes']]

    # Unstar any finished tasks
    for task in finished_gmail_tasks:
        mailbox.delete_mail(task)
            
    # Clear finished tasks
    todo.clear_finished()

    # Add any newly starred email to tasks
    for mail in mail_titles:
        if not mail in gmail_tasks:
            todo.add_task(mail, 'gmail')
Beispiel #7
0
class TestTodoList(unittest.TestCase):
    """ 
	The basic class that inherits unittest.TestCase
	"""
    def setUp(self):
        self.todo_list = TodoList()

    def test_container_has_list_of_todo_instances(self):
        self.assertIsInstance(self.todo_list.container, list)

    def test_add_todo(self):
        #test if it is adding

        self.assertEqual(self.todo_list.count_todos(),
                         0)  #start at 0 because empty
        self.todo_list.add_todo("Do laundry")
        self.assertEqual(self.todo_list.count_todos(), 1)

    def test_remove_todo(self):

        self.assertEqual(self.todo_list.count_todos(), 0)
        todo = self.todo_list.add_todo("Pick up dry cleaning")
        id_to_remove = todo.id
        self.assertEqual(self.todo_list.count_todos(), 1)
        self.todo_list.remove_todo(id_to_remove)
        self.assertEqual(self.todo_list.count_todos(), 0)

    def test_complete_todo(self):
        self.assertEqual(self.todo_list.count_todos(), 0)
        todo = self.todo_list.add_todo("Pick up dry cleaning")
        id_to_remove = todo.id
        self.todo_list.complete_todo(id_to_remove)
        self.assertEqual(self.todo_list.show_todos(),
                         [id_to_remove, "Pick up dry cleaning", True])
Beispiel #8
0
 def setUp(self):
     self.todo_list = TodoList()
Beispiel #9
0
from todo import Todo
from todo_list import TodoList

print('''
1. Wyswietl liste.
2. Dodaj zadanie.
3. Usun zadanie.
4. Wyjdz.
''')

todo_list = TodoList()

while True:
    option = input('Wybierz czynnosc: (1|2|3|4): ')

    if option == '1':
        todo_list.show()

    if option == '2':
        content = input('Podaj tresc zadania: ')
        new_todo = Todo(content)
        todo_list.add(todo=new_todo)

    if option == '3':
        idx = int(input('Podaj indeks zadania do usuniecia: '))
        todo_list.remove(idx)

    if option == '4':
        break

print('Koniec dzialania progrmu.')
Beispiel #10
0
class TestTodoList(unittest.TestCase):
    def setUp(self):
        self.client = Redis(decode_responses=True)
        self.client.flushdb()

        self.todolist = TodoList(self.client, "peter")

        self.events = [
            "buy some milk", "have lunch", "watch tv", "finish homework",
            "go to sleep"
        ]

    def test_add(self):
        self.assertEqual(self.todolist.show_todo_list(), [])
        self.todolist.add(self.events[0])
        self.assertNotEqual(self.todolist.show_todo_list(), [])

    def test_remove(self):
        self.todolist.add(self.events[0])
        self.todolist.remove(self.events[0])
        self.assertEqual(self.todolist.show_todo_list(), [])

    def test_done(self):
        self.todolist.add(self.events[0])
        self.todolist.done(self.events[0])
        self.assertEqual(self.todolist.show_todo_list(), [])
        self.assertNotEqual(self.todolist.show_done_list(), [])

    def test_show_todo_list(self):
        self.assertEqual(self.todolist.show_todo_list(), [])

        for event in self.events:
            self.todolist.add(event)

        self.assertEqual(self.todolist.show_todo_list(),
                         list(reversed(self.events)))

    def test_show_done_list(self):
        self.assertEqual(self.todolist.show_done_list(), [])

        for event in self.events:
            self.todolist.add(event)

        for event in self.events:
            self.todolist.done(event)

        self.assertEqual(self.todolist.show_done_list(),
                         list(reversed(self.events)))
from os import environ
from datetime import datetime, timedelta
from flask import Flask, request, render_template
from flask.json import jsonify
from todo import Todo, edit_deadline, finish_todo, add_tag, remove_tag, to_json
from todo_list import TodoList

app = Flask(__name__)
app.config['TEMPLATES_AUTO_RELOAD'] = True

todolist = TodoList()


@app.after_request
def after_request(response):
    response.headers.add('Access-Control-Allow-Origin', '*')
    response.headers.add('Access-Control-Allow-Headers',
                         'Content-Type,Authorization')
    response.headers.add('Access-Control-Allow-Methods',
                         'GET,PUT,POST,DELETE,OPTIONS')

    return response


@app.route('/', methods=['GET'])
def get_index():
    return render_template('index.html')


@app.route('/assets/<path:file_path>')
def assets(file_path):
    def test_getTodos(self):
        todo_list = TodoList()
        todo_list.create_todo('テスト 1', datetime.now() + timedelta(days=1))
        todo_list.create_todo('テスト 2', datetime.now() + timedelta(days=2))

        self.assertEqual(len(todo_list.get_todos()), 2)
 def test_getTodoRaisesInvalidIdError(self):
     with self.assertRaises(Exception):
         todo_list = TodoList()
         todo_list.get_todo(0)
    def test_getTodo(self):
        todo_list = TodoList()
        todo_list.create_todo('テスト 1', datetime.now() + timedelta(days=1))
        todo_list.create_todo('テスト 2', datetime.now() + timedelta(days=2))

        self.assertEqual(todo_list.get_todo(0)['content'], 'テスト 1')
 def test_editTodoRaisesInvalidIdError(self):
     with self.assertRaises(Exception):
         todo_list = TodoList()
         todo_list.edit_todo(0, lambda todo: todo)
    def test_deleteTodo(self):
        todo_list = TodoList()
        todo_list.create_todo('テスト', datetime.now() + timedelta(days=1))
        todo_list.delete_todo(0)

        self.assertEqual(len(todo_list.get_todos()), 0)