Exemple #1
0
 def test_set_priority_from_scratch(self):
     test_str = "2012-09-15 bar baz @home"
     test_item = TodoItem(test_str)
     self.assertIsNone(test_item.priority)
     test_item.priority = "D"
     self.assertIsNotNone(test_item.priority)
     self.assertEquals("(D) " + test_str, test_item.todo_txt_line)
Exemple #2
0
def test_db_helpers():
    table_name = 'test_table'
    assert check_table_exists(table_name) == False


    #testing query function(new table when if not exist)
    key=1
    query_db('select * from {username}')
    assert check_table_exists(table_name) == False

    #testing insert function
    todoitem = TodoItem('this is title',True, datetime(year= 2019, month = 10,day= 29)) 
    create_todo(todoitem)

    #testing query function(get all rows from a table if exist)
    
    for todo in query_db('select * from {username}'):
        print(todo)
        
        if todo[2] != '':
            temp_todo = TodoItem(todo[1], True if todo[3]==1 else False, datetime.datetime.strptime(todo[2],"%m/%d/%Y, %H:%M:%S"))
            print(temp_todo.is_done)
            todos.append(temp_todo)
    assert todos[0].title == 'this is title'

    #testing delete row function
    key = 0
    delete_todo('this is title')
    assert len(query_db('select * from {username}')) == 0


    #testing delete table function
    delete_table(table_name)
    assert check_table_exists(table_name) == False
Exemple #3
0
def main():
    # 1
    usename_input = input('Podaj nazwę użytkownika: ')
    password_input = input('Podaj hasło użtkownika: ')
    user = User(usename_input, password_input)

    # 2
    tasks = Todo()  # tworzymy obiekt z klasy todo

    # 3
    tasks.assign_user_to_todo(user)
    print(tasks.assigned_user)

    # 5
    first_note = TodoItem('zrobić zakupy')
    second_note = TodoItem('ogarnąć się')
    third_note = TodoItem('nauczyć się programować')
    # 4
    tasks.add_note(first_note)
    tasks.add_note(second_note)
    tasks.add_note(third_note)

    tasks.display_notes  # przed zmianą wyświetlamy
    tasks.notes[0].toggle_done()  # zmieniamy na 'Done'
    tasks.display_notes()  # po zmianie wyśiwetlamy
Exemple #4
0
 def test_set_task_existing(self):
     test_str = "(B) 2012-08-27 Xbox repair"
     test_item = TodoItem(test_str)
     self.assertIsNotNone(test_item.task)
     test_item.task = "ps3 polish"
     self.assertEqual("ps3 polish", test_item.task)
     self.assertEqual("(B) 2012-08-27 ps3 polish", test_item.todo_txt_line)
Exemple #5
0
 def test_del_priority(self):
     test_str = "(B) 2012-08-27 @home Xbox repair"
     test_item = TodoItem(test_str)
     test_item.priority = None
     self.assertIsNone(test_item.priority)
     self.assertEqual("2012-08-27 Xbox repair @home",
                      test_item.todo_txt_line)
Exemple #6
0
 def test_set_date_existing_date(self):
     test_str = "(B) 2012-02-05 @home Xbox repair"
     test_item = TodoItem(test_str)
     self.assertIsNotNone(test_item.creation_date)
     test_item.creation_date = "2012-01-04"
     self.assertIsNotNone(test_item.creation_date)
     self.assertEquals("(B) 2012-01-04 Xbox repair @home",
         test_item.todo_txt_line)
Exemple #7
0
 def test_mark_done(self):
     test_str = "(B) 2012-08-27 @home Xbox repair"
     done_item = TodoItem("x " + TodoItem.curr_date_str() +
                         " 2012-08-27 @home Xbox repair")
     test_item = TodoItem(test_str)
     test_item.done = True
     test_item.priority = None
     self.assertEqual(test_item.__dict__, done_item.__dict__)
Exemple #8
0
def items_view2():
    reader = "ReadOnly"  # added as part of module 10
    os.environ['LOGIN_DISABLED'] = 'True'
    return ViewModel([
        TodoItem(1, "Test in progress Todo", "To Do", datetime.now()),
        TodoItem(2, "Test Pending Todo", "Pending", datetime.now()),
        TodoItem(3, "Test Done Todo", "Done", datetime.now())
    ], reader)  # added as part of module 10
Exemple #9
0
 def test_set_priority_exists(self):
     test_str = "(A) 2012-09-15 bar baz @home"
     test_item = TodoItem(test_str)
     self.assertIsNotNone(test_item.priority)
     test_item.priority = "D"
     self.assertIsNotNone(test_item.priority)
     self.assertEquals("D", test_item.priority)
     self.assertEquals("(D) 2012-09-15 bar baz @home",
                       test_item.todo_txt_line)
Exemple #10
0
 def cmd_add(self):
     priarg = self.cmd.replace("add", "")
     new_td = TodoItem(self.addargs)
     new_td.priority = priarg
     new_td.create_today()
     #print "Adding " + str(new_td)
     self.td_file.append(new_td)
     self.save()
     self.cmd_ls()
Exemple #11
0
 def test_set_context_from_scratch(self):
     test_str = "(B) 2012-08-27 Xbox repair"
     test_item = TodoItem(test_str)
     self.assertIsNone(test_item.context)
     test_item.context = "work"
     self.assertIsNotNone(test_item.context)
     self.assertEqual("work", test_item.context)
     self.assertEqual("Xbox repair", test_item.task)
     self.assertEqual("(B) 2012-08-27 Xbox repair @work",
                      test_item.todo_txt_line)
Exemple #12
0
 def test_set_context_existing(self):
     test_str = "(B) 2012-08-27 Xbox repair @home"
     test_item = TodoItem(test_str)
     self.assertIsNotNone(test_item.context)
     self.assertEqual(test_item.context, "home")
     test_item.context = "work"
     self.assertIsNotNone(test_item.context)
     self.assertEqual("work", test_item.context)
     self.assertEqual(test_str.replace("home", "work"),
                      test_item.todo_txt_line)
Exemple #13
0
def index():
    form = ExampleForm()
    if form.field1.data != None:
        title = form.field1.data
        todo_item = TodoItem(title, False, datetime.datetime.now())
        create_todo(todo_item)
        print(form.field1.data)
    else:
        form.field1.description = ''

    #get all todos from database
    print('before the for loop')
    todos.clear()
    username = current_user.username
    print(current_user.username)
    for todo in query_db('select * from {username}'):
        print(todo)
        todo_items[todo[1]] = False
        if todo[2] != '':
            temp_todo = TodoItem(
                todo[1], True if todo[3] == 1 else False,
                datetime.datetime.strptime(todo[2], "%m/%d/%Y, %H:%M:%S"))
            print(temp_todo.is_done)
            todos.append(temp_todo)

    form.field1.data = ""

    done_count = len(list(filter(lambda todo: todo.is_done, todos)))
    undone_count = len(
        list(
            filter(
                lambda todo: not helpers.is_greater_than_24_hours(
                    todo.creation_date) and not todo.is_done, todos)))
    failed_count = len(
        list(
            filter(
                lambda todo: helpers.is_greater_than_24_hours(
                    todo.creation_date) and not todo.is_done, todos)))

    return render_template(
        'home.html',
        title='Home',
        form=form,
        todo_items=todo_items,
        todos=todos,
        get_time_elapse=helpers.get_time_elapse,
        done_count=done_count,
        undone_count=undone_count,
        failed_count=failed_count,
        is_greater_than_24_hours=helpers.is_greater_than_24_hours)
Exemple #14
0
    def test_set_task_from_scratch(self):
        test_str = "(B) 2012-08-27"
        test_item = TodoItem(test_str)
        self.assertIsNone(test_item.task)
        test_item.task = "foo bar"
        self.assertIsNotNone(test_item.task)
        self.assertEquals("foo bar", test_item.task)
        self.assertEquals(test_str + " " + "foo bar", test_item.todo_txt_line)

        test_str = "(B)"
        test_item = TodoItem(test_str)
        test_item.task = "foo bar"
        self.assertIsNotNone(test_item.task)
        self.assertEquals("foo bar", test_item.task)
        self.assertEquals(test_str + " " + "foo bar", test_item.todo_txt_line)
Exemple #15
0
def test_show_all_done_items_returns_true_for_small_numbers_of_items():
    # Arrange
    items = [
        TodoItem(1, "Started Todo", "Not Started", ""),
        TodoItem(2, "Doing Todo", "In Progress", ""),
        TodoItem(3, "Done Todo", "Completed", ""),
    ]

    vader = ViewModel(items)

    # Act
    result = vader.show_all_done_items

    # Assert
    assert result == True
Exemple #16
0
def main():
    todo = Todo()
    while True:
        print("How can I help you?\n")
        print("1.Add task\n"
              "2.List tasks\n"
              "3.Toggle done\n"
              "4.Remove task\n"
              "0.Exit\n")
        number = input("\nPlease select number: ")
        if number == "1":
            item = TodoItem(input("\nPlease add a task: "))
            todo.add_item(item)
            print("\nTask added.")
        elif number == "2":
            print("\nItems list: ")
            todo.list_items()
        elif number == "3":
            todo.list_items()
            done = input("\nChoose a number for task which is done?: ")
            todo.items[int(done) - 1].toggle_done()
            todo.list_items()
        elif number == "4":
            todo.list_items()
            remove = input("\nChoose a number for task to remove: ")
            removed = int(remove) - 1
            todo.remove_item(removed)
            todo.list_items()
        elif number == "0":
            print("\nGoodbye!")
        else:
            print("Please choose a valid option.")
Exemple #17
0
    def read_from_file(self):
        """
        Read items from file and append all items to todo items list
        """
        name_index = 0
        description_index = 1
        deadline_index = 2
        is_done_index = 3
        year_index = 0
        month_index = 1
        day_index = 2

        with open('data.csv', 'r') as csvfile:
            reader = csv.reader(csvfile)
            for row in reader:
                if row[deadline_index] != 'None':
                    date = row[deadline_index].split('-')
                    date = datetime.date(int(date[year_index]),
                                         int(date[month_index]),
                                         int(date[day_index]))
                else:
                    date = None
                self.todo_items.append(
                    TodoItem(row[name_index], row[description_index], date,
                             True if row[is_done_index] == 'True' else False))
Exemple #18
0
def test_filters_by_status(
):  # first test to see if view model item matches each status
    created_todo = TodoItem(1, "Test in progress Todo", "To Do",
                            datetime.now())
    pending_todo = TodoItem(2, "Test Pending Todo", "Pending", datetime.now())
    done_todo = TodoItem(3, "Test Done Todo", "Done", datetime.now())

    todos = [created_todo, pending_todo, done_todo]

    # added as part of module 10 project
    reader = "ReadOnly"

    view_model = ViewModel(todos, reader)

    assert view_model.to_do_items == [created_todo]
    assert view_model.doing_items == [pending_todo]
    assert view_model.done_items == [done_todo]
Exemple #19
0
 def test_constructor(self):
     date = datetime(2017, 6, 4)
     item = TodoItem('implement ToDoItem class', date)
     self.assertEqual(item.title, 'implement ToDoItem class',
                      "Wrong todo_item")
     self.assertEqual(item.deadline, date, 'Wrong deadline')
     self.assertEqual(item.is_done, False, 'dupa')
     self.assertIsInstance
Exemple #20
0
def test_done():

    items = (
        TodoItem(1, "Started Todo", "Not Started", ""),
        TodoItem(2, "Doing Todo", "In Progress", ""),
        TodoItem(3, "Done Todo", "Completed", ""),
    )
    storm = ViewModel(items)

    done_items = storm.done

    assert len(done_items) == 1

    done_item = done_items[0]

    assert done_item.status == "Completed"
    assert done_item.id == 3
Exemple #21
0
 def add_item(self, name, description, deadline):
     """
     Add item to todo items list
     :param name: string -> name of the todo item
     :param description: string -> description of the todo item
     :param deadline: Datetime -> deadline of the todo item
     """
     self.todo_items.append(TodoItem(name, description, deadline))
Exemple #22
0
def show_all(): 
    tasks=[]
    for db_object in db.to_do.find():

        tasks.append(TodoItem.from_mongodb_object(db_object))

    item_view_model = ViewModel(tasks)
    return render_template('index2.html', view_model=item_view_model)
Exemple #23
0
    def add_item(self):
        '''
        Add an item to the TODO store
        '''

        # print(self.priority.get())
        # print(self.due.get())
        # print(self.description.get("1.0", END))
        print(self.completed.get())
        item = TodoItem(self.description.get("1.0", END), self.completed.get(),
                        self.priority.get(), self.due.get())
        self.store.addItem(item)

        displayBox = Checkbutton(self.master,
                                 text=item.itemToString(),
                                 onvalue="complete",
                                 offvalue="incomplete")
        displayBox.pack(side="bottom")
    def add_item(self, title, deadline):

        if not isinstance(deadline, date):
            raise ValueError('Deadline should be datetime object')

        else:
            self.todo_items.append(TodoItem(title, deadline))

        self.sort_items()
Exemple #25
0
 def modify_item(self, index, name, description, deadline):
     """
     Modify item by index
     :param index: int -> index of item we want to modify
     :param name: string -> name of the todo item
     :param description: string -> description of the todo item
     :param deadline: Datetime -> deadline of the todo item
     """
     self.todo_items[index] = TodoItem(name, description, deadline)
Exemple #26
0
def test_doing():
    # Arrange
    items = [
        TodoItem(1, "Started Todo", "Not Started", ""),
        TodoItem(2, "Doing Todo", "In Progress", ""),
        TodoItem(3, "Done Todo", "Completed", ""),
    ]

    vader = ViewModel(items)

    # Act
    doing_items = vader.doing

    # Assert
    assert len(doing_items) == 1

    doing_item = doing_items[0]

    assert doing_item.status == "In Progress"
    assert doing_item.id == 2
Exemple #27
0
def test_show_all_done_items_today():

    today = arrow.utcnow().floor('day').format('YYYY-MM-DD')

    items = (TodoItem(1, "Started Todo", "Not Started",
                      today), TodoItem(2, "Doing Todo", "In Progress", today),
             TodoItem(3, "Done Todo", "Completed", today),
             TodoItem(4, "Done Todo", "Completed", "2021-04-06"))
    egg = ViewModel(items)

    # Act
    result = egg.show_all_done_items_today

    # Assert
    assert len(result) == 1

    done_item = result[0]

    assert done_item.status == "Completed"
    assert done_item.id == 3
Exemple #28
0
def test_to_do():
    # Passing through blank value for the Date Input as not required for this test
    items = [
        TodoItem(1, "Started Todo", "Not Started", ""),
        TodoItem(2, "Doing Todo", "In Progress", ""),
        TodoItem(3, "Done Todo", "Completed", ""),
    ]

    frank = ViewModel(items)

    # Act
    # [TodoItem(1, "Started Todo", "Not Started")]
    todo_items = frank.to_do

    # Assert
    assert len(todo_items) == 1

    todo_item = todo_items[0]

    assert todo_item.status == "Not Started"
    def add_item(self, title, deadline):
        '''
        Method adds new Item object with attributes title and deadline to list.

        Args:
            title - string
            deadline - datetime object

        Returns:
           None
        '''

        self.todo_items.append(TodoItem(title, deadline))
        self.sort_items()
Exemple #30
0
def my_app():
    form = ExampleForm()
    if form.field1.data != None:
        title = form.field1.data
        todo_item = TodoItem(title, False, datetime.datetime.now())
        create_todo(todo_item)
        print(form.field1.data)
    else:
        form.field1.description = ''
    global ButtonPressed
    ButtonPressed += 1
    """
        create() : Add document to Firestore collection with request body
        Ensure you pass a custom ID as part of json body in post request
        e.g. json={'id': '1', 'title': 'Write a blog post'}
    """

    #get all todos from database
    print('before the for loop')
    todos.clear()
    for todo in query_db('select * from todos'):
        print(todo)
        todo_items[todo[1]] = False
        if todo[2] != '':
            temp_todo = TodoItem(
                todo[1], True if todo[3] == 1 else False,
                datetime.datetime.strptime(todo[2], "%m/%d/%Y, %H:%M:%S"))
            print(temp_todo.is_done)
            todos.append(temp_todo)

    form.field1.data = ""
    return render_template('home.html',
                           ButtonPressed=ButtonPressed,
                           form=form,
                           todo_items=todo_items,
                           todos=todos,
                           get_time_elapse=helpers.get_time_elapse)
Exemple #31
0
def read_todo_list():
    try:
        with open(filename, 'r') as todo_file:
            todo_list = todo_file.readlines()
    except FileNotFoundError:
        return []
    except EnvironmentError as err:
        print(str(err))
    else:
        try:
            return [TodoItem.deserialize(item) for item in todo_list]
        except ValueError:
            print(
                'Your .todo file seems to be broken. Check it for syntax errors.'
            )
            exit(1)
Exemple #32
0
 def save(self):
     self.set_status("Adding new item: ")
     new_item = TodoItem()
     new_item.priority = self.new_priority.get()
     if new_item.priority == "":
         new_item.priority = None
     new_item.context = self.new_context.get()
     if new_item.context == "" or new_item.context == "None":
         new_item.context = None
     new_item.task = self.new_task.get()
     new_item.creation_date = self.new_date.get()
     if new_item.creation_date == "":
         new_item.creation_date = None
     self.set_status("Adding new item: " + str(new_item))
     self.active_td_file().append(new_item)
     self.set_status(
         "Adding new item: " + str(new_item) + " ... save complete")
     self.reset_ui()
    def add_item(self, title, deadline):
        """
        Method adds new object of TodoItem class into todo_items attribute list

        Args:
            title (str): name of the item
            deadline (obj): object of datetime class

        Returns:
            None
        """

        if type(deadline) is not datetime:
            raise TypeError

        self.todo_items.append(TodoItem(title, deadline))
        self.sort_items()
Exemple #34
0
 def add_task(self, event):
     self.add_win = tk.Toplevel(takefocus=True)
     self.add_win.title = "Add a new to do"
     self.add_attr(self.add_win, "Task: ", self.new_task, 1).focus()
     self.add_attr(self.add_win, "Pri: ", self.new_priority, 2)
     self.add_attr(self.add_win, "Context: ", self.new_context, 3)
     self.add_attr(self.add_win, "Creation Date: ", self.new_date, 4)
     button_frame = tk.Frame(self.add_win)
     button_frame.grid(row=5, columnspan=2, column=2)
     tk.Button(button_frame, text="Close", command=lambda:
               self.add_win.destroy()).pack(side=tk.LEFT)
     tk.Button(button_frame, text="Add this task",
               command=lambda: self.save()).pack(side=tk.LEFT)
     tk.Button(button_frame, text="Add and close",
               command=lambda: self.commit_close()).pack(side=tk.LEFT)
     self.new_date.set(TodoItem.curr_date_str())
     self.add_win.focus_set()
     self.add_win.bind("<Return>", lambda event: self.commit_close())
     self.add_win.bind("<Escape>", lambda event: self.add_win.destroy())
Exemple #35
0
    def getAll():

        #myclient = pymongo.MongoClient('mongodb+srv://%s:%[email protected]/ToDo?retryWrites=true&w=majority' % (MONGO_LOGIN, MONGO_PASS))
        #mydb = myclient["ToDo"]
        #mycollection = mydb["All Items"]
        myclient = pymongo.MongoClient(
            'mongodb://%s:%[email protected]:10255/DefaultDatabase?ssl=true&retrywrites=false&replicaSet=globaldb&maxIdleTimeMS=120000&appName=@module11-cosmos-serverless@'
            % (MONGO_LOGIN, MONGO_PASS))
        mydb = myclient["ToDo"]
        mycollection = mydb["All Items"]

        todo_resp = mycollection.find(
        )  # find method returns a cursor instance for iteration

        todo_list = [TodoItem.from_mongo_card(card)
                     for card in todo_resp]  ## returns list of dict

        # user authorization
        user_authorizaion = User(current_user.get_id())
        reader = user_authorizaion.get_role() == Role.Reader

        return render_template('all_items.html',
                               todos=ViewModel(todo_list, reader))
Exemple #36
0
def item_view():
    reader = "ReadOnly"

    created_todo = TodoItem(1, "Test in progress Todo", "To Do", date.today())
    created_todo2 = TodoItem(2, "Test in progress Todo", "To Do", date.today())
    created_todo3 = TodoItem(3, "Test in progress Todo", "To Do", date.today())
    pending_todo = TodoItem(4, "Test Pending Todo", "Pending", date.today())
    pending_todo2 = TodoItem(5, "Test Pending Todo", "Pending", date.today())
    done_todo = TodoItem(6, "You're not done", "Done",
                         date.today() - timedelta(days=2))
    done_todo2 = TodoItem(7, "Are you sure you're done", "Done",
                          date.today() - timedelta(days=3))
    done_todo3 = TodoItem(8, "Are you sure you're done1", "Done",
                          date.today() - timedelta(days=4))
    done_todo4 = TodoItem(9, "Are you sure you're done2", "Done",
                          date.today() - timedelta(days=5))
    done_todo5 = TodoItem(10, "Are you sure you're done3", "Done",
                          date.today())
    done_todo6 = TodoItem(11, "Are you sure you're done4", "Done",
                          date.today())

    todos = [
        created_todo, created_todo2, created_todo3, pending_todo,
        pending_todo2, done_todo, done_todo2, done_todo3, done_todo4,
        done_todo5, done_todo6
    ]

    return ViewModel(todos, reader)
Exemple #37
0
 def test_str(self):
     date = datetime(2017, 6, 4)
     item = TodoItem('implement TodoItem class', date)
     self.assertIsInstance(item.__str__(), str)
 def add_item(self, title, deadline):
     self.todo_items.append(TodoItem(title, deadline))
     TodoQuarter.sort_items(self)
Exemple #39
0
from todo_store import TodoStore
from todo_item import TodoItem

mainStore = TodoStore()

command = input("What would you like to do? ")

while command != "quit":
    if command == "add":
        priority = input("Priority: ")
        description = input("Description: ")
        isDue = input("Is it due (True/False): ")

        if isDue == "True":
            due = input("Due date: ")

        item = TodoItem(description, priority=priority, isDue=isDue)
        mainStore.addItem(item)
    elif command == "complete":
        itemNum = input("Enter item number: ")

        mainStore.completeItem(itemNum)
    elif command == "export":
        mainStore.exportList()
    elif command == "total":
        print(f"Number of items: {mainStore.getNumItems()}")

    command = input("What would you like to do? ")

exit(0)
Exemple #40
0
from flask_materialize import Material
from flask_wtf import Form, RecaptchaField
from flask_wtf.file import FileField
from wtforms import TextField, HiddenField, ValidationError, RadioField,\
    BooleanField, SubmitField, IntegerField, FormField, validators, DateField, SelectField
from wtforms.validators import Required
import helpers

THIS_FOLDER = os.path.dirname(os.path.abspath(__file__))
key_json_file_path = os.path.join(THIS_FOLDER, 'key.json')
DATABASE = os.path.join(THIS_FOLDER, 'database.db')

#mock data
todo_items = {'todo1': True, 'todo222': False, 'just simple to do': True}
todos = [
    TodoItem('This is a mock todo that has not been completed yet', False,
             datetime.datetime.now())
]


# straight from the wtforms docs:
class TelephoneForm(Form):
    country_code = IntegerField('Country Code', [validators.required()])
    area_code = IntegerField('Area Code/Exchange', [validators.required()])
    number = TextField('Number')


class ExampleForm(Form):
    field1 = TextField('Title', description='')

    submit_button = SubmitField('Create')
Exemple #41
0
                print('\t' + str(item))


if no_arguments_are_passed():
    todo_list = read_todo_list()
    if not todo_list:
        if not args.silent:
            print('Nothing to do here...\n'
                  'type \'todo something\' to add a todo or\n'
                  'type \'todo -h\' for usage info.')
    else:
        show_todo_list(todo_list)

if args.new_item:
    new_content = ' '.join(args.new_item)
    new_item = TodoItem(new_content)
    todo_list = read_todo_list()
    not_done_items = [item for item in todo_list if item.status == 'todo']
    for item in not_done_items:
        if item.content == new_item.content:
            print('This item already exists:\n' + '\t' + str(item))
            exit(0)
    try:
        with open(filename, 'a') as todo_file:
            todo_file.write(new_item.serialize() + '\n')
    except EnvironmentError as err:
        print(str(err))
    else:
        print('You have one more thing to do: \n' + '\t' + str(new_item))

if args.done_item:
Exemple #42
0
 def test_str3(self):
     date = datetime(2017, 6, 4)
     item = TodoItem('implement TodoItem class', date)
     item.mark()
     test_string = item.__str__()
     self.assertEqual(test_string[1], 'x', 'Wrong sign')