Пример #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
Пример #2
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
Пример #3
0
def test_plugin_pull(git_project_1):
    git_plugin = FSPlugin(git_project_1)
    assert git_plugin.is_cloned is False
    git_plugin.pull()
    assert git_plugin.is_cloned is True
Пример #4
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")])