Пример #1
0
def test_projectlocale_latest_activity_success(translation_a):
    """
    If the matching ProjectLocale has a latest_translation, return
    it's latest_activity.
    """
    project = translation_a.entity.resource.project
    locale = translation_a.locale
    assert ProjectLocale.get_latest_activity(project, locale)
    assert (ProjectLocale.get_latest_activity(
        project, locale) == translation_a.latest_activity)
Пример #2
0
def test_projectlocale_latest_activity_success(translation_a):
    """
    If the matching ProjectLocale has a latest_translation, return
    it's latest_activity.
    """
    project = translation_a.entity.resource.project
    locale = translation_a.locale
    assert ProjectLocale.get_latest_activity(project, locale)
    assert (
        ProjectLocale.get_latest_activity(project, locale)
        == translation_a.latest_activity
    )
Пример #3
0
 def test_get_latest_activity_doesnt_exist(self):
     """
     If no ProjectLocale exists with the given project/locale,
     return None.
     """
     assert_false(ProjectLocale.objects.filter(project=self.project, locale=self.locale).exists())
     assert_is_none(ProjectLocale.get_latest_activity(self.project, self.locale))
Пример #4
0
def test_projectlocale_latest_activity_no_latest(project_a, locale_a):
    """
    If the matching ProjectLocale has no latest_translation, return
    None.
    """
    ProjectLocaleFactory.create(project=project_a, locale=locale_a)
    assert ProjectLocale.get_latest_activity(project_a, locale_a) is None
Пример #5
0
def test_projectlocale_latest_activity_no_latest(projectX, localeX):
    """
    If the matching ProjectLocale has no latest_translation, return
    None.
    """
    ProjectLocale.objects.create(project=projectX, locale=localeX)
    assert (ProjectLocale.get_latest_activity(projectX, localeX) is None)
Пример #6
0
def test_projectlocale_latest_activity_no_latest(project_a, locale_a):
    """
    If the matching ProjectLocale has no latest_translation, return
    None.
    """
    ProjectLocaleFactory.create(project=project_a, locale=locale_a)
    assert ProjectLocale.get_latest_activity(project_a, locale_a) is None
Пример #7
0
    def test_get_latest_activity_no_latest(self):
        """
        If the matching ProjectLocale has no latest_translation, return
        None.
        """
        ProjectLocaleFactory.create(project=self.project, locale=self.locale, latest_translation=None)

        assert_is_none(ProjectLocale.get_latest_activity(self.project, self.locale))
Пример #8
0
def test_projectlocale_latest_activity_doesnt_exist(project_a, locale_a):
    """
    If no ProjectLocale exists with the given project/locale,
    return None.
    """
    assert not (ProjectLocale.objects.filter(project=project_a,
                                             locale=locale_a).exists())
    assert ProjectLocale.get_latest_activity(project_a, locale_a) is None
Пример #9
0
    def test_get_latest_activity_success(self):
        """
        If the matching ProjectLocale has a latest_translation, return
        it's latest_activity.
        """
        translation = TranslationFactory.create(locale=self.locale, entity__resource__project=self.project)
        ProjectLocaleFactory.create(project=self.project, locale=self.locale, latest_translation=translation)

        assert_equal(ProjectLocale.get_latest_activity(self.project, self.locale), translation.latest_activity)
Пример #10
0
 def test_get_latest_activity_doesnt_exist(self):
     """
     If no ProjectLocale exists with the given project/locale,
     return None.
     """
     assert_false(
         ProjectLocale.objects.filter(project=self.project,
                                      locale=self.locale).exists())
     assert_is_none(
         ProjectLocale.get_latest_activity(self.project, self.locale))
Пример #11
0
    def test_get_latest_activity_no_latest(self):
        """
        If the matching ProjectLocale has no latest_translation, return
        None.
        """
        ProjectLocaleFactory.create(project=self.project,
                                    locale=self.locale,
                                    latest_translation=None)

        assert_is_none(
            ProjectLocale.get_latest_activity(self.project, self.locale))
Пример #12
0
def test_projectlocale_latest_activity_doesnt_exist(project_a, locale_a):
    """
    If no ProjectLocale exists with the given project/locale,
    return None.
    """
    assert not (
        ProjectLocale.objects
        .filter(project=project_a, locale=locale_a)
        .exists()
    )
    assert ProjectLocale.get_latest_activity(project_a, locale_a) is None
Пример #13
0
    def test_get_latest_activity_success(self):
        """
        If the matching ProjectLocale has a latest_translation, return
        it's latest_activity.
        """
        translation = TranslationFactory.create(
            locale=self.locale, entity__resource__project=self.project)
        ProjectLocaleFactory.create(project=self.project,
                                    locale=self.locale,
                                    latest_translation=translation)

        assert_equal(
            ProjectLocale.get_latest_activity(self.project, self.locale),
            translation.latest_activity)
Пример #14
0
def test_localization_filters(
    include_disabled,
    include_system,
    is_admin,
    locale_a,
    regular_projects,
    disabled_projects,
    system_projects,
    private_projects,
    client,
    admin,
):
    expected_projects = set(regular_projects +
                            (disabled_projects if include_disabled else []) +
                            (system_projects if include_system else []) +
                            (private_projects if is_admin else []))
    ProjectLocale.objects.bulk_create([
        ProjectLocale(project=p, locale=locale_a) for p in expected_projects
        if p.slug not in ("pontoon-intro", "tutorial", "terminology")
    ])

    body = {
        "query":
        """{{
            locale (code: \"{locale_code}\") {{
                localizations(includeDisabled: {include_disabled}, includeSystem: {include_system}) {{
                    project {{
                        slug,
                        disabled,
                        systemProject,
                        visibility
                    }}
                }}
            }}
        }}""".format(
            locale_code=locale_a.code,
            include_disabled=str(include_disabled).lower(),
            include_system=str(include_system).lower(),
        )
    }

    if is_admin:
        client.force_login(admin)

    response = client.get("/graphql", body, HTTP_ACCEPT="application/json")

    assert response.status_code == 200
    assert response.json() == {
        "data": {
            "locale": {
                "localizations": [{
                    "project": {
                        "slug": p.slug,
                        "visibility": p.visibility,
                        "systemProject": p.system_project,
                        "disabled": p.disabled,
                    }
                } for p in sorted(
                    expected_projects,
                    key=lambda p: p.project_locale.filter(locale=locale_a)[0].
                    pk,
                )]
            }
        }
    }