Exemple #1
0
def __test_plugin_commit_message(git_project):
    git_plugin = FSPlugin(git_project)
    NEW_COMMIT_MSG = "New commit message"
    git_plugin.pull()
    assert not git_plugin.config.get("pootle_fs.commit_message")

    # make some updates
    git_plugin.push_translations()

    # check that commit message uses default when not set in config
    with tmp_git(git_plugin.fs_url) as (tmp_repo_path, tmp_repo):
        last_commit = tmp_repo.git.log('-1', '--pretty=%s')
        assert last_commit == DEFAULT_COMMIT_MSG

    # update the config
    git_plugin.config["pootle_fs.commit_message"] = NEW_COMMIT_MSG

    # make further updates
    git_plugin.add_translations()
    git_plugin.sync_translations()

    # test that sync_translations committed with new commit message
    with tmp_git(git_plugin.fs_url) as (tmp_repo_path, tmp_repo):
        last_commit = tmp_repo.git.log('-1', '--pretty=%s')
        assert last_commit == NEW_COMMIT_MSG
Exemple #2
0
def test_plugin_commit_message(git_project):
    git_plugin = FSPlugin(git_project)
    NEW_COMMIT_MSG = "New commit message"
    git_plugin.pull()
    assert not git_plugin.config.get("pootle_fs.commit_message")

    # make some updates
    git_plugin.push_translations()

    # check that commit message uses default when not set in config
    with tmp_git(git_plugin.fs_url) as (tmp_repo_path, tmp_repo):
        last_commit = tmp_repo.git.log('-1', '--pretty=%s')
        assert last_commit == DEFAULT_COMMIT_MSG

    # update the config
    git_plugin.config["pootle_fs.commit_message"] = NEW_COMMIT_MSG

    # make further updates
    git_plugin.add_translations()
    git_plugin.sync_translations()

    # test that sync_translations committed with new commit message
    with tmp_git(git_plugin.fs_url) as (tmp_repo_path, tmp_repo):
        last_commit = tmp_repo.git.log('-1', '--pretty=%s')
        assert last_commit == NEW_COMMIT_MSG
Exemple #3
0
def _git_remove(plugin, filepath):
    with tmp_git(plugin.fs.url) as (tmp_repo_path, tmp_repo):
        po_file = os.path.join(
            tmp_repo_path, filepath.strip("/"))
        os.unlink(po_file)
        tmp_repo.index.commit("Removing %s" % filepath)
        tmp_repo.remotes.origin.push()
Exemple #4
0
def test_plugin_commit_committer(git_project):
    plugin = FSPlugin(git_project)

    NEW_COMMITTER_NAME = "New Committer"
    NEW_COMMITTER_EMAIL = "*****@*****.**"

    plugin.pull()
    assert not plugin.config.get("pootle_fs.committer_name")
    assert not plugin.config.get("pootle_fs.committer_email")

    # make some updates
    plugin.push_translations()

    # check that commit message uses system default when not set in config
    with tmp_git(plugin.fs_url) as (tmp_repo_path, tmp_repo):
        last_committer_name = tmp_repo.git.log('-1', '--pretty=%an')
        last_committer_email = tmp_repo.git.log('-1', '--pretty=%ae')
        git_config = tmp_repo.config_reader()
        default_user = os.environ["USER"]
        default_email = (
            "%s@%s"
            % (default_user, os.environ.get("HOSTNAME", "")))
        assert (
            last_committer_name
            == git_config.get_value("user", "name", default_user))
        assert (
            last_committer_email
            == git_config.get_value("user", "email", default_email))

    # update the committer name/email in config
    plugin.config["pootle_fs.committer_name"] = NEW_COMMITTER_NAME
    plugin.config["pootle_fs.committer_email"] = NEW_COMMITTER_EMAIL

    # make further updates
    plugin.add_translations()
    plugin.sync_translations()

    # test that sync_translations committed with new commit committer
    with tmp_git(plugin.fs_url) as (tmp_repo_path, tmp_repo):
        last_committer_name = tmp_repo.git.log('-1', '--pretty=%cn')
        last_committer_email = tmp_repo.git.log('-1', '--pretty=%ce')
        assert last_committer_name == NEW_COMMITTER_NAME
        assert last_committer_email == NEW_COMMITTER_EMAIL
Exemple #5
0
def __test_plugin_commit_committer(git_project):
    plugin = FSPlugin(git_project)

    NEW_COMMITTER_NAME = "New Committer"
    NEW_COMMITTER_EMAIL = "*****@*****.**"

    plugin.pull()
    assert not plugin.config.get("pootle_fs.committer_name")
    assert not plugin.config.get("pootle_fs.committer_email")

    # make some updates
    plugin.push_translations()

    # check that commit message uses system default when not set in config
    with tmp_git(plugin.fs_url) as (tmp_repo_path, tmp_repo):
        last_committer_name = tmp_repo.git.log('-1', '--pretty=%an')
        last_committer_email = tmp_repo.git.log('-1', '--pretty=%ae')
        git_config = tmp_repo.config_reader()
        default_user = os.environ["USER"]
        default_email = ("%s@%s" %
                         (default_user, os.environ.get("HOSTNAME", "")))
        assert (last_committer_name == git_config.get_value(
            "user", "name", default_user))
        assert (last_committer_email == git_config.get_value(
            "user", "email", default_email))

    # update the committer name/email in config
    plugin.config["pootle_fs.committer_name"] = NEW_COMMITTER_NAME
    plugin.config["pootle_fs.committer_email"] = NEW_COMMITTER_EMAIL

    # make further updates
    plugin.add_translations()
    plugin.sync_translations()

    # test that sync_translations committed with new commit committer
    with tmp_git(plugin.fs_url) as (tmp_repo_path, tmp_repo):
        last_committer_name = tmp_repo.git.log('-1', '--pretty=%cn')
        last_committer_email = tmp_repo.git.log('-1', '--pretty=%ce')
        assert last_committer_name == NEW_COMMITTER_NAME
        assert last_committer_email == NEW_COMMITTER_EMAIL
Exemple #6
0
def moz_env(post_db_setup, _django_cursor_wrapper, ios_pootle_file):

    from django.conf import settings

    from pytest_pootle.factories import (
        ProjectDBFactory, StoreDBFactory,
        TranslationProjectFactory)

    from pootle_fs.models import ProjectFS
    from pootle_language.models import Language

    with _django_cursor_wrapper:
        ios_project = ProjectDBFactory(
            source_language=Language.objects.get(code="en"),
            code="ios",
            localfiletype="xliff")
        ios_tp = TranslationProjectFactory(
            project=ios_project,
            language=Language.objects.get(code="language0"))
        ios_store = StoreDBFactory(
            parent=ios_tp.directory,
            translation_project=ios_tp,
            name="firefox-ios.xliff")
        ios_bytes = io.BytesIO(ios_pootle_file.encode("utf8"))
        ios_store.update(
            getclass(ios_bytes)(ios_bytes.read()))

        fs_dir = tempfile.mkdtemp()
        settings.POOTLE_FS_PATH = fs_dir

        repo_path = os.path.join(fs_dir, "__moz_ios_src__")
        Repo.init(repo_path, bare=True)

        with tmp_git(repo_path) as (tmp_repo_path, tmp_repo):
            config_file = os.path.join(tmp_repo_path, ".pootle.ini")
            with open(config_file, "w") as ini:
                config = (
                    "[default]\n"
                    "serializers = ios\n"
                    "deserializers = ios\n"
                    "translation_path = <lang>/<filename>.xliff")
                ini.write(config)
            tmp_repo.index.add([".pootle.ini"])
            tmp_repo.index.commit("Add Pootle configuration")
            tmp_repo.remotes.origin.push("master:master")

        ios_fs = ProjectFS.objects.create(
            project=ios_project,
            fs_type="git",
            url=repo_path)
        ios_plugin = ios_fs.plugin
        ios_plugin.add_translations()
Exemple #7
0
def _git_edit(plugin, filepath, content=None, message=None):
    with tmp_git(plugin.fs.url) as (tmp_repo_path, tmp_repo):
        po_file = os.path.join(tmp_repo_path, filepath.strip("/"))
        dir_name = os.path.dirname(po_file)
        if not os.path.exists(dir_name):
            os.makedirs(dir_name)
        if content is None:
            content = str(datetime.now())
        if message is None:
            message = "Editing %s" % filepath
        with open(po_file, "w") as f:
            f.write(content)
        tmp_repo.index.add([filepath.strip("/")])
        tmp_repo.index.commit(message)
        tmp_repo.remotes.origin.push()
Exemple #8
0
def _git_edit(plugin, filepath, content=None, message=None):
    with tmp_git(plugin.fs.url) as (tmp_repo_path, tmp_repo):
        po_file = os.path.join(
            tmp_repo_path, filepath.strip("/"))
        dir_name = os.path.dirname(po_file)
        if not os.path.exists(dir_name):
            os.makedirs(dir_name)
        if content is None:
            content = str(datetime.now())
        if message is None:
            message = "Editing %s" % filepath
        with open(po_file, "w") as f:
            f.write(content)
        tmp_repo.index.add([filepath.strip("/")])
        tmp_repo.index.commit(message)
        tmp_repo.remotes.origin.push()
Exemple #9
0
def moz_env(post_db_setup, _django_cursor_wrapper, ios_pootle_file):

    from django.conf import settings

    from pytest_pootle.factories import (ProjectDBFactory, StoreDBFactory,
                                         TranslationProjectFactory)

    from pootle_fs.models import ProjectFS
    from pootle_language.models import Language

    with _django_cursor_wrapper:
        ios_project = ProjectDBFactory(
            source_language=Language.objects.get(code="en"),
            code="ios",
            localfiletype="xliff")
        ios_tp = TranslationProjectFactory(
            project=ios_project,
            language=Language.objects.get(code="language0"))
        ios_store = StoreDBFactory(parent=ios_tp.directory,
                                   translation_project=ios_tp,
                                   name="firefox-ios.xliff")
        ios_bytes = io.BytesIO(ios_pootle_file.encode("utf8"))
        ios_store.update(getclass(ios_bytes)(ios_bytes.read()))

        fs_dir = tempfile.mkdtemp()
        settings.POOTLE_FS_PATH = fs_dir

        repo_path = os.path.join(fs_dir, "__moz_ios_src__")
        Repo.init(repo_path, bare=True)

        with tmp_git(repo_path) as (tmp_repo_path, tmp_repo):
            config_file = os.path.join(tmp_repo_path, ".pootle.ini")
            with open(config_file, "w") as ini:
                config = ("[default]\n"
                          "serializers = ios\n"
                          "deserializers = ios\n"
                          "translation_path = <lang>/<filename>.xliff")
                ini.write(config)
            tmp_repo.index.add([".pootle.ini"])
            tmp_repo.index.commit("Add Pootle configuration")
            tmp_repo.remotes.origin.push("master:master")

        ios_fs = ProjectFS.objects.create(project=ios_project,
                                          fs_type="git",
                                          url=repo_path)
        ios_plugin = ios_fs.plugin
        ios_plugin.add_translations()
Exemple #10
0
def _check_git_fs(plugin, response):
    with tmp_git(plugin.fs_url) as (tmp_repo_path, tmp_repo):
        check_files_match(tmp_repo_path, response)
Exemple #11
0
def git_env(post_db_setup, _django_cursor_wrapper):
    from django.conf import settings

    from pytest_pootle.utils import update_store
    from pytest_pootle.fs.utils import create_test_suite
    import pytest_pootle

    from pytest_pootle.factories import (
        ProjectDBFactory, TranslationProjectFactory)

    from pootle_app.models import Directory
    from pootle_config.utils import ObjectConfig
    from pootle_fs.plugin import FSPlugin
    from pootle_language.models import Language
    from pootle_store.models import Store

    import tempfile

    with _django_cursor_wrapper:
        project0 = ProjectDBFactory(
            source_language=Language.objects.get(code="en"),
            code="git_project_0")

        language0 = Language.objects.get(code="language0")
        tp = TranslationProjectFactory(project=project0, language=language0)

        initial_src_path = os.path.abspath(
            os.path.join(
                os.path.dirname(pytest_pootle.__file__),
                "data/fs/example_fs"))
        fs_dir = tempfile.mkdtemp()
        settings.POOTLE_FS_PATH = fs_dir

        repo_path = os.path.join(fs_dir, "__git_src_project_0__")
        Repo.init(repo_path, bare=True)

        with tmp_git(repo_path) as (tmp_repo_path, tmp_repo):
            with get_dir_util() as dir_util:
                dir_util.copy_tree(initial_src_path, tmp_repo_path)
            tmp_repo.index.add([".pootle.ini", "*"])
            tmp_repo.index.commit("Initial commit")
            tmp_repo.remotes.origin.push("master:master")

        conf = ObjectConfig(project0)
        conf["pootle_fs.fs_type"] = "git"
        conf["pootle_fs.fs_url"] = repo_path
        conf["pootle_fs.translation_paths"] = OrderedDict(
            [("default", "gnu_style/po/<lang>.po"),
             ("subdir1",
              "gnu_style_named_folders/po-<filename>/<lang>.po"),
             ("subdir2",
              "gnu_style_named_files/po/<filename>-<lang>.po"),
             ("subdir3",
              "non_gnu_style/locales/<lang>/<directory_path>/<filename>.po")])

        updated_src_path = os.path.abspath(
            os.path.join(
                os.path.dirname(pytest_pootle.__file__),
                "data/fs/example_fs_updated"))

        plugin = FSPlugin(project0)
        plugin.add_translations()
        plugin.fetch_translations()
        plugin.sync_translations()

        with tmp_git(repo_path) as (tmp_repo_path, tmp_repo):
            # merge the update onto the repo src
            with get_dir_util() as dir_util:
                dir_util.copy_tree(
                    updated_src_path,
                    tmp_repo_path, preserve_times=0)
            tmp_repo.index.add([".pootle.ini", "*"])
            tmp_repo.index.commit("Creating test suite")
            tmp_repo.remotes.origin.push("master:master")

        # conflict
        pootle_path_conflict = (
            "%ssubdir3/subsubdir/example3.po"
            % tp.pootle_path)
        plugin.pull()
        update_store(
            Store.objects.get(pootle_path=pootle_path_conflict),
            units=(("Hello, world", "Hello, world DB CONFLICT"), ))

        # conflict_untracked
        subdir3 = Directory.objects.get(
            pootle_path="%ssubdir3/" % tp.pootle_path)
        Store.objects.create(
            translation_project=tp,
            parent=subdir3,
            name="example3.po")

        # pootle_ahead
        pootle_path_ahead = "%ssubdir1/example1.po" % tp.pootle_path
        update_store(
            Store.objects.get(pootle_path=pootle_path_ahead),
            units=(("Hello, world", "Hello, world DB AHEAD"), ))

        # pootle_untracked
        Store.objects.create(
            translation_project=tp,
            parent=subdir3,
            name="example4.po")

        # pootle_removed
        Store.objects.get(
            pootle_path="%ssubdir1/example2.po" % tp.pootle_path).delete()

        create_test_suite(plugin)

        project1 = ProjectDBFactory(
            source_language=Language.objects.get(code="en"),
            code="git_project_1")

        tp = TranslationProjectFactory(project=project1, language=language0)

        repo_path = os.path.join(fs_dir, "__git_src_project_1__")
        Repo.init(repo_path, bare=True)
        with tmp_git(repo_path) as (tmp_repo_path, tmp_repo):
            with get_dir_util() as dir_util:
                dir_util.copy_tree(initial_src_path, tmp_repo_path)
            tmp_repo.index.add(["*"])
            tmp_repo.index.commit("Initial commit")
            tmp_repo.remotes.origin.push("master:master")
        conf = ObjectConfig(project1)
        conf["pootle_fs.fs_type"] = "git"
        conf["pootle_fs.fs_url"] = repo_path
        conf["pootle_fs.translation_paths"] = OrderedDict(
            [("default", "gnu_style/po/<lang>.po"),
             ("subdir1",
              "gnu_style_named_folders/po-<filename>/<lang>.po"),
             ("subdir2",
              "gnu_style_named_files/po/<filename>-<lang>.po"),
             ("subdir3",
              "non_gnu_style/locales/<lang>/<directory_path>/<filename>.po")])
Exemple #12
0
def setup_git_env(django_db_setup, django_db_blocker):
    """Sets up the site DB only if tests requested to use the DB (autouse)."""
    from django.conf import settings

    import pytest_pootle

    from pytest_pootle.factories import (ProjectDBFactory,
                                         TranslationProjectFactory)

    from pootle_fs.utils import FSPlugin
    from pootle_language.models import Language

    import tempfile

    with django_db_blocker.unblock():
        project0 = ProjectDBFactory(
            source_language=Language.objects.get(code="en"),
            code="git_project_0")

        language0 = Language.objects.get(code="language0")
        TranslationProjectFactory(project=project0, language=language0)

        initial_src_path = os.path.abspath(
            os.path.join(os.path.dirname(pytest_pootle.__file__),
                         "data/fs/example_fs"))
        fs_dir = tempfile.mkdtemp()
        settings.POOTLE_FS_PATH = fs_dir

        repo_path = os.path.join(fs_dir, "__git_src_project_0__")
        Repo.init(repo_path, bare=True)

        with tmp_git(repo_path) as (tmp_repo_path, tmp_repo):
            with get_dir_util() as dir_util:
                dir_util.copy_tree(initial_src_path, tmp_repo_path)
            tmp_repo.index.commit("Initial commit")
            tmp_repo.remotes.origin.push("master:master")

        project0.config["pootle_fs.fs_type"] = "git"
        project0.config["pootle_fs.fs_url"] = repo_path
        project0.config["pootle_fs.translation_mappings"] = {
            "default": "/<language_code>/<dir_path>/<filename>.<ext>"
        }
        plugin = FSPlugin(project0)
        plugin.fetch()
        plugin.add()
        plugin.sync()

        # create_test_suite(plugin)

        project1 = ProjectDBFactory(
            source_language=Language.objects.get(code="en"),
            code="git_project_1")

        TranslationProjectFactory(project=project1, language=language0)

        repo_path = os.path.join(fs_dir, "__git_src_project_1__")
        Repo.init(repo_path, bare=True)
        with tmp_git(repo_path) as (tmp_repo_path, tmp_repo):
            with get_dir_util() as dir_util:
                dir_util.copy_tree(initial_src_path, tmp_repo_path)
            tmp_repo.index.add(["*"])
            tmp_repo.index.commit("Initial commit")
            tmp_repo.remotes.origin.push("master:master")
        project1.config["pootle_fs.fs_type"] = "git"
        project1.config["pootle_fs.fs_url"] = repo_path
        project1.config["pootle_fs.translation_mappings"] = {
            "default": "/<language_code>/<dir_path>/<filename>.<ext>"
        }
Exemple #13
0
def _git_remove(plugin, filepath):
    with tmp_git(plugin.fs.url) as (tmp_repo_path, tmp_repo):
        po_file = os.path.join(tmp_repo_path, filepath.strip("/"))
        os.unlink(po_file)
        tmp_repo.index.commit("Removing %s" % filepath)
        tmp_repo.remotes.origin.push()