def test_adding_two_tasks_in_two_todo_and_checking_if_output_matches_expected( self, mock_input): formatter = Format() todo = ToDoList(formatter) todo.add_task() todo1 = ToDoList(formatter) todo1.add_task() with patch('sys.stdout', new=StringIO()) as fake_out: todo.view_tasks() self.assertEqual("Incomplete Tasks:\n\n1. Meet Ema at 7\n", fake_out.getvalue())
class Schedule: tdl = None taskList = [] timer = None def __init__(self, fname): self.tdl = ToDoList(fname) self.taskList = self.tdl.getTaskList() random.shuffle(self.taskList) self.timer = Timer() def rereadTDL(self): currentTask = self.getCurrentTask() self.tdl.readTDL() self.taskList = self.tdl.getTaskList() random.shuffle(self.taskList) if currentTask in self.taskList: self.taskList.remove(currentTask) self.taskList.append(currentTask) self.taskList.reverse() else: self.timer.reset() def getCurrentTask(self): if len(self.taskList)==0: return None idx = (int(self.timer.getElapsed())/3600)%len(self.taskList) return self.taskList[idx] def getTimeRemaining(self): return int((3600-self.timer.getElapsed()%3600)/60) def markDone(self): if len(self.taskList)==0: return idx = int(self.timer.getElapsed()/3600)%len(self.taskList) self.taskList.pop(idx) def pauseTimer(self): self.timer.pause() def isPaused(self): return self.timer.paused def shuffle(self): random.shuffle(self.taskList)
def test_adding_task_and_editing_there_itself(self, mock_input): formatter = Format() todo = ToDoList(formatter) todo.add_task() with patch('sys.stdout', new=StringIO()) as fake_out: todo.view_tasks() self.assertEqual("Incomplete Tasks:\n\n1. Meet Ema at 7:00\n", fake_out.getvalue()) todo.edit_task() with patch('sys.stdout', new=StringIO()) as fake_out: todo.view_tasks() self.assertEqual("Incomplete Tasks:\n\n1. Meet Ema at 8:00\n", fake_out.getvalue())
def test_when_saving_empty_tasks_in_a_file(self, mock_input): formatter = Format() todo = ToDoList(formatter) todo.save_task() with patch('sys.stdout', new=StringIO()) as fake_out: with open("MyTasks.txt", "r") as file: content = file.readlines() all_tasks = "" for _ in content: all_tasks += _ self.assertEqual("Your TODO list is empty!", all_tasks) clear_saved_files = SaveListsToFiles() clear_saved_files.clear()
def test_the_list_order_is_retained_when_a_task_from_middle_is_marked_as_complete( self, mock_input): formatter = Format() todo = ToDoList(formatter) todo.add_task() todo.add_task() todo.add_task() todo.add_task() todo.mark_completed() with patch('sys.stdout', new=StringIO()) as fake_out: todo.view_tasks() self.assertEqual( "Incomplete Tasks:\n\n1. Have Lunch at 1:00pm\n2. Do your assignments\n3. Sleep\n\nComplete Tasks:\n\n1. Meet Ema at 7:00\n", fake_out.getvalue())
def __init__(self, fname): self.tdl = ToDoList(fname) self.taskList = self.tdl.getTaskList() random.shuffle(self.taskList) self.timer = Timer()
def test_when_incomplete_list_is_empty_and_completed_list_has_elements( self, mock_list_type): formatter = Format() todo = ToDoList(formatter) todo.add_task() todo.mark_completed() with patch('sys.stdout', new=StringIO()) as fake_out: todo.view_tasks() self.assertEqual("Complete Tasks:\n\n1. Meet Rishabh\n", fake_out.getvalue())
def test_when_TODO_list_is_not_empty_and_list_type_is_given_then_one_task_to_delete( self, mock_list_type): formatter = Format() todo = ToDoList(formatter) todo.add_task() todo.mark_completed() with patch('sys.stdout', new=StringIO()) as fake_out: todo.delete_task() self.assertEqual("Your task has been deleted successfully\n", fake_out.getvalue())
def test_marking_a_task_as_complete_moves_it_to_the_complete_list( self, mock_input): formatter = Format() todo = ToDoList(formatter) todo.add_task() todo.add_task() todo.mark_completed() with patch('sys.stdout', new=StringIO()) as fake_out: todo.view_tasks() self.assertEqual( "Incomplete Tasks:\n\n1. Have Lunch at 1:00pm\n\nComplete Tasks:\n\n1. Meet Ema at 7:00\n", fake_out.getvalue())
def test_when_the_task_number_is_negative_it_can_not_be_marked_as_completed( self, mock_input): formatter = Format() todo = ToDoList(formatter) todo.add_task() todo.add_task() todo.add_task() todo.add_task() with patch('sys.stdout', new=StringIO()) as fake_out: todo.mark_completed() self.assertEqual( "Incomplete Tasks:\n\n1. Have Lunch at 1:00pm\n2. Meet Ema at 7:00\n3. Do your assignments\n4. Sleep\nThe task you're trying to mark is not present in the list\n", fake_out.getvalue())
def test_when_saving_tasks_in_a_file(self, mock_input): formatter = Format() todo = ToDoList(formatter) todo.add_task() todo.add_task() todo.add_task() todo.save_task() with patch('sys.stdout', new=StringIO()) as fake_out: with open("MyTasks.txt", "r") as file: content = file.readlines() all_tasks = "" for _ in content: all_tasks += _ self.assertEqual( "Incomplete Tasks:\n\n1. Have Lunch at 1:00pm\n2. Send Email at 3:00\n3. Meeting at 4:00", all_tasks)
def test_empty_todo_list(self): formatter = Format() todo = ToDoList(formatter) with patch('sys.stdout', new=StringIO()) as fake_out: todo.view_tasks() self.assertEqual("Your TODO list is empty!\n", fake_out.getvalue())
from ToDoList import ToDoList from ListTable import ListTable import sqlite3 from datetime import date, timedelta import flask from flask import jsonify, request, redirect, url_for from flask_cors import CORS app = flask.Flask(__name__) app.config["DEBUG"] CORS(app) # conn = sqlite3.connect("hadobit_db.db") # conn.row_factory = sqlite3.Row todolist = ToDoList() # c = conn.cursor() @app.route("/todo", methods=["GET", "POST"]) def home(): try: if request.method == "POST": # todolist.append_row(str(date.today()), "test", # "test post request", "False") data = request.get_json() todolist.add_task_today(data['task']) # print(data['task']) return "< h1 > row appended < /h1 >" else: list_to_json = []
def test_adding_no_task(self, mock_input): formatter = Format() todo = ToDoList(formatter) with patch('sys.stdout', new=StringIO()) as fake_out: todo.add_task() self.assertEqual("Empty Task\n", fake_out.getvalue())
from Format import Format from ToDoList import ToDoList formatter = Format() todo = ToDoList(formatter) options = """ \n 0. Exit 1. Add task 2. View task 3. Edit task 4. Mark a task as complete 5. Save list to file """ def invalid(): print("Invalid option") def task_options(i): switcher = { 0: exit, 1: todo.add_task, 2: todo.view_tasks, 3: todo.edit_task, 4: todo.mark_completed, 5: todo.save_task, } return switcher.get(i, invalid)()
def test_the_todo_list_persists_after_each_session(self, mock_input): formatter = Format() todo = ToDoList(formatter) todo.add_task() todo_another_one = ToDoList(formatter) self.assertEqual(todo.view_tasks(), todo_another_one.view_tasks())
import sys from PyQt5.QtWidgets import QApplication from ToDoList import ToDoList if __name__ == '__main__': app = QApplication(sys.argv) ex = ToDoList() sys.exit(app.exec_())
def test_when_TODO_list_is_empty_then_to_mark_a_task_as_complete_is_not_allowed( self): todo = ToDoList(console_format) with patch('sys.stdout', new=StringIO()) as fake_out: todo.mark_completed(1) self.assertEqual("\nYour TODO list is empty!", fake_out.getvalue())
def get_todo_list_with(tasks): todo = ToDoList(console_format) for task in tasks: todo.add_task(task) return todo
def test_when_TODO_list_is_empty_mark_as_complete_is_not_allowed(self): formatter = Format() todo = ToDoList(formatter) with patch('sys.stdout', new=StringIO()) as fake_out: todo.mark_completed() self.assertEqual("Your TODO list is empty!\n", fake_out.getvalue())
def test_viewing_empty_task(self): todo = ToDoList(console_format) with patch('sys.stdout', new=StringIO()) as fake_output: todo.write_tasks(sys.stdout) self.assertEqual("Your TODO list is empty!", fake_output.getvalue())
def test_when_TODO_list_is_empty_then_no_task_to_delete(self): formatter = Format() todo = ToDoList(formatter) with patch('sys.stdout', new=StringIO()) as fake_out: todo.delete_task() self.assertEqual("Your Todo List is empty\n", fake_out.getvalue())