예제 #1
0
def test_missing_mapped_destination_tasks_src_not_complete():
    """ Tests expected behaviours on mapped tasks that are missing in
    the destination.
    """
    src = random_task()
    src.completed = False
    src_tasks = [src]
    src_svc = MockTaskService(src_tasks)

    dst = random_task()
    dst_tasks = []
    dst_svc = MockTaskService(dst_tasks)

    map = TaskMap()

    # create the pre-existing mapping
    map.map(src, dst)

    # preconditions
    assert len(map.get_all_src_keys()) == 1
    assert map.get_dst_id(src.id) == dst.id
    assert map.get_src_id(dst.id) == src.id

    TaskSync(src_svc, dst_svc, map).synchronise()

    assert dst.id != dst_svc.tasks[0].id
    assert len(map.get_all_src_keys()) == 1, "should still be just one mapping"
    assert not map.try_get_src_id(dst.id), "old dst should be unmapped"
    assert map.get_dst_id(src.id) != dst.id, "src should be mapped to something else"
    assert dst_svc.tasks[0].status == SyncStatus.new, "should be flagged as a new task"
    assert len(dst_svc.tasks) == 1
예제 #2
0
def test_missing_mapped_destination_tasks_src_complete():
    """ Tests expected behaviours on mapped tasks that are missing in
    the destination.
    """
    src = random_task()
    src.completed = True
    src_tasks = [src]
    src_svc = MockTaskService(src_tasks)

    dst = random_task()
    dst_tasks = []
    dst_svc = MockTaskService(dst_tasks)

    map = TaskMap()

    # create the pre-existing mapping
    map.map(src, dst)

    # preconditions
    assert len(map.get_all_src_keys()) == 1
    assert map.get_dst_id(src.id) == dst.id
    assert map.get_src_id(dst.id) == src.id

    TaskSync(src_svc, dst_svc, map).synchronise()

    assert len(dst_svc.tasks) == 0
예제 #3
0
def test_new_tasks_are_mapped():
    src_tasks = [random_task()]
    dst_tasks = []
    src = MockTaskService(src_tasks)
    dst = MockTaskService(dst_tasks)
    map = TaskMap()
    sync = TaskSync(src, dst, map)

    # preconditions
    assert len(map.get_all_src_keys()) == 0

    sync.synchronise()

    assert len(map.get_all_src_keys()) == 1
    assert src_tasks[0].id in map.get_all_src_keys()
    assert map.get_dst_id(src_tasks[0].id) == dst_tasks[0].id
예제 #4
0
    def test_get_all_src_keys(self):
        src_keys = (1, 2, 3, 4)
        src_tasks = [MockTask(_id=i) for i in src_keys]
        dst_tasks = [MockTask(_id=i + 20) for i in range(4)]
        map = TaskMap()
        for s, d in zip(src_tasks, dst_tasks):
            map.map(s, d)

        for actual in map.get_all_src_keys():
            assert actual in src_keys
예제 #5
0
    def test_get_all_src_keys(self):
        src_keys = (1,2,3,4)
        src_tasks = [MockTask(_id=i) for i in src_keys]
        dst_tasks = [MockTask(_id=i+20) for i in range(4)]
        map = TaskMap()
        for s,d in zip(src_tasks, dst_tasks):
            map.map(s,d)

        for actual in map.get_all_src_keys():
            assert actual in src_keys
예제 #6
0
def test_remove_orphan_mappings():
    src_tasks = [random_task()]
    dst_tasks = []
    ss = MockTaskService(src_tasks)
    ds = MockTaskService(dst_tasks)
    map = TaskMap()

    # add a few task mappings that won't exist in either source or destination
    map.map(random_task(), random_task())
    map.map(random_task(), random_task())
    map.map(random_task(), random_task())

    TaskSync(ss, ds, map).synchronise(clean_orphans=True)

    # We now expect just one mapping for the new src task
    all_mappings = map.get_all_src_keys()
    assert len(all_mappings) == 1
    assert map.get_dst_id(src_tasks[0].id)