Example #1
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)
Example #2
0
def localfs_pootle_staged_real(localfs_base):
    from pytest_pootle.utils import add_store_fs

    plugin = localfs_base
    for store in plugin.resources.stores:
        add_store_fs(store=store,
                     fs_path=plugin.get_fs_path(store.pootle_path))
    state = plugin.state()
    assert len(state["pootle_staged"]) == plugin.resources.tracked.count()
    assert len([x for x in state]) == 1
    return plugin
Example #3
0
def test_fs_state_trackable_tracked(project0_dummy_plugin):
    plugin = project0_dummy_plugin
    project = plugin.project
    stores = Store.objects.filter(translation_project__project=project)
    store = stores[0]
    # the Store is not trackable if its got a StoreFS
    add_store_fs(store, plugin.get_fs_path(store.pootle_path))
    trackable = FSProjectStateResources(plugin).trackable_stores
    qs = stores.exclude(pootle_path=store.pootle_path)
    assert (sorted(trackable, key=lambda item: item[0].pk) == [
        (s, plugin.get_fs_path(s.pootle_path)) for s in list(qs.order_by("pk"))
    ])
Example #4
0
def localfs_pootle_staged_real(localfs_base):
    from pytest_pootle.utils import add_store_fs

    plugin = localfs_base
    for store in plugin.resources.stores:
        add_store_fs(
            store=store,
            fs_path=plugin.get_fs_path(store.pootle_path))
    state = plugin.state()
    assert len(state["pootle_staged"]) == plugin.resources.tracked.count()
    assert len([x for x in state]) == 1
    return plugin
Example #5
0
def test_fs_state_tracked_paths(fs_path_queries):
    plugin, (qfilter, pootle_path, fs_path) = fs_path_queries
    resources = FSProjectStateResources(plugin)
    for trackable in resources.trackable_stores:
        add_store_fs(*trackable)
    qs = StoreFS.objects.filter(project=plugin.project)
    if qfilter is False:
        qs = qs.none()
    elif qfilter:
        qs = qs.filter(qfilter)
    resources = FSProjectStateResources(plugin)
    assert (sorted(resources.tracked.values_list(
        "path", "pootle_path")) == sorted(resources.tracked_paths.items()))
Example #6
0
    def _setup_project_fs(self, project):
        from pootle_fs.utils import FSPlugin
        from pytest_pootle.utils import add_store_fs

        project.config["pootle_fs.fs_type"] = "localfs"
        project.config["pootle_fs.translation_mappings"] = {
            "default": "/<language_code>/<dir_path>/<filename>.<ext>"
        }
        project.config["pootle_fs.fs_url"] = "/tmp/path/for/setup"
        plugin = FSPlugin(project)
        for store in plugin.resources.stores:
            add_store_fs(store=store,
                         fs_path=plugin.get_fs_path(store.pootle_path),
                         synced=True)
Example #7
0
def test_fs_state_tracked(fs_path_queries):
    plugin, (qfilter, pootle_path, fs_path) = fs_path_queries
    resources = FSProjectStateResources(plugin)
    for trackable in resources.trackable_stores:
        add_store_fs(*trackable)
    qs = StoreFS.objects.filter(project=plugin.project)
    if qfilter is False:
        qs = qs.none()
    elif qfilter:
        qs = qs.filter(qfilter)
    tracked = FSProjectStateResources(plugin,
                                      pootle_path=pootle_path,
                                      fs_path=fs_path).tracked
    assert (list(tracked.order_by("pk")) == list(qs.order_by("pk")))
Example #8
0
File: env.py Project: cloph/pootle
    def _setup_project_fs(self, project):
        from pootle_fs.utils import FSPlugin
        from pytest_pootle.utils import add_store_fs

        project.config["pootle_fs.fs_type"] = "localfs"
        project.config["pootle_fs.translation_mappings"] = {
            "default": "/<language_code>/<dir_path>/<filename>.<ext>"}
        project.config["pootle_fs.fs_url"] = "/tmp/path/for/setup"
        plugin = FSPlugin(project)
        for store in plugin.resources.stores:
            add_store_fs(
                store=store,
                fs_path=plugin.get_fs_path(store.pootle_path),
                synced=True)
Example #9
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 #10
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 #11
0
def project0_dummy_plugin_no_stores(settings, request,
                                    no_fs_plugins, no_fs_files):
    from pytest_pootle.utils import add_store_fs

    from pootle.core.plugin import getter, provider
    from pootle_fs.delegate import fs_file, fs_plugins
    from pootle_fs.files import FSFile
    from pootle_fs.utils import FSPlugin
    from pootle_project.models import Project
    from pootle_store.models import Store

    settings.POOTLE_FS_PATH = "/tmp/foo/"
    project = Project.objects.get(code="project0")
    project.config["pootle_fs.fs_type"] = "dummyfs"
    project.config["pootle_fs.fs_url"] = "/foo/bar"
    stores = Store.objects.filter(
        translation_project__project=project)
    pootle_paths = list(stores.values_list("pootle_path", flat=True))

    class NoStoresDummyPlugin(DummyPlugin):

        def find_translations(self, fs_path=None, pootle_path=None):
            for pp in pootle_paths:
                if pootle_path and not fnmatch(pp, pootle_path):
                    continue
                fp = self.get_fs_path(pp)
                if fs_path and not fnmatch(fp, fs_path):
                    continue
                yield pp, fp

    @provider(fs_plugins, weak=False, sender=Project)
    def plugin_provider(**kwargs):
        return dict(dummyfs=NoStoresDummyPlugin)

    @getter(fs_file, weak=False, sender=NoStoresDummyPlugin)
    def fs_files_getter(**kwargs):
        return FSFile

    plugin = FSPlugin(project)
    for store in stores:
        add_store_fs(
            store=store,
            fs_path=plugin.get_fs_path(store.pootle_path),
            synced=True)
    return plugin
Example #12
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 #13
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 #14
0
def test_fs_state_fs_removed(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:
        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 = 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_fs_removed))
    assert len(state["fs_removed"]) == len(stores)
    if len(stores):
        assert state["fs_removed"]
    assert len(state["fs_removed"]) == len(stores)
    _test_state_type(plugin, state, "fs_removed", not stores)
Example #15
0
File: env.py Project: yar0d/pootle
    def setup_fs(self):
        from pytest_pootle.utils import add_store_fs

        from django.conf import settings

        from pootle_project.models import Project
        from pootle_fs.utils import FSPlugin

        settings.POOTLE_FS_PATH = os.path.join(
            settings.POOTLE_TRANSLATION_DIRECTORY, "__fs_working_dir__")
        os.mkdir(settings.POOTLE_FS_PATH)

        project = Project.objects.get(code="project0")
        project.config["pootle_fs.fs_type"] = "localfs"
        project.config["pootle_fs.translation_paths"] = {
            "default": "/<language_code>/<dir_path>/<filename>.<ext>"}
        project.config["pootle_fs.fs_url"] = "/tmp/path/for/setup"
        plugin = FSPlugin(project)
        for store in plugin.resources.stores:
            add_store_fs(
                store=store,
                fs_path=plugin.get_fs_path(store.pootle_path),
                synced=True)
Example #16
0
    def setup_fs(self):
        from pytest_pootle.utils import add_store_fs

        from django.conf import settings

        from pootle_project.models import Project
        from pootle_fs.utils import FSPlugin

        settings.POOTLE_FS_PATH = os.path.join(
            settings.POOTLE_TRANSLATION_DIRECTORY, "__fs_working_dir__")
        os.mkdir(settings.POOTLE_FS_PATH)

        project = Project.objects.get(code="project0")
        project.config["pootle_fs.fs_type"] = "localfs"
        project.config["pootle_fs.translation_paths"] = {
            "default": "/<language_code>/<dir_path>/<filename>.<ext>"
        }
        project.config["pootle_fs.fs_url"] = "/tmp/path/for/setup"
        plugin = FSPlugin(project)
        for store in plugin.resources.stores:
            add_store_fs(store=store,
                         fs_path=plugin.get_fs_path(store.pootle_path),
                         synced=True)
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)
Example #18
0
def test_fs_state_fs_removed(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:
        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 = 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_fs_removed))
    assert len(state["fs_removed"]) == len(stores)
    if len(stores):
        assert state["fs_removed"]
    assert len(state["fs_removed"]) == len(stores)
    _test_state_type(plugin, state, "fs_removed", not stores)
Example #19
0
def test_fs_state_pootle_changed(fs_path_queries):
    plugin, (qfilter, pootle_path, fs_path) = fs_path_queries
    resources = FSProjectStateResources(plugin)
    for trackable in resources.trackable_stores:
        add_store_fs(*trackable, synced=True)
    assert list(
        FSProjectStateResources(plugin,
                                pootle_path=pootle_path,
                                fs_path=fs_path).pootle_changed) == []
    stores = Store.objects.filter(translation_project__project=plugin.project)
    for store in stores.all():
        unit = store.units.first()
        unit.target = "%s FOO!" % store.name
        unit.save()
    qs = StoreFS.objects.filter(project=plugin.project)
    if qfilter is False:
        qs = qs.none()
    elif qfilter:
        qs = qs.filter(qfilter)
    resources = FSProjectStateResources(plugin,
                                        pootle_path=pootle_path,
                                        fs_path=fs_path)
    assert (sorted(resources.pootle_changed.values_list(
        "pk", flat=True)) == sorted(qs.values_list("pk", flat=True)))
Example #20
0
def test_fs_state_unsynced_staged(project0_dummy_plugin):
    plugin = project0_dummy_plugin
    resources = FSProjectStateResources(plugin)
    store_fs = add_store_fs(*resources.trackable_stores[0])
    assert resources.unsynced.count() == 1
    # unsynced does not include any that are staged rm/merge
    store_fs.staged_for_merge = True
    store_fs.save()
    assert resources.unsynced.count() == 0
    store_fs.staged_for_merge = False
    store_fs.staged_for_removal = True
    store_fs.save()
    assert resources.unsynced.count() == 0
    store_fs.staged_for_removal = False
    store_fs.save()
    assert resources.unsynced.count() == 1
Example #21
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 #22
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 #23
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 #24
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 #25
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 #26
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())