Пример #1
0
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
Пример #2
0
def test_create_first_then_diff():
    import tempfile, shutil
    from core.storage import setup_temp_db, write_test_file, teardown_temp_db
    from scheduling.fixed_scheduler import FixedScheduler

    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=lambda x: FixedScheduler())
    # this should create the first revision
    diffrunner.scan_files_for_changes()

    # then check to see that file's path has a revision, containing all lines
    rev_objs = store.get_revisions_for_document_path_sorted("notes1.txt")

    assert len(rev_objs) == 1
    assert rev_objs[0].content == content_at_first
    assert rev_objs[0].changelist == "0\n1"

    # wait a bit otw we get a problem with collision of two revisions having
    # the same timestamp... if timestamp difference is less than 2 seconds, the
    # diff is not taken
    time.sleep(3)
    
    # then modify the file
    write_test_file(os.path.join(notes_dir, "notes1.txt"), content_for_diff)

    # create new revision
    diffrunner.scan_files_for_changes()

    # check for two revisions, second one only has third line modified 
    rev_objs = store.get_revisions_for_document_path_sorted("notes1.txt")

    assert len(rev_objs) == 2
    assert rev_objs[0].content == content_at_first
    assert rev_objs[0].changelist == "0\n1"
    assert rev_objs[1].content == content_for_diff
    assert rev_objs[1].changelist == "2"

    shutil.rmtree(notes_dir)
    teardown_temp_db(store)
Пример #3
0
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)