def setup_revisions_notes1(): import tempfile, shutil from core.storage import setup_temp_db, write_test_file, teardown_temp_db from diffing.diff_runner import DiffRunner notes_dir = tempfile.mkdtemp() store = setup_temp_db() store.config.notes_directory = notes_dir content_at_first = "First\nsecond" content_for_diff = content_at_first + "\nThird" write_test_file(os.path.join(notes_dir, "notes1.txt"), content_at_first) # mark the file as watched for changes store.add_docs_to_watched_list(["notes1.txt"]) diffrunner = DiffRunner(store.config) # this should create the first revision diffrunner.scan_files_for_changes() # then modify the file write_test_file(os.path.join(notes_dir, "notes1.txt"), content_for_diff) # wait a bit otw we get a problem with collision of two revisions having # the same timestamp time.sleep(1) # create another revision diffrunner.scan_files_for_changes() return store, notes_dir
def test__reviews_finished__basic(): import tempfile, shutil from core.storage import setup_temp_db, write_test_file, teardown_temp_db from diffing.diff_runner import DiffRunner import scheduling.fixed_scheduler notes_dir = tempfile.mkdtemp() store = setup_temp_db() store.config.notes_directory = notes_dir content_at_first = "First\nsecond" content_for_diff = content_at_first + "\nThird" write_test_file(os.path.join(notes_dir, "notes1.txt"), content_at_first) store.add_docs_to_watched_list(["notes1.txt"]) diffrunner = DiffRunner(store.config, scheduler_getter=store.config.get_scheduler) # this should create the first revision diffrunner.scan_files_for_changes() rev_objs = store.get_revisions_for_document_path_sorted("notes1.txt") # HERE: reschedule based on id # note that mock config has a FixedScheduler with default intervals, # so next review should be in 6 days delta = datetime.timedelta(scheduling.fixed_scheduler.DEFAULT_INTERVALS[1]) reviews_finished([str(rev_objs[0].id)], store.config) rev_objs2 = store.get_revisions_for_document_path_sorted("notes1.txt") assert rev_objs2[0].scheduled_date == datetime.date.today() + delta shutil.rmtree(notes_dir) teardown_temp_db(store)
def perform_diff(config, scheduler_getter): diffrunner = DiffRunner(config, scheduler_getter=config.get_scheduler) diffrunner.scan_files_for_changes()