Beispiel #1
0
    def setup_terminology(self):
        from tests.factories import (
            ProjectDBFactory,
            StoreDBFactory,
            TranslationProjectFactory,
            UnitDBFactory,
        )
        from pootle_language.models import Language

        source_language = Language.objects.get(code="en")
        terminology = ProjectDBFactory(
            code="terminology",
            checkstyle="terminology",
            fullname="Terminology",
            source_language=source_language,
        )
        for language in Language.objects.exclude(code="en"):
            tp = TranslationProjectFactory(project=terminology,
                                           language=language)

            store = StoreDBFactory(translation_project=tp,
                                   name="terminology.po")
            store.save()
            for i_ in range(0, 1):
                UnitDBFactory(store=store)
Beispiel #2
0
def ordered_po(test_fs, tp0):
    """Create a store with ordered units."""
    from tests.factories import StoreDBFactory

    store = StoreDBFactory(name="ordered.po",
                           translation_project=tp0,
                           parent=tp0.directory)
    with test_fs.open("data/po/ordered.po", "rb") as src:
        store.update(store.deserialize(src.read()))
    return store
Beispiel #3
0
def numbered_po(test_fs, project0_disk):
    """Create a store with numbered units."""
    from tests.factories import (
        LanguageDBFactory,
        StoreDBFactory,
        TranslationProjectFactory,
    )

    tp = TranslationProjectFactory(project=project0_disk,
                                   language=LanguageDBFactory())
    store = StoreDBFactory(name="numbered.po",
                           translation_project=tp,
                           parent=tp.directory)
    with test_fs.open("data/po/1234.po", "rb") as src:
        store.update(store.deserialize(src.read()))
    return store
Beispiel #4
0
    def setup_complex_po(self):
        import tests
        from tests.factories import StoreDBFactory
        from pootle_translationproject.models import TranslationProject

        po_file = os.path.join(os.path.dirname(tests.__file__),
                               *("data", "po", "complex.po"))
        with open(po_file, "rb") as f:
            ttk = getclass(f)(f.read())

        tp = TranslationProject.objects.get(project__code="project0",
                                            language__code="language0")

        store = StoreDBFactory(parent=tp.directory,
                               translation_project=tp,
                               name="complex.po")
        store.update(ttk)
Beispiel #5
0
def test_delete_mark_obsolete(project0_disk, store0):
    """Tests that the in-DB Store and Directory are marked as obsolete
    after the on-disk file ceased to exist.

    Refs. #269.
    """
    tp = TranslationProjectFactory(
        project=project0_disk, language=LanguageDBFactory()
    )
    store = StoreDBFactory(translation_project=tp, parent=tp.directory)

    store.update(store.deserialize(store0.serialize()))
    store.sync()
    pootle_path = store.pootle_path

    # Remove on-disk file
    os.remove(store.file.path)

    # Update stores by rescanning TP
    tp.scan_files()

    # Now files that ceased to exist should be marked as obsolete
    updated_store = Store.objects.get(pootle_path=pootle_path)
    assert updated_store.obsolete

    # The units they contained are obsolete too
    assert not updated_store.units.exists()
    assert updated_store.unit_set.filter(state=OBSOLETE).exists()
Beispiel #6
0
def test_sync(project0_disk, store0):
    """Tests that the new on-disk file is created after sync for existing
    in-DB Store if the corresponding on-disk file ceased to exist.
    """
    tp = TranslationProjectFactory(project=project0_disk,
                                   language=LanguageDBFactory())
    store = StoreDBFactory(translation_project=tp, parent=tp.directory)

    store.update(store.deserialize(store0.serialize()))
    assert not store.file.exists()
    store.sync()
    assert store.file.exists()
    os.remove(store.file.path)
    assert not store.file.exists()
    store.sync()
    assert store.file.exists()
Beispiel #7
0
def param_update_store_test(request, tp0, member, member2):
    from tests.factories import StoreDBFactory

    store = StoreDBFactory(translation_project=tp0, parent=tp0.directory)
    test = _setup_store_test(store, member, UPDATE_STORE_TESTS[request.param])
    update_store(
        test["store"],
        units=test["units_in_file"],
        store_revision=test["store_revision"],
        user=member2,
    )
    return test
Beispiel #8
0
def store_po(tp0):
    """An empty Store in the /language0/project0 TP"""
    from pootle_translationproject.models import TranslationProject

    from tests.factories import StoreDBFactory

    tp = TranslationProject.objects.get(project__code="project0",
                                        language__code="language0")

    store = StoreDBFactory(parent=tp.directory,
                           translation_project=tp,
                           name="test_store.po")
    return store
Beispiel #9
0
def store_diff_tests(request, tp0, member):
    from tests.factories import StoreDBFactory
    from pootle_store.diff import StoreDiff

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

    test = _setup_store_test(store, member, UPDATE_STORE_TESTS[request.param])
    test_store = create_store(units=test["units_in_file"])

    return {
        "diff": StoreDiff(test["store"], test_store, test["store_revision"]),
        "store": test["store"],
        "units_in_file": test["units_in_file"],
        "store_revision": test["store_revision"],
    }
Beispiel #10
0
    def _add_stores(self, tp, n=(3, 2), parent=None):
        from tests.factories import StoreDBFactory, UnitDBFactory

        from pootle_store.constants import UNTRANSLATED, TRANSLATED, FUZZY, OBSOLETE

        for i_ in range(0, n[0]):
            # add 3 stores
            if parent is None:
                store = StoreDBFactory(translation_project=tp)
            else:
                store = StoreDBFactory(translation_project=tp, parent=parent)
            store.save()

            # add 8 units to each store
            for state in [UNTRANSLATED, TRANSLATED, FUZZY, OBSOLETE]:
                for i_ in range(0, n[1]):
                    UnitDBFactory(store=store, state=state)