def __test_plugin_commit_message(hg_project): hg_plugin = FSPlugin(hg_project) NEW_COMMIT_MSG = "New commit message" hg_plugin.pull() assert not hg_plugin.config.get("pootle_fs.commit_message") # make some updates hg_plugin.push_translations() # check that commit message uses default when not set in config with tmp_hg(hg_plugin.fs_url) as (tmp_repo_path, tmp_repo): last_commit = tmp_repo.hg.log('-1', '--pretty=%s') assert last_commit == DEFAULT_COMMIT_MSG # update the config hg_plugin.config["pootle_fs.commit_message"] = NEW_COMMIT_MSG # make further updates hg_plugin.add_translations() hg_plugin.sync_translations() # test that sync_translations committed with new commit message with tmp_hg(hg_plugin.fs_url) as (tmp_repo_path, tmp_repo): last_commit = tmp_repo.hg.log('-1', '--pretty=%s') assert last_commit == NEW_COMMIT_MSG
def _hg_remove(plugin, filepath): with tmp_hg(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()
def __test_plugin_commit_committer(hg_project): plugin = FSPlugin(hg_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_hg(plugin.fs_url) as (tmp_repo_path, tmp_repo): last_committer_name = tmp_repo.hg.log('-1', '--pretty=%an') last_committer_email = tmp_repo.hg.log('-1', '--pretty=%ae') hg_config = tmp_repo.config_reader() default_user = os.environ["USER"] default_email = ( "%s@%s" % (default_user, os.environ.get("HOSTNAME", ""))) assert ( last_committer_name == hg_config.get_value("user", "name", default_user)) assert ( last_committer_email == hg_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_hg(plugin.fs_url) as (tmp_repo_path, tmp_repo): last_committer_name = tmp_repo.hg.log('-1', '--pretty=%cn') last_committer_email = tmp_repo.hg.log('-1', '--pretty=%ce') assert last_committer_name == NEW_COMMITTER_NAME assert last_committer_email == NEW_COMMITTER_EMAIL
def __test_plugin_commit_committer(hg_project): plugin = FSPlugin(hg_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_hg(plugin.fs_url) as (tmp_repo_path, tmp_repo): last_committer_name = tmp_repo.hg.log('-1', '--pretty=%an') last_committer_email = tmp_repo.hg.log('-1', '--pretty=%ae') hg_config = tmp_repo.config_reader() default_user = os.environ["USER"] default_email = ("%s@%s" % (default_user, os.environ.get("HOSTNAME", ""))) assert (last_committer_name == hg_config.get_value( "user", "name", default_user)) assert (last_committer_email == hg_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_hg(plugin.fs_url) as (tmp_repo_path, tmp_repo): last_committer_name = tmp_repo.hg.log('-1', '--pretty=%cn') last_committer_email = tmp_repo.hg.log('-1', '--pretty=%ce') assert last_committer_name == NEW_COMMITTER_NAME assert last_committer_email == NEW_COMMITTER_EMAIL
def _hg_edit(plugin, filepath, content=None, message=None): with tmp_hg(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()
def _hg_edit(plugin, filepath, content=None, message=None): with tmp_hg(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()
def hg_env(post_db_setup, _django_cursor_wrapper): 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_cursor_wrapper: project0 = ProjectDBFactory( source_language=Language.objects.get(code="en"), code="hg_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, "__hg_src_project_0__") hglib.init(repo_path) with tmp_hg(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.add() tmp_repo.commit("Initial commit") tmp_repo.push() project0.config["pootle_fs.fs_type"] = "hg" project0.config["pootle_fs.fs_url"] = repo_path project0.config["pootle_fs.translation_paths"] = { "default": "/<language_code>/<dir_path>/<filename>.<ext>" } plugin = FSPlugin(project0) plugin.add() plugin.fetch() plugin.sync() # create_test_suite(plugin) project1 = ProjectDBFactory( source_language=Language.objects.get(code="en"), code="hg_project_1") TranslationProjectFactory(project=project1, language=language0) repo_path = os.path.join(fs_dir, "__hg_src_project_1__") hglib.init(repo_path) with tmp_hg(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.add() tmp_repo.commit("Initial commit") tmp_repo.push() project1.config["pootle_fs.fs_type"] = "hg" project1.config["pootle_fs.fs_url"] = repo_path project1.config["pootle_fs.translation_paths"] = { "default": "/<language_code>/<dir_path>/<filename>.<ext>" }
def _hg_remove(plugin, filepath): with tmp_hg(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()
def hg_env(post_db_setup, _django_cursor_wrapper): 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_cursor_wrapper: project0 = ProjectDBFactory( source_language=Language.objects.get(code="en"), code="hg_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, "__hg_src_project_0__") hglib.init(repo_path) with tmp_hg(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.add() tmp_repo.commit("Initial commit") tmp_repo.push() project0.config["pootle_fs.fs_type"] = "hg" project0.config["pootle_fs.fs_url"] = repo_path project0.config["pootle_fs.translation_paths"] = { "default": "/<language_code>/<dir_path>/<filename>.<ext>"} plugin = FSPlugin(project0) plugin.add() plugin.fetch() plugin.sync() # create_test_suite(plugin) project1 = ProjectDBFactory( source_language=Language.objects.get(code="en"), code="hg_project_1") TranslationProjectFactory(project=project1, language=language0) repo_path = os.path.join(fs_dir, "__hg_src_project_1__") hglib.init(repo_path) with tmp_hg(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.add() tmp_repo.commit("Initial commit") tmp_repo.push() project1.config["pootle_fs.fs_type"] = "hg" project1.config["pootle_fs.fs_url"] = repo_path project1.config["pootle_fs.translation_paths"] = { "default": "/<language_code>/<dir_path>/<filename>.<ext>"}