Example #1
0
def test_update_upload_new_revision(en_tutorial_po):
    update_store(
        en_tutorial_po,
        [("Hello, world", "Hello, world UPDATED")],
        submission_type=SubmissionTypes.UPLOAD,
        store_revision=Revision.get() + 1)
    assert en_tutorial_po.units[0].target == "Hello, world UPDATED"
Example #2
0
def test_update_upload_member_user(store0, member):
    store0.state = PARSED
    unit_source = store0.units.first().source
    update_store(store0, [(unit_source, "%s UPDATED" % unit_source)],
                 user=member,
                 store_revision=Revision.get() + 1)
    assert store0.units[0].submitted_by == member
Example #3
0
def test_update_upload_member_user(en_tutorial_po, member):
    update_store(
        en_tutorial_po,
        [("Hello, world", "Hello, world UPDATED")],
        user=member,
        store_revision=Revision.get() + 1)
    assert en_tutorial_po.units[0].submitted_by == member
Example #4
0
def test_update_upload_defaults(en_tutorial_po, system):
    update_store(en_tutorial_po, [("Hello, world", "Hello, world UPDATED")],
                 user=system,
                 store_revision=Revision.get() + 1)
    assert en_tutorial_po.units[0].submitted_by == system
    assert (en_tutorial_po.units[0].submission_set.first().type ==
            SubmissionTypes.SYSTEM)
Example #5
0
def test_update_upload_submission_type(en_tutorial_po):
    update_store(
        en_tutorial_po,
        [("Hello, world", "Hello, world UPDATED")],
        submission_type=SubmissionTypes.UPLOAD,
        store_revision=Revision.get() + 1)
    assert (en_tutorial_po.units[0].submission_set.first().type
            == SubmissionTypes.UPLOAD)
Example #6
0
def test_update_upload_submission_type(store0):
    store0.state = PARSED
    unit_source = store0.units.first().source
    update_store(store0, [(unit_source, "%s UPDATED" % unit_source)],
                 submission_type=SubmissionTypes.UPLOAD,
                 store_revision=Revision.get() + 1)
    assert (
        store0.units[0].submission_set.last().type == SubmissionTypes.UPLOAD)
Example #7
0
def test_update_upload_defaults(en_tutorial_po, system):
    update_store(
        en_tutorial_po,
        [("Hello, world", "Hello, world UPDATED")],
        user=system,
        store_revision=Revision.get() + 1)
    assert en_tutorial_po.units[0].submitted_by == system
    assert (en_tutorial_po.units[0].submission_set.first().type
            == SubmissionTypes.SYSTEM)
Example #8
0
def param_update_store_test(request, en_tutorial_po, member, member2):
    test = _setup_store_test(en_tutorial_po, member, member2,
                             UPDATE_STORE_TESTS[request.param])
    update_store(test[0],
                 units=test[1],
                 store_revision=test[2],
                 user=member2,
                 resolve_conflict=test[3])
    return test
Example #9
0
def test_update_upload_defaults(store0, system):
    store0.state = PARSED
    unit_source = store0.units.first().source
    update_store(store0, [(unit_source, "%s UPDATED" % unit_source)],
                 user=system,
                 store_revision=Revision.get() + 1)
    assert store0.units[0].submitted_by == system
    assert (
        store0.units[0].submission_set.last().type == SubmissionTypes.SYSTEM)
Example #10
0
def param_update_store_test(request, en_tutorial_po, member, member2):
    test = _setup_store_test(en_tutorial_po, member, member2,
                             UPDATE_STORE_TESTS[request.param])
    update_store(test[0],
                 units=test[1],
                 store_revision=test[2],
                 user=member2,
                 resolve_conflict=test[3])
    return test
Example #11
0
def test_update_upload_member_user(store0, member):
    store0.state = PARSED
    unit_source = store0.units.first().source
    update_store(
        store0,
        [(unit_source, "%s UPDATED" % unit_source)],
        user=member,
        store_revision=Revision.get() + 1)
    assert store0.units[0].submitted_by == member
Example #12
0
def test_update_upload_submission_type(store0):
    store0.state = PARSED
    unit_source = store0.units.first().source
    update_store(
        store0,
        [(unit_source, "%s UPDATED" % unit_source)],
        submission_type=SubmissionTypes.UPLOAD,
        store_revision=Revision.get() + 1)
    assert (
        store0.units[0].submission_set.last().type
        == SubmissionTypes.UPLOAD)
Example #13
0
def param_update_store_test(request, tp0, member, member2):
    from pytest_pootle.factories import StoreDBFactory

    store = StoreDBFactory(translation_project=tp0, parent=tp0.directory)
    test = _setup_store_test(store, member, member2,
                             UPDATE_STORE_TESTS[request.param])
    update_store(test[0],
                 units=test[1],
                 store_revision=test[2],
                 user=member2,
                 resolve_conflict=test[3])
    return test
Example #14
0
def test_update_upload_defaults(store0, system):
    store0.state = PARSED
    unit_source = store0.units.first().source
    update_store(
        store0,
        [(unit_source, "%s UPDATED" % unit_source)],
        user=system,
        store_revision=Revision.get() + 1)
    assert store0.units[0].submitted_by == system
    assert (
        store0.units[0].submission_set.last().type
        == SubmissionTypes.SYSTEM)
Example #15
0
def param_update_store_test(request, tp0, member, member2):
    from pootle.core.contextmanagers import update_data_after

    store = StoreDBFactory(translation_project=tp0, parent=tp0.directory)
    with update_data_after(store):
        test = _setup_store_test(store, member, member2,
                                 UPDATE_STORE_TESTS[request.param])
        update_store(test[0],
                     units=test[1],
                     store_revision=test[2],
                     user=member2,
                     resolve_conflict=test[3])
    return test
Example #16
0
def test_update_upload_again_new_revision(en_tutorial_po_no_file):
    store = en_tutorial_po_no_file
    assert store.state == NEW
    update_store(store, [("Hello, world", "Hello, world UPDATED")],
                 submission_type=SubmissionTypes.UPLOAD,
                 store_revision=Revision.get() + 1)
    store = Store.objects.get(pk=store.pk)
    assert store.state == PARSED
    assert store.units[0].target == "Hello, world UPDATED"

    update_store(store, [("Hello, world", "Hello, world UPDATED AGAIN")],
                 submission_type=SubmissionTypes.UPLOAD,
                 store_revision=Revision.get() + 1)
    store = Store.objects.get(pk=store.pk)
    assert store.state == PARSED
    assert store.units[0].target == "Hello, world UPDATED AGAIN"
Example #17
0
def _create_submission_and_suggestion(store,
                                      user,
                                      units=None,
                                      suggestion="SUGGESTION"):

    from pootle.core.models import Revision

    # Update store as user
    if units is None:
        units = [("Hello, world", "Hello, world UPDATED")]
    update_store(store, units, user=user, store_revision=Revision.get() + 1)

    # Add a suggestion
    unit = store.units[0]
    unit.add_suggestion(suggestion, user=user)
    return unit
Example #18
0
def test_update_upload_old_revision_unit_conflict(en_tutorial_po):
    original_revision = Revision.get()
    update_store(en_tutorial_po, [("Hello, world", "Hello, world UPDATED")],
                 submission_type=SubmissionTypes.UPLOAD,
                 store_revision=original_revision + 1)

    # load update with expired revision and conflicting unit
    update_store(en_tutorial_po, [("Hello, world", "Hello, world CONFLICT")],
                 submission_type=SubmissionTypes.UPLOAD,
                 store_revision=original_revision)

    # unit target is not updated
    assert en_tutorial_po.units[0].target == "Hello, world UPDATED"

    # but suggestion is added
    suggestion = en_tutorial_po.units[0].get_suggestions()[0].target
    assert suggestion == "Hello, world CONFLICT"
Example #19
0
def _create_submission_and_suggestion(store,
                                      user,
                                      units=None,
                                      suggestion="SUGGESTION"):
    from pootle.core.delegate import review
    from pootle.core.models import Revision
    from pootle_store.models import Suggestion

    # Update store as user
    if units is None:
        units = [("Hello, world", "Hello, world UPDATED", False)]
    update_store(store, units, user=user, store_revision=Revision.get() + 1)

    # Add a suggestion
    unit = store.units[0]
    review.get(Suggestion)().add(unit, suggestion, user)
    return unit
Example #20
0
def param_update_store_test(request, tp0, member, member2):
    from pootle.core.contextmanagers import update_data_after

    store = StoreDBFactory(
        translation_project=tp0,
        parent=tp0.directory)
    with update_data_after(store):
        test = _setup_store_test(
            store, member, member2,
            UPDATE_STORE_TESTS[request.param])
        update_store(
            test[0],
            units=test[1],
            store_revision=test[2],
            user=member2,
            resolve_conflict=test[3])
    return test
Example #21
0
def _create_submission_and_suggestion(store, user,
                                      units=None,
                                      suggestion="SUGGESTION"):

    from pootle.core.models import Revision

    # Update store as user
    if units is None:
        units = [("Hello, world", "Hello, world UPDATED")]
    update_store(
        store,
        units,
        user=user,
        store_revision=Revision.get() + 1)

    # Add a suggestion
    unit = store.units[0]
    unit.add_suggestion(suggestion, user=user)
    return unit
Example #22
0
def test_update_upload_again_new_revision(en_tutorial_po_no_file):
    store = en_tutorial_po_no_file
    assert store.state == NEW
    update_store(
        store,
        [("Hello, world", "Hello, world UPDATED")],
        submission_type=SubmissionTypes.UPLOAD,
        store_revision=Revision.get() + 1)
    store = Store.objects.get(pk=store.pk)
    assert store.state == PARSED
    assert store.units[0].target == "Hello, world UPDATED"

    update_store(
        store,
        [("Hello, world", "Hello, world UPDATED AGAIN")],
        submission_type=SubmissionTypes.UPLOAD,
        store_revision=Revision.get() + 1)
    store = Store.objects.get(pk=store.pk)
    assert store.state == PARSED
    assert store.units[0].target == "Hello, world UPDATED AGAIN"
Example #23
0
def param_update_store_test(request, tp0, member, member2):
    from pootle.core.contextmanagers import keep_data
    from pootle.core.signals import update_data

    store = StoreDBFactory(translation_project=tp0, parent=tp0.directory)

    with keep_data():
        test = _setup_store_test(store, member, member2,
                                 UPDATE_STORE_TESTS[request.param])
    update_data.send(store.__class__, instance=store)

    with keep_data():
        update_store(test[0],
                     units=test[1],
                     store_revision=test[2],
                     user=member2,
                     resolve_conflict=test[3])
    update_data.send(store.__class__, instance=store)

    return test
Example #24
0
File: store.py Project: arky/pootle
def _create_submission_and_suggestion(store, user,
                                      units=None,
                                      suggestion="SUGGESTION"):
    from pootle.core.delegate import review
    from pootle.core.models import Revision
    from pootle_store.models import Suggestion

    # Update store as user
    if units is None:
        units = [("Hello, world", "Hello, world UPDATED", False)]
    update_store(
        store,
        units,
        user=user,
        store_revision=Revision.get() + 1)

    # Add a suggestion
    unit = store.units[0]
    review.get(Suggestion)().add(unit, suggestion, user)
    return unit
Example #25
0
def _setup_store_test(store, member, member2, test):
    from pootle_store.constants import POOTLE_WINS, SOURCE_WINS

    setup = test.get("setup", None)

    if setup is None:
        setup = [(DEFAULT_STORE_UNITS_1),
                 (DEFAULT_STORE_UNITS_1 + DEFAULT_STORE_UNITS_2)]

    for units in setup:
        store_revision = store.get_max_unit_revision()
        print("setup store: %s %s" % (store_revision, units))
        update_store(store,
                     store_revision=store_revision,
                     units=units,
                     user=member)
        for unit in store.units:
            comment = ("Set up unit(%s) with store_revision: %s" %
                       (unit.source_f, store_revision))
            _create_comment_on_unit(unit, member, comment)

    store_revision, units_update = test["update_store"]
    units_before = [(unit, unit.change)
                    for unit in store.unit_set.select_related(
                        "change").all().order_by("index")]

    fs_wins = test.get("fs_wins", True)
    if fs_wins:
        resolve_conflict = SOURCE_WINS
    else:
        resolve_conflict = POOTLE_WINS

    if store_revision == "MAX":
        store_revision = store.get_max_unit_revision()

    elif store_revision == "MID":
        revisions = [unit.revision for unit, change in units_before]
        store_revision = sum(revisions) / len(revisions)

    return (store, units_update, store_revision, resolve_conflict,
            units_before, member, member2)
Example #26
0
def test_update_upload_old_revision_unit_conflict(en_tutorial_po):
    original_revision = Revision.get()
    update_store(
        en_tutorial_po,
        [("Hello, world", "Hello, world UPDATED")],
        submission_type=SubmissionTypes.UPLOAD,
        store_revision=original_revision + 1)

    # load update with expired revision and conflicting unit
    update_store(
        en_tutorial_po,
        [("Hello, world", "Hello, world CONFLICT")],
        submission_type=SubmissionTypes.UPLOAD,
        store_revision=original_revision)

    # unit target is not updated
    assert en_tutorial_po.units[0].target == "Hello, world UPDATED"

    # but suggestion is added
    suggestion = en_tutorial_po.units[0].get_suggestions()[0].target
    assert suggestion == "Hello, world CONFLICT"
Example #27
0
def _setup_store_test(store, member, member2, test):
    from pootle_store.constants import POOTLE_WINS, SOURCE_WINS

    setup = test.get("setup", None)

    if setup is None:
        setup = [(DEFAULT_STORE_UNITS_1),
                 (DEFAULT_STORE_UNITS_1 + DEFAULT_STORE_UNITS_2)]

    for units in setup:
        store_revision = store.get_max_unit_revision()
        print("setup store: %s %s" % (store_revision, units))
        update_store(store, store_revision=store_revision, units=units,
                     user=member)
        for unit in store.units:
            comment = ("Set up unit(%s) with store_revision: %s"
                       % (unit.source_f, store_revision))
            _create_comment_on_unit(unit, member, comment)

    store_revision, units_update = test["update_store"]
    units_before = [
        (unit, unit.change)
        for unit in store.unit_set.select_related("change").all().order_by("index")]

    fs_wins = test.get("fs_wins", True)
    if fs_wins:
        resolve_conflict = SOURCE_WINS
    else:
        resolve_conflict = POOTLE_WINS

    if store_revision == "MAX":
        store_revision = store.get_max_unit_revision()

    elif store_revision == "MID":
        revisions = [unit.revision for unit, change in units_before]
        store_revision = sum(revisions) / len(revisions)

    return (store, units_update, store_revision, resolve_conflict,
            units_before, member, member2)
Example #28
0
File: store.py Project: arky/pootle
def param_update_store_test(request, tp0, member, member2):
    from pootle.core.contextmanagers import keep_data
    from pootle.core.signals import update_data

    store = StoreDBFactory(
        translation_project=tp0,
        parent=tp0.directory)

    with keep_data():
        test = _setup_store_test(
            store, member, member2,
            UPDATE_STORE_TESTS[request.param])
    update_data.send(store.__class__, instance=store)

    with keep_data():
        update_store(
            test[0],
            units=test[1],
            store_revision=test[2],
            user=member2,
            resolve_conflict=test[3])
    update_data.send(store.__class__, instance=store)

    return test
Example #29
0
def test_update_upload_submission_type(en_tutorial_po):
    update_store(en_tutorial_po, [("Hello, world", "Hello, world UPDATED")],
                 submission_type=SubmissionTypes.UPLOAD,
                 store_revision=Revision.get() + 1)
    assert (en_tutorial_po.units[0].submission_set.first().type ==
            SubmissionTypes.UPLOAD)
Example #30
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")])
Example #31
0
def test_update_upload_member_user(en_tutorial_po, member):
    update_store(en_tutorial_po, [("Hello, world", "Hello, world UPDATED")],
                 user=member,
                 store_revision=Revision.get() + 1)
    assert en_tutorial_po.units[0].submitted_by == member
Example #32
0
def test_update_upload_new_revision(en_tutorial_po):
    update_store(en_tutorial_po, [("Hello, world", "Hello, world UPDATED")],
                 submission_type=SubmissionTypes.UPLOAD,
                 store_revision=Revision.get() + 1)
    assert en_tutorial_po.units[0].target == "Hello, world UPDATED"