Exemple #1
0
def vfolders():
    from pytest_pootle.factories import VirtualFolderDBFactory

    from django.db import connection
    from django.apps import apps

    from pootle.core.utils.db import set_mysql_collation_for_column

    cursor = connection.cursor()

    # VirtualFolderTreeItem
    set_mysql_collation_for_column(apps, cursor,
                                   "virtualfolder.VirtualFolderTreeItem",
                                   "pootle_path", "utf8_bin", "varchar(255)")

    # VirtualFolder
    set_mysql_collation_for_column(apps, cursor, "virtualfolder.VirtualFolder",
                                   "name", "utf8_bin", "varchar(70)")
    set_mysql_collation_for_column(apps, cursor, "virtualfolder.VirtualFolder",
                                   "location", "utf8_bin", "varchar(255)")

    VirtualFolderDBFactory(filter_rules="store0.po")
    VirtualFolderDBFactory(filter_rules="store1.po")
    VirtualFolderDBFactory(location='/{LANG}/project0/',
                           is_public=False,
                           filter_rules="store0.po")
    VirtualFolderDBFactory(location='/{LANG}/project0/',
                           is_public=False,
                           filter_rules="store1.po")
    VirtualFolderDBFactory(location='/language0/project0/',
                           filter_rules="subdir0/store4.po")
Exemple #2
0
    def setup_vfolders(self):
        from pytest_pootle.factories import VirtualFolderDBFactory

        from django.db import connection
        from django.apps import apps

        from pootle.core.utils.db import set_mysql_collation_for_column
        from pootle_language.models import Language
        from pootle_project.models import Project

        cursor = connection.cursor()

        # VirtualFolder
        set_mysql_collation_for_column(apps, cursor,
                                       "virtualfolder.VirtualFolder", "name",
                                       "utf8_bin", "varchar(70)")

        project0 = Project.objects.get(code="project0")
        language0 = Language.objects.get(code="language0")
        VirtualFolderDBFactory(filter_rules="store0.po")
        VirtualFolderDBFactory(filter_rules="store1.po")
        vf = VirtualFolderDBFactory(all_languages=True,
                                    is_public=False,
                                    filter_rules="store0.po")
        vf.projects.add(project0)
        vf.save()
        vf = VirtualFolderDBFactory(all_languages=True,
                                    is_public=False,
                                    filter_rules="store1.po")
        vf.projects.add(project0)
        vf.save()
        vf = VirtualFolderDBFactory(filter_rules="subdir0/store4.po")
        vf.languages.add(language0)
        vf.projects.add(project0)
        vf.save()
def test_vfolder_unit_priorities():

    # remove the default vfolders and update units to reset priorities
    VirtualFolder.objects.all().delete()
    [unit.save() for unit in Unit.objects.all()]

    assert all(
        priority == 1
        for priority
        in Unit.objects.values_list("priority", flat=True))

    vfolder0 = VirtualFolderDBFactory(filter_rules="store0.po", priority=3)

    assert all(
        priority == 3
        for priority
        in vfolder0.units.values_list("priority", flat=True))

    assert all(
        priority == 1.0
        for priority
        in Unit.objects.filter(vfolders__isnull=True)
                       .values_list("priority", flat=True))

    vfolder0.filter_rules = "store1.po"
    vfolder0.save()

    assert all(
        priority == 3
        for priority
        in vfolder0.units.values_list("priority", flat=True))

    assert all(
        priority == 1.0
        for priority
        in Unit.objects.filter(vfolders__isnull=True)
                       .values_list("priority", flat=True))

    vfolder1 = VirtualFolderDBFactory(
        location='/{LANG}/project0/',
        filter_rules="store1.po",
        priority=4)
    vf1_pks = vfolder1.units.values_list("pk", flat=True)

    assert all(
        priority == 4.0
        for priority
        in vfolder1.units.values_list("priority", flat=True))

    assert all(
        priority == 3.0
        for priority
        in vfolder0.units.exclude(pk__in=vf1_pks)
                         .values_list("priority", flat=True))

    assert all(
        priority == 1.0
        for priority
        in Unit.objects.filter(vfolders__isnull=True)
                       .values_list("priority", flat=True))
Exemple #4
0
    def setup_vfolders(self):
        from pytest_pootle.factories import VirtualFolderDBFactory

        VirtualFolderDBFactory(filter_rules="store0.po")
        VirtualFolderDBFactory(filter_rules="store1.po")
        VirtualFolderDBFactory(location='/{LANG}/project0/',
                               is_public=False,
                               filter_rules="store0.po")
        VirtualFolderDBFactory(location='/{LANG}/project0/',
                               is_public=False,
                               filter_rules="store1.po")
        VirtualFolderDBFactory(location='/language0/project0/',
                               filter_rules="subdir0/store4.po")
Exemple #5
0
def test_vfolder_calc_priority(settings, store0):
    vf = VirtualFolderDBFactory(filter_rules=store0.name)
    vf.priority = 5
    vf.save()
    assert store0.calculate_priority() == 5.0
    settings.INSTALLED_APPS.remove("virtualfolder")
    assert store0.calculate_priority() == 1.0
Exemple #6
0
def test_vfolder_store_priorities():

    # remove the default vfolders and update units to reset priorities
    VirtualFolder.objects.all().delete()
    [store.save() for store in Store.objects.all()]

    assert all(
        priority == 1
        for priority in Store.objects.values_list("priority", flat=True))

    vfolder0 = VirtualFolderDBFactory(filter_rules="store0.po")
    vfolder0.priority = 3
    vfolder0.save()
    vfolder0_stores = vfolder0.units.values_list("store", flat=True).distinct()
    assert all(priority == 3 for priority in Store.objects.filter(
        id__in=vfolder0_stores).values_list("priority", flat=True))
    assert all(priority == 1.0 for priority in Store.objects.exclude(
        id__in=vfolder0_stores).values_list("priority", flat=True))

    vfolder0.filter_rules = "store1.po"
    vfolder0.save()
    vfolder0_stores = vfolder0.units.values_list("store", flat=True).distinct()
    assert all(priority == 3 for priority in Store.objects.filter(
        id__in=vfolder0_stores).values_list("priority", flat=True))
    assert all(priority == 1.0 for priority in Store.objects.exclude(
        id__in=vfolder0_stores).values_list("priority", flat=True))

    vfolder1 = VirtualFolderDBFactory(location='/{LANG}/project0/',
                                      filter_rules="store1.po")
    vfolder1.priority = 4
    vfolder1.save()
    vfolder1_stores = vfolder1.units.values_list("store", flat=True).distinct()

    assert all(priority == 4.0 for priority in Store.objects.filter(
        id__in=vfolder1_stores).values_list("priority", flat=True))

    assert all(
        priority == 3.0
        for priority in Store.objects.filter(id__in=vfolder0_stores).exclude(
            id__in=vfolder1_stores).values_list("priority", flat=True))

    assert all(
        priority == 1.0
        for priority in Store.objects.exclude(id__in=vfolder0_stores).exclude(
            id__in=vfolder1_stores).values_list("priority", flat=True))
Exemple #7
0
def test_vfolder_store_priorities(project0):

    # remove the default vfolders and update units to reset priorities
    VirtualFolder.objects.all().delete()
    assert all(
        priority == 1
        for priority in Store.objects.values_list("priority", flat=True))

    vfolder0 = VirtualFolderDBFactory(filter_rules="store0.po", name="FOO")
    vfolder0.priority = 3
    vfolder0.save()
    vfolder0_stores = vfolder0.stores.values_list("pk", flat=True)
    assert all(priority == 3 for priority in Store.objects.filter(
        id__in=vfolder0_stores).values_list("priority", flat=True))
    assert all(priority == 1.0 for priority in Store.objects.exclude(
        id__in=vfolder0_stores).values_list("priority", flat=True))

    vfolder0.filter_rules = "store1.po"
    vfolder0.save()
    vfolder0_stores = vfolder0.stores.values_list("pk", flat=True)
    assert all(priority == 3 for priority in Store.objects.filter(
        id__in=vfolder0_stores).values_list("priority", flat=True))
    assert all(priority == 1.0 for priority in Store.objects.exclude(
        id__in=vfolder0_stores).values_list("priority", flat=True))

    vfolder1 = VirtualFolderDBFactory(filter_rules="store1.po")
    vfolder1.languages.add(*Language.objects.all())
    vfolder1.projects.add(project0)
    vfolder1.priority = 4
    vfolder1.save()
    vfolder1_stores = vfolder1.stores.values_list("pk", flat=True)

    assert all(priority == 4.0 for priority in Store.objects.filter(
        id__in=vfolder1_stores).values_list("priority", flat=True))

    assert all(
        priority == 3.0
        for priority in Store.objects.filter(id__in=vfolder0_stores).exclude(
            id__in=vfolder1_stores).values_list("priority", flat=True))

    assert all(
        priority == 1.0
        for priority in Store.objects.exclude(id__in=vfolder0_stores).exclude(
            id__in=vfolder1_stores).values_list("priority", flat=True))
def test_vfolder_membership():

    vfolder = VirtualFolderDBFactory(filter_rules="store0.po")

    live_units = Unit.objects.filter(state__gt=OBSOLETE)

    expected_units = live_units.filter(store__name="store0.po")

    # check default vfolder membership
    assert (
        sorted(vfolder.units.values_list("pk", flat=True))
        == sorted(expected_units.values_list("pk", flat=True)))

    vfolder.location = "/language0/{PROJ}/"
    vfolder.save()

    expected_units = live_units.filter(
        store__translation_project__language__code="language0",
        store__name="store0.po")

    # check vfolder membership after changing the location
    assert (
        sorted(vfolder.units.values_list("pk", flat=True))
        == sorted(expected_units.values_list("pk", flat=True)))

    obsolete_unit = (
        Unit.objects.filter(
            state=OBSOLETE,
            store__translation_project__language__code="language0",
            store__name="store0.po"))[0]

    # obsolete unit is not in the vfolder
    assert obsolete_unit not in vfolder.units.all()

    obsolete_unit.state = TRANSLATED
    obsolete_unit.save()

    # unobsoleted unit is in the vfolder
    assert obsolete_unit in vfolder.units.all()

    to_obsolete = vfolder.units.all()[0]
    to_obsolete.state = OBSOLETE
    to_obsolete.save()

    # obsoleted unit is not in the vfolder
    assert to_obsolete not in vfolder.units.all()
Exemple #9
0
def test_virtualfolder_repr():
    vf = VirtualFolderDBFactory(filter_rules="store0.po")
    assert ("<VirtualFolder: %s>" % (vf.name) == repr(vf))