Example #1
0
def test_fs_state_filtered(state_filters, dummyfs_plugin_no_files, tp0):
    plugin = dummyfs_plugin_no_files
    state = ProjectFSState(plugin)
    current_state = {
        k: copy(v)
        for k, v
        in state.__state__.items()}
    filtered_state = state.filter(**state_filters)
    pootle_paths = state_filters["pootle_paths"]
    fs_paths = state_filters["fs_paths"]
    states = state_filters["states"]
    # original is unchanged
    assert state.__state__ == current_state
    for name, items in state.__state__.items():
        if states and name not in states:
            assert filtered_state[name] == []
            continue
        assert (
            [(item.fs_path, item.pootle_path)
             for item in items
             if (not pootle_paths
                 or item.pootle_path in pootle_paths)
             and (not fs_paths
                  or item.fs_path in fs_paths)]
            == [(x.fs_path, x.pootle_path) for x in filtered_state[name]])
Example #2
0
def test_fs_state_filtered(state_filters, dummyfs_plugin_no_files, tp0):
    plugin = dummyfs_plugin_no_files
    state = ProjectFSState(plugin)
    current_state = {
        k: copy(v)
        for k, v
        in state.__state__.items()}
    filtered_state = state.filter(**state_filters)
    pootle_paths = state_filters["pootle_paths"]
    fs_paths = state_filters["fs_paths"]
    states = state_filters["states"]
    # original is unchanged
    assert state.__state__ == current_state
    for name, items in state.__state__.items():
        if states and name not in states:
            assert filtered_state[name] == []
            continue
        assert (
            [(item.fs_path, item.pootle_path)
             for item in items
             if (not pootle_paths
                 or item.pootle_path in pootle_paths)
             and (not fs_paths
                  or item.fs_path in fs_paths)]
            == [(x.fs_path, x.pootle_path) for x in filtered_state[name]])
Example #3
0
def _test_state(plugin, pootle_path, fs_path, state_type, paths=None):
    state = ProjectFSState(plugin, pootle_path=pootle_path, fs_path=fs_path)
    if paths is None:
        paths = list(
            state.resources.storefs_filter.filtered(
                state.resources.tracked).values_list("pootle_path", "path"))
    state_paths = []
    for item in getattr(state, "state_%s" % state_type):
        fs_path = None
        if item.get("pootle_path"):
            pootle_path = item["pootle_path"]
        elif item.get("store_fs"):
            pootle_path = item["store_fs"].pootle_path
            fs_path = item["store_fs"].path
        else:
            pootle_path = item["store"].pootle_path
        if not fs_path:
            fs_path = item["fs_path"]
        state_paths.append((pootle_path, fs_path))
    result_state_paths = []
    for item in sorted(reversed(state[state_type])):
        assert isinstance(item, state.item_state_class)
        assert item > None
        assert item.project == plugin.project
        assert item.store == item.kwargs.get("store")
        result_state_paths.append((item.pootle_path, item.fs_path))
    assert sorted(state_paths) == result_state_paths == sorted(paths)
Example #4
0
def _test_state(plugin,
                pootle_path,
                fs_path,
                state_type,
                paths=None,
                exclude_templates=False):
    state = ProjectFSState(plugin, pootle_path=pootle_path, fs_path=fs_path)
    if paths is None:
        paths = state.resources.storefs_filter.filtered(
            state.resources.tracked)
        if exclude_templates:
            paths = paths.exclude(
                store__translation_project__language__code="templates")
        paths = list(paths.values_list("pootle_path", "path"))
    state_paths = []
    for item in getattr(state, "state_%s" % state_type):
        if item.get("pootle_path"):
            pootle_path = item["pootle_path"]
        else:
            pootle_path = item["store"].pootle_path
        fs_path = item["fs_path"]
        state_paths.append((pootle_path, fs_path))
    result_state_paths = []
    for item in sorted(reversed(state[state_type])):
        assert isinstance(item, state.item_state_class)
        assert item > None
        assert item.project == plugin.project
        assert item.store == item.kwargs.get("store")
        result_state_paths.append((item.pootle_path, item.fs_path))
    assert sorted(state_paths) == result_state_paths == sorted(paths)
Example #5
0
def test_fs_state_pootle_untracked(fs_path_qs, dummyfs_plugin_no_files):
    (qfilter, pootle_path, fs_path) = fs_path_qs
    plugin = dummyfs_plugin_no_files
    state = ProjectFSState(plugin, pootle_path=pootle_path, fs_path=fs_path)
    paths = list(
        state.resources.storefs_filter.filtered(
            state.resources.tracked).values_list("pootle_path", "path"))
    plugin.resources.tracked.delete()
    _test_state(plugin, pootle_path, fs_path, "pootle_untracked", paths)
Example #6
0
def test_fs_state_remove(fs_path_queries):
    plugin, (qfilter, pootle_path, fs_path) = fs_path_queries
    stores = Store.objects.filter(translation_project__project=plugin.project)
    state = ProjectFSState(plugin, pootle_path=pootle_path, fs_path=fs_path)
    stores = state.resources.store_filter.filtered(stores)
    for store in stores:
        store_fs = add_store_fs(store=store,
                                fs_path=plugin.get_fs_path(store.pootle_path))
        store_fs.staged_for_removal = True
        store_fs.save()
    stores_fs = state.resources.storefs_filter.filtered(
        state.resources.tracked)
    state = ProjectFSState(plugin, pootle_path=pootle_path, fs_path=fs_path)
    assert len(list(state.state_remove)) == stores_fs.count()
    for store_fs in state.state_remove:
        assert store_fs["store_fs"] in stores_fs
    assert len(state["remove"]) == stores_fs.count()
    _test_state_type(plugin, state, "remove", not stores_fs.count())
Example #7
0
def test_fs_state_merge_pootle_unsynced(fs_path_queries):
    plugin, (qfilter, pootle_path, fs_path) = fs_path_queries
    stores = Store.objects.filter(translation_project__project=plugin.project)
    state = ProjectFSState(plugin, pootle_path=pootle_path, fs_path=fs_path)
    stores = state.resources.store_filter.filtered(stores)
    for store in stores:
        store_fs = add_store_fs(store=store,
                                fs_path=plugin.get_fs_path(store.pootle_path))
        store_fs.staged_for_merge = True
        store_fs.resolve_conflict = POOTLE_WINS
        store_fs.save()
    stores_fs = state.resources.storefs_filter.filtered(
        state.resources.tracked)
    state = ProjectFSState(plugin, pootle_path=pootle_path, fs_path=fs_path)
    assert len(list(state.state_merge_pootle_wins)) == stores_fs.count()
    for store_fs in state.state_merge_pootle_wins:
        assert store_fs["store_fs"] in stores_fs
    assert len(state["merge_pootle_wins"]) == stores_fs.count()
    _test_state_type(plugin, state, "merge_pootle_wins", not stores_fs.count())
Example #8
0
def test_fs_state_instance(settings, english):
    settings.POOTLE_FS_PATH = "/tmp/foo/"
    project = ProjectDBFactory(source_language=english)
    plugin = DummyPlugin(project)
    state = ProjectFSState(plugin)
    assert state.project == project
    assert state.states == FS_STATE.keys()
    assert (str(state) == (
        "<ProjectFSState(<DummyPlugin(%s)>): Nothing to report>" %
        project.fullname))
Example #9
0
def test_fs_state_conflict_untracked(fs_path_queries):
    plugin, (qfilter, pootle_path, fs_path) = fs_path_queries
    stores = Store.objects.filter(translation_project__project=plugin.project)
    state = ProjectFSState(plugin, pootle_path=pootle_path, fs_path=fs_path)
    stores = state.resources.store_filter.filtered(stores)
    if fs_path:
        stores = [
            store for store in stores
            if fnmatch(plugin.get_fs_path(store.pootle_path), fs_path)
        ]
    else:
        stores = list(stores)
    assert len(list(state.state_conflict_untracked)) == len(stores)
    for result in state.state_conflict_untracked:
        assert result["store"] in stores
        if fs_path:
            assert fnmatch(result["fs_path"], fs_path)
    state = ProjectFSState(plugin, pootle_path=pootle_path, fs_path=fs_path)
    assert len(state["conflict_untracked"]) == len(stores)
    _test_state_type(plugin, state, "conflict_untracked", not stores)
Example #10
0
def test_fs_state_pootle_removed(fs_path_qs, project0_dummy_plugin_del_stores):
    (qfilter, pootle_path, fs_path) = fs_path_qs
    plugin = project0_dummy_plugin_del_stores
    state = ProjectFSState(plugin, pootle_path=pootle_path, fs_path=fs_path)
    stores_fs = state.resources.storefs_filter.filtered(
        state.resources.tracked)
    assert len(list(state.state_pootle_removed)) == stores_fs.count()
    for store_fs in state.state_pootle_removed:
        assert store_fs["store_fs"] in stores_fs
    assert len(state["pootle_removed"]) == stores_fs.count()
    _test_state_type(plugin, state, "pootle_removed", not stores_fs.count())
Example #11
0
def test_fs_state_fs_untracked(fs_path_qs, project0_dummy_plugin_del_stores):
    (qfilter, pootle_path, fs_path) = fs_path_qs
    plugin = project0_dummy_plugin_del_stores
    StoreFS.objects.filter(project=plugin.project).delete()
    state = ProjectFSState(plugin, pootle_path=pootle_path, fs_path=fs_path)
    found = [
        dict(pootle_path=pp, fs_path=fp)
        for pp, fp in plugin.find_translations(pootle_path=pootle_path,
                                               fs_path=fs_path)
    ]
    assert found == list(state.state_fs_untracked)
    assert len(state["fs_untracked"]) == len(found)
    _test_state_type(plugin, state, "fs_untracked", not found)
Example #12
0
def test_fs_state_fs_ahead(fs_path_qs, project0_dummy_plugin_fs_changed):
    (qfilter, pootle_path, fs_path) = fs_path_qs
    plugin = project0_dummy_plugin_fs_changed
    stores = Store.objects.filter(translation_project__project=plugin.project)
    for store in stores:
        add_store_fs(store=store,
                     fs_path=plugin.get_fs_path(store.pootle_path),
                     synced=True)
    state = ProjectFSState(plugin, pootle_path=pootle_path, fs_path=fs_path)
    stores_fs = state.resources.storefs_filter.filtered(
        state.resources.tracked)
    assert len(list(state.state_fs_ahead)) == stores_fs.count()
    for store_fs in state.state_fs_ahead:
        assert store_fs["store_fs"] in stores_fs
    assert len(state["fs_ahead"]) == stores_fs.count()
    _test_state_type(plugin, state, "fs_ahead", not stores_fs.count())
Example #13
0
def test_fs_state_fs_staged_store_removed(fs_path_qs,
                                          project0_dummy_plugin_del_stores):
    (qfilter, pootle_path, fs_path) = fs_path_qs
    plugin = project0_dummy_plugin_del_stores
    stores_fs = StoreFS.objects.filter(project=plugin.project)
    for storefs in stores_fs:
        storefs.resolve_conflict = FILE_WINS
        storefs.save()
    state = ProjectFSState(plugin, pootle_path=pootle_path, fs_path=fs_path)
    stores_fs = state.resources.storefs_filter.filtered(
        state.resources.tracked)
    assert len(list(state.state_fs_staged)) == stores_fs.count()
    assert len(state["fs_staged"]) == stores_fs.count()
    for store_fs in state.state_fs_staged:
        assert store_fs["store_fs"] in stores_fs
    assert len(state["fs_staged"]) == stores_fs.count()
    _test_state_type(plugin, state, "fs_staged", not stores_fs.count())
Example #14
0
def test_fs_state_pootle_untracked(fs_path_qs, project0_dummy_plugin_no_files):
    (qfilter, pootle_path, fs_path) = fs_path_qs
    plugin = project0_dummy_plugin_no_files
    state = ProjectFSState(plugin, pootle_path=pootle_path, fs_path=fs_path)
    stores = state.resources.store_filter.filtered(
        Store.objects.filter(translation_project__project=plugin.project))
    if fs_path:
        stores = [
            store for store in stores
            if fnmatch(plugin.get_fs_path(store.pootle_path), fs_path)
        ]
    else:
        stores = list(stores)
    assert len(stores) == len(list(state.state_pootle_untracked))
    assert len(state["pootle_untracked"]) == len(stores)
    if len(stores):
        assert state["pootle_untracked"]
    assert len(state["pootle_untracked"]) == len(stores)
    _test_state_type(plugin, state, "pootle_untracked", not stores)
Example #15
0
def test_fs_state_conflict(fs_path_qs, project0_dummy_plugin_fs_changed):
    (qfilter, pootle_path, fs_path) = fs_path_qs
    plugin = project0_dummy_plugin_fs_changed
    stores = Store.objects.filter(translation_project__project=plugin.project)
    for store in stores:
        add_store_fs(store=store,
                     fs_path=plugin.get_fs_path(store.pootle_path),
                     synced=True)
        unit = store.units[0]
        unit.target = "%sFOO!" % store.name
        unit.save()
    state = ProjectFSState(plugin, pootle_path=pootle_path, fs_path=fs_path)
    stores_fs = state.resources.storefs_filter.filtered(
        state.resources.tracked)
    assert len(list(state.state_conflict)) == stores_fs.count()
    for store_fs in state.state_conflict:
        assert store_fs["store_fs"] in stores_fs
    assert len(state["conflict"]) == stores_fs.count()
    _test_state_type(plugin, state, "conflict", not stores_fs.count())
Example #16
0
def test_fs_state_pootle_staged_no_file(fs_path_qs,
                                        project0_dummy_plugin_no_files):
    (qfilter, pootle_path, fs_path) = fs_path_qs
    plugin = project0_dummy_plugin_no_files
    stores = Store.objects.filter(translation_project__project=plugin.project)
    for store in stores:
        store_fs = add_store_fs(store=store,
                                fs_path=plugin.get_fs_path(store.pootle_path),
                                synced=True)
        store_fs.resolve_conflict = POOTLE_WINS
        store_fs.save()
    state = ProjectFSState(plugin, pootle_path=pootle_path, fs_path=fs_path)
    stores_fs = state.resources.storefs_filter.filtered(
        state.resources.tracked)
    assert len(list(state.state_pootle_staged)) == stores_fs.count()
    for store_fs in state.state_pootle_staged:
        assert store_fs["store_fs"] in stores_fs
    assert len(state["pootle_staged"]) == stores_fs.count()
    _test_state_type(plugin, state, "pootle_staged", not stores_fs.count())
Example #17
0
def test_fs_state_pootle_ahead(fs_path_queries):
    plugin, (qfilter, pootle_path, fs_path) = fs_path_queries
    stores = Store.objects.filter(translation_project__project=plugin.project)
    for store in stores:
        add_store_fs(store=store,
                     fs_path=plugin.get_fs_path(store.pootle_path),
                     synced=True)
        unit = store.units[0]
        unit.target = "%sFOO!" % store.name
        unit.save()
    state = ProjectFSState(plugin, pootle_path=pootle_path, fs_path=fs_path)
    stores = state.resources.store_filter.filtered(stores)
    if fs_path:
        stores = [
            store for store in stores
            if fnmatch(plugin.get_fs_path(store.pootle_path), fs_path)
        ]
    else:
        stores = list(stores)
    assert len(stores) == len(list(state.state_pootle_ahead))
    if len(stores):
        assert state["pootle_ahead"]
    assert len(state["pootle_ahead"]) == len(stores)
    _test_state_type(plugin, state, "pootle_ahead", not stores)