def setUp(self): """ Creates the environment for the tests @returns: None """ self.datastore = DataStore() self.requester = self.datastore.get_requester()
def setUp(self): thread_tomboy = threading.Thread(target=self.spawn_fake_tomboy_server) thread_tomboy.start() thread_tomboy.join() # only the test process should go further, the dbus server one should # stop here if not PID_TOMBOY: return # we create a custom dictionary listening to the server, and register # it in GTG. additional_dic = {} additional_dic["use this fake connection instead"] = ( FakeTomboy.BUS_NAME, FakeTomboy.BUS_PATH, FakeTomboy.BUS_INTERFACE) additional_dic[GenericBackend.KEY_ATTACHED_TAGS] = \ [GenericBackend.ALLTASKS_TAG] additional_dic[GenericBackend.KEY_DEFAULT_BACKEND] = True dic = BackendFactory().get_new_backend_dict('backend_tomboy', additional_dic) self.datastore = DataStore() self.backend = self.datastore.register_backend(dic) # waiting for the "start_get_tasks" to settle time.sleep(1) # we create a dbus session to speak with the server self.bus = dbus.SessionBus() obj = self.bus.get_object(FakeTomboy.BUS_NAME, FakeTomboy.BUS_PATH) self.tomboy = dbus.Interface(obj, FakeTomboy.BUS_INTERFACE)
def setUp(self): ds = DataStore() self.req = ds.get_requester() # initalize gobject signaling system self.gobject_signal_manager = GobjectSignalsManager() self.gobject_signal_manager.init_signals() # refresh the viewtree for tasks tt = self.req.get_tasks_tree() tt.reset_filters()
def _setup_backend(): datastore = DataStore() parameters = { 'pid': 'favorite', 'service-url': 'color', 'username': '******', 'password': '******', 'period': 1 } backend = Backend(parameters) datastore.register_backend({ 'backend': backend, 'pid': 'backendid', 'first_run': True }) return datastore, backend
def do_startup(self): """Callback when primary instance should initialize""" Gtk.Application.do_startup(self) # Register backends datastore = DataStore() for backend_dic in BackendFactory().get_saved_backends_list(): datastore.register_backend(backend_dic) # Save the backends directly to be sure projects.xml is written datastore.save(quit=False) self.req = datastore.get_requester() self.config = self.req.get_config("browser") self.config_plugins = self.req.get_config("plugins") self.clipboard = clipboard.TaskClipboard(self.req) self.timer = Timer(self.config) self.timer.connect('refresh', self.autoclean) self.preferences_dialog = Preferences(self.req, self) self.plugins_dialog = PluginsDialog(self.req) if self.config.get('dark_mode'): self.toggle_darkmode() self.init_style()
def core_main_init(options=None, args=None): ''' Part of the main function prior to the UI initialization. ''' # Debugging subsystem initialization if options.debug: Log.setLevel(logging.DEBUG) Log.debug("Debug output enabled.") else: Log.setLevel(logging.INFO) Log.set_debugging_mode(options.debug) config = CoreConfig() check_instance(config.get_data_dir(), args) backends_list = BackendFactory().get_saved_backends_list() # Load data store ds = DataStore(config) # Register backends for backend_dic in backends_list: ds.register_backend(backend_dic) # save the backends directly to be sure projects.xml is written ds.save(quit=False) # Launch task browser req = ds.get_requester() return ds, req
class TestBackendTomboy(unittest.TestCase): """ Tests for the tomboy backend """ def setUp(self): thread_tomboy = threading.Thread(target=self.spawn_fake_tomboy_server) thread_tomboy.start() thread_tomboy.join() # only the test process should go further, the dbus server one should # stop here if not PID_TOMBOY: return # we create a custom dictionary listening to the server, and register # it in GTG. additional_dic = {} additional_dic["use this fake connection instead"] = ( FakeTomboy.BUS_NAME, FakeTomboy.BUS_PATH, FakeTomboy.BUS_INTERFACE) additional_dic[GenericBackend.KEY_ATTACHED_TAGS] = \ [GenericBackend.ALLTASKS_TAG] additional_dic[GenericBackend.KEY_DEFAULT_BACKEND] = True dic = BackendFactory().get_new_backend_dict('backend_tomboy', additional_dic) self.datastore = DataStore() self.backend = self.datastore.register_backend(dic) # waiting for the "start_get_tasks" to settle time.sleep(1) # we create a dbus session to speak with the server self.bus = dbus.SessionBus() obj = self.bus.get_object(FakeTomboy.BUS_NAME, FakeTomboy.BUS_PATH) self.tomboy = dbus.Interface(obj, FakeTomboy.BUS_INTERFACE) def spawn_fake_tomboy_server(self): # the fake tomboy server has to be in a different process, # otherwise it will lock on the GIL. # For details, see # http://lists.freedesktop.org/archives/dbus/2007-January/006921.html # we use a lockfile to make sure the server is running before we start # the test global PID_TOMBOY lockfile_fd, lockfile_path = tempfile.mkstemp() PID_TOMBOY = os.fork() if PID_TOMBOY: # we wait in polling that the server has been started while True: try: fd = os.open(lockfile_path, os.O_CREAT | os.O_EXCL | os.O_RDWR) except OSError, e: if e.errno != errno.EEXIST: raise time.sleep(0.3) continue os.close(fd) break else:
def __init__(self, app_id, debug): """Setup Application.""" super().__init__(application_id=app_id) if debug: log.setLevel(logging.DEBUG) log.debug("Debug output enabled.") else: log.setLevel(logging.INFO) # Register backends datastore = DataStore() [datastore.register_backend(backend_dic) for backend_dic in BackendFactory().get_saved_backends_list()] # Save the backends directly to be sure projects.xml is written datastore.save(quit=False) self.req = datastore.get_requester() self.config = self.req.get_config("browser") self.config_plugins = self.req.get_config("plugins") self.clipboard = clipboard.TaskClipboard(self.req) self.timer = Timer(self.config) self.timer.connect('refresh', self.autoclean) self.preferences_dialog = Preferences(self.req, self) self.plugins_dialog = PluginsDialog(self.req) self.init_style()
def __init__(self, app_id): """Setup Application.""" super().__init__(application_id=app_id, flags=Gio.ApplicationFlags.HANDLES_OPEN) # Register backends datastore = DataStore() [ datastore.register_backend(backend_dic) for backend_dic in BackendFactory().get_saved_backends_list() ] # Save the backends directly to be sure projects.xml is written datastore.save(quit=False) self.req = datastore.get_requester() self.config = self.req.get_config("browser") self.config_plugins = self.req.get_config("plugins") self.clipboard = clipboard.TaskClipboard(self.req) self.timer = Timer(self.config) self.timer.connect('refresh', self.autoclean) self.preferences_dialog = Preferences(self.req, self) self.plugins_dialog = PluginsDialog(self.req) if self.config.get('dark_mode'): self.toggle_darkmode() self.init_style()
def do_startup(self): """Callback when primary instance should initialize""" try: Gtk.Application.do_startup(self) Gtk.Window.set_default_icon_name(self.props.application_id) # Load default file data_file = os.path.join(DATA_DIR, 'gtg_data.xml') self.ds.find_and_load_file(data_file) # TODO: Remove this once the new core is stable self.ds.data_path = os.path.join(DATA_DIR, 'gtg_data2.xml') # Register backends datastore = DataStore() for backend_dic in BackendFactory().get_saved_backends_list(): datastore.register_backend(backend_dic) # Save the backends directly to be sure projects.xml is written datastore.save(quit=False) self.req = datastore.get_requester() self.config = self.req.get_config("browser") self.config_plugins = self.req.get_config("plugins") self.clipboard = clipboard.TaskClipboard(self.req) self.timer = Timer(self.config) self.timer.connect('refresh', self.autoclean) self.preferences_dialog = Preferences(self.req, self) self.plugins_dialog = PluginsDialog(self.req) if self.config.get('dark_mode'): self.toggle_darkmode() self.init_style() except Exception as e: self._exception = e log.exception("Exception during startup") self._exception_dialog_timeout_id = GLib.timeout_add( # priority is a kwarg for some reason not reflected in the docs 5000, self._startup_exception_timeout, None)
class TestBackendTomboy(unittest.TestCase): """ Tests for the tomboy backend """ def setUp(self): thread_tomboy = threading.Thread(target=self.spawn_fake_tomboy_server) thread_tomboy.start() thread_tomboy.join() # only the test process should go further, the dbus server one should # stop here if not PID_TOMBOY: return # we create a custom dictionary listening to the server, and register # it in GTG. additional_dic = {} additional_dic["use this fake connection instead"] = ( FakeTomboy.BUS_NAME, FakeTomboy.BUS_PATH, FakeTomboy.BUS_INTERFACE) additional_dic[GenericBackend.KEY_ATTACHED_TAGS] = \ [GenericBackend.ALLTASKS_TAG] additional_dic[GenericBackend.KEY_DEFAULT_BACKEND] = True dic = BackendFactory().get_new_backend_dict('backend_tomboy', additional_dic) self.datastore = DataStore() self.backend = self.datastore.register_backend(dic) # waiting for the "start_get_tasks" to settle time.sleep(1) # we create a dbus session to speak with the server self.bus = dbus.SessionBus() obj = self.bus.get_object(FakeTomboy.BUS_NAME, FakeTomboy.BUS_PATH) self.tomboy = dbus.Interface(obj, FakeTomboy.BUS_INTERFACE) def spawn_fake_tomboy_server(self): # the fake tomboy server has to be in a different process, # otherwise it will lock on the GIL. # For details, see # http://lists.freedesktop.org/archives/dbus/2007-January/006921.html # we use a lockfile to make sure the server is running before we start # the test global PID_TOMBOY lockfile_fd, lockfile_path = tempfile.mkstemp() PID_TOMBOY = os.fork() if PID_TOMBOY: # we wait in polling that the server has been started while True: try: fd = os.open(lockfile_path, os.O_CREAT | os.O_EXCL | os.O_RDWR) except OSError as e: if e.errno != errno.EEXIST: raise time.sleep(0.3) continue os.close(fd) break else: FakeTomboy() os.close(lockfile_fd) os.unlink(lockfile_path) def tearDown(self): if not PID_TOMBOY: return self.datastore.save(quit=True) time.sleep(0.5) self.tomboy.FakeQuit() # FIXME: self.bus.close() os.kill(PID_TOMBOY, signal.SIGKILL) os.waitpid(PID_TOMBOY, 0) def test_everything(self): # we cannot use separate test functions because we only want a single # FakeTomboy dbus server running if not PID_TOMBOY: return for function in dir(self): if function.startswith("TEST_"): getattr(self, function)() self.tomboy.Reset() for tid in self.datastore.get_all_tasks(): self.datastore.request_task_deletion(tid) time.sleep(0.1) def TEST_processing_tomboy_notes(self): self.backend.set_attached_tags([GenericBackend.ALLTASKS_TAG]) # adding a note note = self.tomboy.CreateNamedNote(str(uuid.uuid4())) self.backend._process_tomboy_note(note) self.assertEqual(len(self.datastore.get_all_tasks()), 1) tid = self.backend.sync_engine.sync_memes.get_local_id(note) task = self.datastore.get_task(tid) # re-adding that (should not change anything) self.backend._process_tomboy_note(note) self.assertEqual(len(self.datastore.get_all_tasks()), 1) self.assertEqual( self.backend.sync_engine.sync_memes.get_local_id(note), tid) # removing the note and updating gtg self.tomboy.DeleteNote(note) self.backend.set_task(task) self.assertEqual(len(self.datastore.get_all_tasks()), 0) def TEST_set_task(self): self.backend.set_attached_tags([GenericBackend.ALLTASKS_TAG]) # adding a task task = self.datastore.requester.new_task() task.set_title("title") self.backend.set_task(task) self.assertEqual(len(self.tomboy.ListAllNotes()), 1) note = self.tomboy.ListAllNotes()[0] self.assertEqual(str(self.tomboy.GetNoteTitle(note)), task.get_title()) # re-adding that (should not change anything) self.backend.set_task(task) self.assertEqual(len(self.tomboy.ListAllNotes()), 1) self.assertEqual(note, self.tomboy.ListAllNotes()[0]) # removing the task and updating tomboy self.datastore.request_task_deletion(task.get_id()) self.backend._process_tomboy_note(note) self.assertEqual(len(self.tomboy.ListAllNotes()), 0) def TEST_update_newest(self): self.backend.set_attached_tags([GenericBackend.ALLTASKS_TAG]) task = self.datastore.requester.new_task() task.set_title("title") self.backend.set_task(task) note = self.tomboy.ListAllNotes()[0] gtg_modified = task.get_modified() tomboy_modified = self._modified_string_to_datetime( self.tomboy.GetNoteChangeDate(note)) # no-one updated, nothing should happen self.backend.set_task(task) self.assertEqual(gtg_modified, task.get_modified()) self.assertEqual(tomboy_modified, self._modified_string_to_datetime( self.tomboy.GetNoteChangeDate(note))) # we update the GTG task UPDATED_GTG_TITLE = "UPDATED_GTG_TITLE" task.set_title(UPDATED_GTG_TITLE) self.backend.set_task(task) self.assertTrue(gtg_modified < task.get_modified()) self.assertTrue(tomboy_modified <= self._modified_string_to_datetime( self.tomboy.GetNoteChangeDate(note))) self.assertEqual(task.get_title(), UPDATED_GTG_TITLE) self.assertEqual(self.tomboy.GetNoteTitle(note), UPDATED_GTG_TITLE) gtg_modified = task.get_modified() tomboy_modified = self._modified_string_to_datetime( self.tomboy.GetNoteChangeDate(note)) # we update the TOMBOY task UPDATED_TOMBOY_TITLE = "UPDATED_TOMBOY_TITLE" # the resolution of tomboy notes changed time is 1 second, so we need # to wait. This *shouldn't* be needed in the actual code because # tomboy signals are always a few seconds late. time.sleep(1) self.tomboy.SetNoteContents(note, UPDATED_TOMBOY_TITLE) self.backend._process_tomboy_note(note) self.assertTrue(gtg_modified <= task.get_modified()) self.assertTrue(tomboy_modified <= self._modified_string_to_datetime( self.tomboy.GetNoteChangeDate(note))) self.assertEqual(task.get_title(), UPDATED_TOMBOY_TITLE) self.assertEqual(self.tomboy.GetNoteTitle(note), UPDATED_TOMBOY_TITLE) def TEST_processing_tomboy_notes_with_tags(self): self.backend.set_attached_tags(['@a']) # adding a not syncable note note = self.tomboy.CreateNamedNote("title" + str(uuid.uuid4())) self.backend._process_tomboy_note(note) self.assertEqual(len(self.datastore.get_all_tasks()), 0) # re-adding that (should not change anything) self.backend._process_tomboy_note(note) self.assertEqual(len(self.datastore.get_all_tasks()), 0) # adding a tag to that note self.tomboy.SetNoteContents(note, "something with @a") self.backend._process_tomboy_note(note) self.assertEqual(len(self.datastore.get_all_tasks()), 1) # removing the tag and resyncing self.tomboy.SetNoteContents(note, "something with no tags") self.backend._process_tomboy_note(note) self.assertEqual(len(self.datastore.get_all_tasks()), 0) # adding a syncable note note = self.tomboy.CreateNamedNote("title @a" + str(uuid.uuid4())) self.backend._process_tomboy_note(note) self.assertEqual(len(self.datastore.get_all_tasks()), 1) tid = self.backend.sync_engine.sync_memes.get_local_id(note) task = self.datastore.get_task(tid) # re-adding that (should not change anything) self.backend._process_tomboy_note(note) self.assertEqual(len(self.datastore.get_all_tasks()), 1) self.assertEqual( self.backend.sync_engine.sync_memes.get_local_id(note), tid) # removing the note and updating gtg self.tomboy.DeleteNote(note) self.backend.set_task(task) self.assertEqual(len(self.datastore.get_all_tasks()), 0) def TEST_set_task_with_tags(self): self.backend.set_attached_tags(['@a']) # adding a not syncable task task = self.datastore.requester.new_task() task.set_title("title") self.backend.set_task(task) self.assertEqual(len(self.tomboy.ListAllNotes()), 0) # making that task syncable task.set_title("something else") task.add_tag("@a") self.backend.set_task(task) self.assertEqual(len(self.tomboy.ListAllNotes()), 1) note = self.tomboy.ListAllNotes()[0] self.assertEqual(str(self.tomboy.GetNoteTitle(note)), task.get_title()) # re-adding that (should not change anything) self.backend.set_task(task) self.assertEqual(len(self.tomboy.ListAllNotes()), 1) self.assertEqual(note, self.tomboy.ListAllNotes()[0]) # removing the syncable property and updating tomboy task.remove_tag("@a") self.backend.set_task(task) self.assertEqual(len(self.tomboy.ListAllNotes()), 0) def TEST_multiple_task_same_title(self): self.backend.set_attached_tags(['@a']) how_many_tasks = int(math.ceil(20 * random.random())) for iteration in range(0, how_many_tasks): task = self.datastore.requester.new_task() task.set_title("title") task.add_tag('@a') self.backend.set_task(task) self.assertEqual(len(self.tomboy.ListAllNotes()), how_many_tasks) def _modified_string_to_datetime(self, modified_string): return datetime.fromtimestamp(modified_string)
class TestDatastore(unittest.TestCase): """ Tests for the DataStore object. """ def setUp(self): """ Creates the environment for the tests @returns: None """ self.datastore = DataStore() self.requester = self.datastore.get_requester() def test_task_factory(self): """ Test for the task_factory function """ # generate a Task with a random id tid = str(uuid.uuid4()) task = self.datastore.task_factory(tid, newtask=True) self.assertTrue(isinstance(task, GTG.core.task.Task)) self.assertEqual(task.get_id(), tid) self.assertEqual(task.is_new(), True) tid = str(uuid.uuid4()) task = self.datastore.task_factory(tid, newtask=False) self.assertEqual(task.is_new(), False) def test_new_task_and_has_task(self): """ Tests the new_task function """ task = self.datastore.new_task() tid = task.get_id() self.assertTrue(isinstance(tid, str)) self.assertTrue(tid != '') self.assertTrue(task.is_new()) self.assertTrue(self.datastore.has_task(tid)) self.assertTrue(len(self.datastore.get_all_tasks()) == 1) def test_get_all_tasks(self): """ Tests the get_all_tasks function """ task_ids = [] for i in xrange(1, 10): task = self.datastore.new_task() task_ids.append(task.get_id()) return_list = self.datastore.get_all_tasks() self.assertEqual(len(return_list), i) task_ids.sort() return_list.sort() self.assertEqual(task_ids, return_list) def test_get_task(self): ''' Tests the get_task function ''' task = self.datastore.new_task() self.assertTrue(isinstance(self.datastore.get_task(task.get_id()), GTG.core.task.Task)) self.assertEqual(self.datastore.get_task(task.get_id()), task) def test_get_requester(self): ''' Tests the get_requester function ''' requester = self.datastore.get_requester() self.assertTrue(isinstance(requester, GTG.core.requester.Requester)) def test_get_tasks_tree(self): ''' Tests the get_tasks_tree function ''' tasks_tree = self.datastore.get_tasks_tree() self.assertTrue(isinstance(tasks_tree, Tree)) def test_push_task(self): ''' Tests the push_task function ''' task_ids = [] for i in xrange(1, 10): tid = str(uuid.uuid4()) if tid not in task_ids: task_ids.append(tid) task = self.datastore.task_factory(tid) return_value1 = self.datastore.push_task(task) self.assertTrue(return_value1) # we do it twice, but it should be pushed only once if it's # working correctly (the second should be discarded) return_value2 = self.datastore.push_task(task) self.assertFalse(return_value2) stored_tasks = self.datastore.get_all_tasks() task_ids.sort() stored_tasks.sort() self.assertEqual(task_ids, stored_tasks) def test_register_backend(self): ''' Tests the register_backend function. It also tests the get_all_backends and get_backend function as a side effect ''' # create a simple backend dictionary backend = FakeBackend(enabled=True) tasks_in_backend_count = randint(1, 20) for temp in xrange(0, tasks_in_backend_count): backend.fake_add_random_task() backend_dic = {'backend': backend, 'pid': 'a'} self.datastore.register_backend(backend_dic) all_backends = self.datastore.get_all_backends(disabled=True) self.assertEqual(len(all_backends), 1) registered_backend = self.datastore.get_backend(backend.get_id()) self.assertEqual(backend.get_id(), registered_backend.get_id()) self.assertTrue(isinstance(registered_backend, GTG.core.datastore.TaskSource)) self.assertTrue(registered_backend.is_enabled()) self.assertEqual(registered_backend.fake_get_initialized_count(), 1) # we give some time for the backend to push all its tasks sleep_within_loop(1) self.assertEqual(len(self.datastore.get_all_tasks()), tasks_in_backend_count) # same test, disabled backend backend = FakeBackend(enabled=False) for temp in xrange(1, randint(2, 20)): backend.fake_add_random_task() backend_dic = {'backend': backend, 'pid': 'b'} self.datastore.register_backend(backend_dic) all_backends = self.datastore.get_all_backends(disabled=True) self.assertEqual(len(all_backends), 2) all_backends = self.datastore.get_all_backends(disabled=False) self.assertEqual(len(all_backends), 1) registered_backend = self.datastore.get_backend(backend.get_id()) self.assertEqual(backend.get_id(), registered_backend.get_id()) self.assertTrue(isinstance(registered_backend, GTG.core.datastore.TaskSource)) self.assertFalse(registered_backend.is_enabled()) self.assertEqual(registered_backend.fake_get_initialized_count(), 0) # we give some time for the backend to push all its tasks (is # shouldn't, since it's disabled, but we give time anyway time.sleep(1) self.assertEqual(len(self.datastore.get_all_tasks()), tasks_in_backend_count) def test_set_backend_enabled(self): ''' Tests the set_backend_enabled function ''' enabled_backend = FakeBackend(enabled=True) disabled_backend = FakeBackend(enabled=False) self.datastore.register_backend({'backend': enabled_backend, 'pid': str(uuid.uuid4()), GenericBackend.KEY_DEFAULT_BACKEND: False}) self.datastore.register_backend({'backend': disabled_backend, 'pid': str(uuid.uuid4()), GenericBackend.KEY_DEFAULT_BACKEND: False}) # enabling an enabled backend self.datastore.set_backend_enabled(enabled_backend.get_id(), True) self.assertEqual(enabled_backend.fake_get_initialized_count(), 1) self.assertTrue(enabled_backend.is_enabled()) # disabling a disabled backend self.datastore.set_backend_enabled(disabled_backend.get_id(), False) self.assertEqual(disabled_backend.fake_get_initialized_count(), 0) self.assertFalse(disabled_backend.is_enabled()) # disabling an enabled backend self.datastore.set_backend_enabled(enabled_backend.get_id(), False) self.assertEqual(enabled_backend.fake_get_initialized_count(), 1) countdown = 10 while countdown >= 0 and enabled_backend.is_enabled(): time.sleep(0.1) self.assertFalse(enabled_backend.is_enabled()) # #enabling a disabled backend # self.datastore.set_backend_enabled(disabled_backend.get_id(), True) # self.assertEqual(disabled_backend.fake_get_initialized_count(), 1) # self.assertTrue(disabled_backend.is_enabled()) def test_remove_backend(self): """ Tests the remove_backend function """ enabled_backend = FakeBackend(enabled=True) disabled_backend = FakeBackend(enabled=False) self.datastore.register_backend({'backend': enabled_backend, 'pid': str(uuid.uuid4()), GenericBackend.KEY_DEFAULT_BACKEND: False}) self.datastore.register_backend({'backend': disabled_backend, 'pid': str(uuid.uuid4()), GenericBackend.KEY_DEFAULT_BACKEND: False}) # removing an enabled backend self.datastore.remove_backend(enabled_backend.get_id()) # waiting countdown = 10 while countdown >= 0 and enabled_backend.is_enabled(): time.sleep(0.1) self.assertFalse(enabled_backend.is_enabled()) self.assertEqual( len(self.datastore.get_all_backends(disabled=True)), 1) # removing a disabled backend self.datastore.remove_backend(disabled_backend.get_id()) self.assertFalse(disabled_backend.is_enabled()) self.assertEqual( len(self.datastore.get_all_backends(disabled=True)), 0) def test_flush_all_tasks(self): ''' Tests the flush_all_tasks function ''' # we add some tasks in the datastore tasks_in_datastore_count = 10 # randint(1, 20) for temp in xrange(0, tasks_in_datastore_count): self.datastore.new_task() datastore_stored_tids = self.datastore.get_all_tasks() self.assertEqual(tasks_in_datastore_count, len(datastore_stored_tids)) # we enable a backend backend = FakeBackend(enabled=True) self.datastore.register_backend({'backend': backend, 'pid': 'a'}) # we wait for the signal storm to wear off sleep_within_loop(2) # we sync self.datastore.get_backend(backend.get_id()).sync() # and we inject task in the backend tasks_in_backend_count = 5 # randint(1, 20) for temp in xrange(0, tasks_in_backend_count): backend.fake_add_random_task() backend_stored_tids = backend.fake_get_task_ids() self.assertEqual(tasks_in_backend_count, len(backend_stored_tids)) self.datastore.flush_all_tasks(backend.get_id()) # we wait for the signal storm to wear off sleep_within_loop(2) # we sync self.datastore.get_backend(backend.get_id()).sync() all_tasks_count = tasks_in_backend_count + tasks_in_datastore_count new_datastore_stored_tids = self.datastore.get_all_tasks() new_backend_stored_tids = backend.fake_get_task_ids() self.assertEqual(len(new_backend_stored_tids), all_tasks_count) self.assertEqual(len(new_datastore_stored_tids), all_tasks_count) new_datastore_stored_tids.sort() new_backend_stored_tids.sort() self.assertEqual(new_backend_stored_tids, new_datastore_stored_tids)
def test_translate(self): datastore = DataStore() root_task = datastore.task_factory('root-task', newtask=True) root_task.add_tag('@my-tag') root_task.add_tag('@my-other-tag') root_task.set_title('my task') datastore.push_task(root_task) child_task = datastore.task_factory('child-task', newtask=True) child_task.set_title('my first child') child_task.add_tag('@my-tag') child_task.add_tag('@my-other-tag') child_task.set_text("@my-tag, @my-other-tag, \n\ntask content") datastore.push_task(child_task) root_task.add_child(child_task.get_id()) child2_task = datastore.task_factory('done-child-task', newtask=True) child2_task.set_title('my done child') child2_task.add_tag('@my-tag') child2_task.add_tag('@my-other-tag') child2_task.set_text("@my-tag, @my-other-tag, \n\nother task txt") child2_task.set_status(Task.STA_DONE) datastore.push_task(child2_task) root_task.add_child(child2_task.get_id()) root_task.set_text(f"@my-tag, @my-other-tag\n\nline\n" f"{{!{child_task.get_id()}!}}\n" f"{{!{child2_task.get_id()}!}}\n") self.assertEqual( [child_task.get_id(), child2_task.get_id()], root_task.get_children()) self.assertEqual([root_task.get_id()], child_task.get_parents()) self.assertEqual([], PARENT_FIELD.get_gtg(root_task, NAMESPACE)) self.assertEqual(['child-task', 'done-child-task'], CHILDREN_FIELD.get_gtg(root_task, NAMESPACE)) self.assertEqual(['root-task'], PARENT_FIELD.get_gtg(child_task, NAMESPACE)) self.assertEqual([], CHILDREN_FIELD.get_gtg(child_task, NAMESPACE)) root_vtodo = Translator.fill_vtodo(root_task, 'calname', NAMESPACE) child_vtodo = Translator.fill_vtodo(child_task, 'calname', NAMESPACE) child2_vtodo = Translator.fill_vtodo(child2_task, 'calname', NAMESPACE) self.assertEqual([], PARENT_FIELD.get_dav(vtodo=root_vtodo.vtodo)) self.assertEqual(['child-task', 'done-child-task'], CHILDREN_FIELD.get_dav(vtodo=root_vtodo.vtodo)) self.assertEqual(['root-task'], PARENT_FIELD.get_dav(vtodo=child_vtodo.vtodo)) self.assertEqual([], CHILDREN_FIELD.get_dav(vtodo=child_vtodo.vtodo)) self.assertTrue('\r\nRELATED-TO;RELTYPE=CHILD:child-task\r\n' in root_vtodo.serialize()) self.assertTrue('\r\nRELATED-TO;RELTYPE=PARENT:root-task\r\n' in child_vtodo.serialize()) root_contents = root_vtodo.contents['vtodo'][0].contents child_cnt = child_vtodo.contents['vtodo'][0].contents child2_cnt = child2_vtodo.contents['vtodo'][0].contents for cnt in root_contents, child_cnt, child2_cnt: self.assertEqual(['my-tag', 'my-other-tag'], cnt['categories'][0].value) self.assertEqual('my first child', child_cnt['summary'][0].value) self.assertEqual('my done child', child2_cnt['summary'][0].value) self.assertEqual('task content', child_cnt['description'][0].value) self.assertEqual('other task txt', child2_cnt['description'][0].value) self.assertEqual('line\n[ ] my first child\n[x] my done child', root_contents['description'][0].value)