def __init__(self, database=None, host=None, port=None, expose=None): self.things3 = Things3(database=database) cfg = self.things3.get_from_config(host, 'KANBANVIEW_HOST') self.host = cfg if cfg else self.host self.things3.set_config('KANBANVIEW_HOST', self.host) cfg = self.things3.get_from_config(port, 'KANBANVIEW_PORT') self.port = cfg if cfg else self.port self.things3.set_config('KANBANVIEW_PORT', self.port) cfg = self.things3.get_from_config(expose, 'API_EXPOSE') self.host = '0.0.0.0' if (str(cfg).lower() == 'true') else 'localhost' self.things3.set_config('KANBANVIEW_HOST', self.host) self.things3.set_config('API_EXPOSE', str(cfg).lower() == 'true') self.flask = Flask(__name__) self.flask.add_url_rule('/config/<key>', view_func=self.config_get) self.flask.add_url_rule('/config/<key>', view_func=self.config_set, methods=["PUT"]) self.flask.add_url_rule('/api/<command>', view_func=self.api) self.flask.add_url_rule('/api/url', view_func=self.get_url) self.flask.add_url_rule('/api/tag/<tag>', view_func=self.tag) self.flask.add_url_rule('/api/tag/<tag>/<area>', view_func=self.tag) self.flask.add_url_rule('/api/filter/<mode>/<uuid>', view_func=self.api_filter) self.flask.add_url_rule('/api/filter/reset', view_func=self.api_filter_reset) self.flask.add_url_rule('/<url>', view_func=self.on_get) self.flask.add_url_rule('/', view_func=self.on_get) self.flask.app_context().push() self.flask_context = None
def setUp(self): self.things3 = Things3(database="resources/demo.sqlite3") self.things3.tag_mit = "😀" self.things3.tag_waiting = "Waiting" self.things3.tag_cleanup = "Cleanup" self.things3.tag_seinfeld = "Seinfeld" self.things3.tag_a = "A" self.things3.tag_b = "B" self.things3.tag_c = "C" self.things3.tag_d = "D" self.things3.stat_days = 365
class Things3CLICase(unittest.TestCase): """Class documentation goes here.""" things3 = Things3(database='tests/Things.sqlite3') def test_today(self): """Test Today.""" args = things3_cli.get_parser().parse_args(['today']) new_out = io.StringIO() old_out = sys.stdout try: sys.stdout = new_out things3_cli.main(args, self.things3) finally: sys.stdout = old_out self.assertIn("Today Todo", new_out.getvalue())
class Things3KanbanCase(unittest.TestCase): """Class documentation goes here.""" things3 = Things3(database='resources/demo.sqlite3') class CustomStringIO(io.StringIO): """Do not close output for testing.""" def close(self): pass def test_today(self): """Test Today.""" output = self.CustomStringIO() things3_kanban.THINGS3 = self.things3 things3_kanban.main(output) self.assertIn("Today MIT", output.getvalue())
class Things3APICase(unittest.TestCase): """Class documentation goes here.""" things3_api.THINGS3 = Things3(database='tests/Things.sqlite3') def test_today(self): """Test Today.""" result = things3_api.api("today").response self.assertEqual(1, len(result)) def test_get_file(self): """Test get file.""" result = things3_api.on_get("/kanban.html").response[0].decode("utf-8") self.assertIn("footer", result)
def main(args=None, things3=Things3()): """ Main entry point of the app """ if args is None: main(get_parser().parse_args()) else: things_cli = Things3CLI(args, things3) command = args.command if command in things3.functions: func = things3.functions[command] things_cli.print_tasks(func(things3)) elif command == "csv": print("Deprecated: use --csv instead") elif command == "feedback": webbrowser.open( 'https://github.com/AlexanderWillner/KanbanView/issues') else: Things3CLI.print_unimplemented()
def __init__(self, database=None, host=None, port=None, expose=None, debug_text=""): # pylint: disable-msg=too-many-arguments self.things3 = Things3(database=database, debug_text=debug_text) cfg = self.things3.get_from_config(host, "KANBANVIEW_HOST") self.host = cfg if cfg else self.host self.things3.set_config("KANBANVIEW_HOST", self.host) cfg = self.things3.get_from_config(port, "KANBANVIEW_PORT") self.port = cfg if cfg else self.port self.things3.set_config("KANBANVIEW_PORT", self.port) cfg = self.things3.get_from_config(expose, "API_EXPOSE") self.host = "0.0.0.0" if (str(cfg).lower() == "true") else "localhost" self.things3.set_config("KANBANVIEW_HOST", self.host) self.things3.set_config("API_EXPOSE", str(cfg).lower() == "true") self.flask = Flask(__name__) self.flask.add_url_rule("/config/<key>", view_func=self.config_get) self.flask.add_url_rule("/config/<key>", view_func=self.config_set, methods=["PUT"]) self.flask.add_url_rule("/api/<command>", view_func=self.api) self.flask.add_url_rule("/api/<command>", view_func=self.api, methods=["PUT"]) self.flask.add_url_rule("/api/url", view_func=self.get_url) self.flask.add_url_rule("/api/seinfeld/<tag>", view_func=self.seinfeld) self.flask.add_url_rule("/api/tag/<tag>", view_func=self.tag) self.flask.add_url_rule("/api/tag/<tag>/<area>", view_func=self.tag) self.flask.add_url_rule("/api/filter/<mode>/<uuid>", view_func=self.api_filter) self.flask.add_url_rule("/api/filter/reset", view_func=self.api_filter_reset) self.flask.add_url_rule("/<url>", view_func=self.on_get) self.flask.add_url_rule("/", view_func=self.on_get) self.flask.app_context().push() self.flask_context = None
ctx = Context() mod = Module() apps = mod.apps apps.things3 = """ app.name: Things """ ctx.matches = r""" app: things3 """ mod.list("things_tag", desc="Tags in Things") mod.list("things_tag_with_shortcut", desc="Tags in Things within an assigned shortcut") mod.list("things_project", desc="Areas and projects in Things") things = Things3() @dataclass class Tag: uuid: str title: str shortcut: Optional[str] @dataclass class Project: uuid: str title: str
class Things3Case(unittest.TestCase): """Class documentation goes here.""" things3 = Things3(database='tests/Things.sqlite3') def test_today(self): """Test Today.""" tasks = self.things3.get_today() self.assertEqual(1, len(tasks), "foo") def test_inbox(self): """Test Inbox.""" tasks = self.things3.get_inbox() self.assertEqual(1, len(tasks)) def test_next(self): """Test Next.""" tasks = self.things3.get_anytime() self.assertEqual(4, len(tasks)) def test_backlog(self): """Test Backlog.""" tasks = self.things3.get_someday() self.assertEqual(1, len(tasks)) def test_upcoming(self): """Test Upcoming.""" tasks = self.things3.get_upcoming() self.assertEqual(3, len(tasks)) def test_waiting(self): """Test Waiting.""" tasks = self.things3.get_waiting() self.assertEqual(1, len(tasks)) def test_mit(self): """Test MIT.""" tasks = self.things3.get_mit() self.assertEqual(0, len(tasks)) def test_completed(self): """Test completed tasks.""" tasks = self.things3.get_completed() self.assertEqual(1, len(tasks)) def test_cancelled(self): """Test cancelled tasks.""" tasks = self.things3.get_cancelled() self.assertEqual(1, len(tasks)) def test_trashed(self): """Test trashed tasks.""" tasks = self.things3.get_trashed() self.assertEqual(3, len(tasks)) def test_all(self): """Test all tasks.""" tasks = self.things3.get_all() self.assertEqual(13, len(tasks)) def test_due(self): """Test due tasks.""" tasks = self.things3.get_due() self.assertEqual(1, len(tasks)) def test_anonymize(self): """Test anonymized tasks.""" tasks = self.things3.get_today() self.assertIn("Today Todo", tasks.pop()) self.things3.anonymize = True tasks = self.things3.get_today() self.assertNotIn("Today Todo", tasks.pop())
def __init__(self, database=None): self.things3 = Things3(database)
def setUp(self): self.things3 = Things3(database='resources/demo.sqlite3') self.things3.tag_mit = 'MIT'
__author__ = "Alexander Willner" __copyright__ = "Copyright 2020 Alexander Willner" __credits__ = ["Luc Beaulieu", "Alexander Willner"] __license__ = "Apache License 2.0" __version__ = "2.6.2" __maintainer__ = "Alexander Willner" __email__ = "*****@*****.**" __status__ = "Development" import codecs from os import getcwd from things3.things3 import Things3 # Basic variables FILE_HTML = getcwd() + '/kanban-static.html' THINGS3 = Things3() TARGET = codecs.open(FILE_HTML, 'w', 'utf-8') def write_html_column(cssclass, file, header, rows): """Create a column in the output.""" file.write("<div class='column'><div class=''>" + "<h2 class='h2 " + cssclass + "'>" + header + "<span class='size'>" + str(len(rows)) + "</span></h2>") for row in rows: task_uuid = str(row['uuid']) \ if row['uuid'] is not None else '' task_title = str(row['title']) \ if row['title'] is not None else ''