Esempio n. 1
0
    def test_parts_stats_pages_tied_to_resources(self):
        """
        Return subpage name and stats for locales resources are available for.
        """
        resource_other = ResourceFactory.create(project=self.project,
                                                path='/other/path.po')
        EntityFactory.create(resource=resource_other)
        TranslatedResourceFactory.create(resource=resource_other,
                                         locale=self.locale)
        TranslatedResourceFactory.create(resource=resource_other,
                                         locale=self.locale_other)
        SubpageFactory.create(project=self.project,
                              name='Subpage',
                              resources=[self.resource])
        SubpageFactory.create(project=self.project,
                              name='Other Subpage',
                              resources=[resource_other])

        details = self.locale.parts_stats(self.project)
        details_other = self.locale_other.parts_stats(self.project)

        assert_equal(details[0]['title'], 'Other Subpage')
        assert_equal(details[0]['translated_strings'], 0)
        assert_equal(details[1]['title'], 'Subpage')
        assert_equal(details[1]['translated_strings'], 0)
        assert_equal(details_other[0]['title'], 'Other Subpage')
        assert_equal(details_other[0]['translated_strings'], 0)
Esempio n. 2
0
    def test_parts_stats_pages_tied_to_resources(self):
        """
        Return subpage name and stats for locales resources are available for.
        """
        resource_other = ResourceFactory.create(
            project=self.project,
            path='/other/path.po'
        )
        EntityFactory.create(resource=resource_other)
        TranslatedResourceFactory.create(resource=resource_other, locale=self.locale)
        TranslatedResourceFactory.create(resource=resource_other, locale=self.locale_other)
        SubpageFactory.create(
            project=self.project,
            name='Subpage',
            resources=[self.resource]
        )
        SubpageFactory.create(
            project=self.project,
            name='Other Subpage',
            resources=[resource_other]
        )

        details = self.locale.parts_stats(self.project)
        details_other = self.locale_other.parts_stats(self.project)

        assert_equal(details[0]['title'], 'Other Subpage')
        assert_equal(details[0]['translated_strings'], 0)
        assert_equal(details[1]['title'], 'Subpage')
        assert_equal(details[1]['translated_strings'], 0)
        assert_equal(details_other[0]['title'], 'Other Subpage')
        assert_equal(details_other[0]['translated_strings'], 0)
Esempio n. 3
0
 def setUp(self):
     self.locale, self.locale_other = LocaleFactory.create_batch(2)
     self.project = ProjectFactory.create(
         locales=[self.locale, self.locale_other])
     self.resource = ResourceFactory.create(project=self.project,
                                            path='/main/path.po')
     EntityFactory.create(resource=self.resource)
     TranslatedResourceFactory.create(resource=self.resource,
                                      locale=self.locale)
Esempio n. 4
0
 def setUp(self):
     self.locale, self.locale_other = LocaleFactory.create_batch(2)
     self.project = ProjectFactory.create(
         locales=[self.locale, self.locale_other]
     )
     self.resource = ResourceFactory.create(
         project=self.project,
         path='/main/path.po'
     )
     EntityFactory.create(resource=self.resource)
     TranslatedResourceFactory.create(resource=self.resource, locale=self.locale)
Esempio n. 5
0
    def test_not_authed_public_project(self):
        """
        If the user is not authenticated and we're translating project
        ID 1, return a 200.
        """
        # Clear out existing project with ID=1 if necessary.
        Project.objects.filter(id=1).delete()
        locale = LocaleFactory.create(code='fakelocale')
        project = ProjectFactory.create(id=1, slug='valid-project', locales=[locale])
        resource = ResourceFactory.create(project=project, path='foo.lang', total_strings=1)
        TranslatedResourceFactory.create(resource=resource, locale=locale)

        response = self.client.get('/fakelocale/valid-project/foo.lang/')
        assert_equal(response.status_code, 200)
Esempio n. 6
0
    def test_save_latest_translation_update(self):
        """
        When a translation is saved, update the latest_translation
        attribute on the related project, locale, translatedresource,
        and project_locale objects.
        """
        locale = LocaleFactory.create(latest_translation=None)
        project = ProjectFactory.create(locales=[locale],
                                        latest_translation=None)
        resource = ResourceFactory.create(project=project)
        translatedresource = TranslatedResourceFactory.create(
            locale=locale, resource=resource, latest_translation=None)
        project_locale = ProjectLocale.objects.get(locale=locale,
                                                   project=project)

        assert_is_none(locale.latest_translation)
        assert_is_none(project.latest_translation)
        assert_is_none(translatedresource.latest_translation)
        assert_is_none(project_locale.latest_translation)

        translation = TranslationFactory.create(locale=locale,
                                                entity__resource=resource,
                                                date=aware_datetime(
                                                    1970, 1, 1))
        self.assert_latest_translation(locale, translation)
        self.assert_latest_translation(project, translation)
        self.assert_latest_translation(translatedresource, translation)
        self.assert_latest_translation(project_locale, translation)

        # Ensure translation is replaced for newer translations
        newer_translation = TranslationFactory.create(
            locale=locale,
            entity__resource=resource,
            date=aware_datetime(1970, 2, 1))
        self.assert_latest_translation(locale, newer_translation)
        self.assert_latest_translation(project, newer_translation)
        self.assert_latest_translation(translatedresource, newer_translation)
        self.assert_latest_translation(project_locale, newer_translation)

        # Ensure translation isn't replaced for older translations.
        TranslationFactory.create(locale=locale,
                                  entity__resource=resource,
                                  date=aware_datetime(1970, 1, 5))
        self.assert_latest_translation(locale, newer_translation)
        self.assert_latest_translation(project, newer_translation)
        self.assert_latest_translation(translatedresource, newer_translation)
        self.assert_latest_translation(project_locale, newer_translation)

        # Ensure approved_date is taken into consideration as well.
        newer_approved_translation = TranslationFactory.create(
            locale=locale,
            entity__resource=resource,
            approved_date=aware_datetime(1970, 3, 1))
        self.assert_latest_translation(locale, newer_approved_translation)
        self.assert_latest_translation(project, newer_approved_translation)
        self.assert_latest_translation(translatedresource,
                                       newer_approved_translation)
        self.assert_latest_translation(project_locale,
                                       newer_approved_translation)
Esempio n. 7
0
    def test_save_latest_translation_update(self):
        """
        When a translation is saved, update the latest_translation
        attribute on the related project, locale, translatedresource,
        and project_locale objects.
        """
        locale = LocaleFactory.create(latest_translation=None)
        project = ProjectFactory.create(locales=[locale], latest_translation=None)
        resource = ResourceFactory.create(project=project)
        translatedresource = TranslatedResourceFactory.create(locale=locale, resource=resource, latest_translation=None)
        project_locale = ProjectLocale.objects.get(locale=locale, project=project)

        assert_is_none(locale.latest_translation)
        assert_is_none(project.latest_translation)
        assert_is_none(translatedresource.latest_translation)
        assert_is_none(project_locale.latest_translation)

        translation = TranslationFactory.create(
            locale=locale,
            entity__resource=resource,
            date=aware_datetime(1970, 1, 1)
        )
        self.assert_latest_translation(locale, translation)
        self.assert_latest_translation(project, translation)
        self.assert_latest_translation(translatedresource, translation)
        self.assert_latest_translation(project_locale, translation)

        # Ensure translation is replaced for newer translations
        newer_translation = TranslationFactory.create(
            locale=locale,
            entity__resource=resource,
            date=aware_datetime(1970, 2, 1)
        )
        self.assert_latest_translation(locale, newer_translation)
        self.assert_latest_translation(project, newer_translation)
        self.assert_latest_translation(translatedresource, newer_translation)
        self.assert_latest_translation(project_locale, newer_translation)

        # Ensure translation isn't replaced for older translations.
        TranslationFactory.create(
            locale=locale,
            entity__resource=resource,
            date=aware_datetime(1970, 1, 5)
        )
        self.assert_latest_translation(locale, newer_translation)
        self.assert_latest_translation(project, newer_translation)
        self.assert_latest_translation(translatedresource, newer_translation)
        self.assert_latest_translation(project_locale, newer_translation)

        # Ensure approved_date is taken into consideration as well.
        newer_approved_translation = TranslationFactory.create(
            locale=locale,
            entity__resource=resource,
            approved_date=aware_datetime(1970, 3, 1)
        )
        self.assert_latest_translation(locale, newer_approved_translation)
        self.assert_latest_translation(project, newer_approved_translation)
        self.assert_latest_translation(translatedresource, newer_approved_translation)
        self.assert_latest_translation(project_locale, newer_approved_translation)
Esempio n. 8
0
    def test_parts_stats_no_page_multiple_resources(self):
        """
        Return resource paths and stats for locales resources are available for.
        """
        resource_other = ResourceFactory.create(project=self.project,
                                                path='/other/path.po')
        EntityFactory.create(resource=resource_other)
        TranslatedResourceFactory.create(resource=resource_other,
                                         locale=self.locale)
        TranslatedResourceFactory.create(resource=resource_other,
                                         locale=self.locale_other)

        details = self.locale.parts_stats(self.project)
        details_other = self.locale_other.parts_stats(self.project)

        assert_equal(details[0]['title'], '/main/path.po')
        assert_equal(details[0]['translated_strings'], 0)
        assert_equal(details[1]['title'], '/other/path.po')
        assert_equal(details[1]['translated_strings'], 0)
        assert_equal(len(details_other), 1)
        assert_equal(details_other[0]['title'], '/other/path.po')
        assert_equal(details_other[0]['translated_strings'], 0)
Esempio n. 9
0
    def test_parts_stats_no_page_multiple_resources(self):
        """
        Return resource paths and stats for locales resources are available for.
        """
        resource_other = ResourceFactory.create(
            project=self.project,
            path='/other/path.po'
        )
        EntityFactory.create(resource=resource_other)
        TranslatedResourceFactory.create(resource=resource_other, locale=self.locale)
        TranslatedResourceFactory.create(resource=resource_other, locale=self.locale_other)

        details = self.locale.parts_stats(self.project)
        details_other = self.locale_other.parts_stats(self.project)

        assert_equal(details[0]['title'], '/main/path.po')
        assert_equal(details[0]['translated_strings'], 0)
        assert_equal(details[1]['title'], '/other/path.po')
        assert_equal(details[1]['translated_strings'], 0)
        assert_equal(len(details_other), 1)
        assert_equal(details_other[0]['title'], '/other/path.po')
        assert_equal(details_other[0]['translated_strings'], 0)
Esempio n. 10
0
    def test_save_latest_translation_missing_project_locale(self):
        """
        If a translation is saved for a locale that isn't active on the
        project, do not fail due to a missing ProjectLocale.
        """
        locale = LocaleFactory.create(latest_translation=None)
        project = ProjectFactory.create(latest_translation=None)
        resource = ResourceFactory.create(project=project)
        translatedresource = TranslatedResourceFactory.create(locale=locale, resource=resource, latest_translation=None)

        # This calls .save, this should fail if we're not properly
        # handling the missing ProjectLocale.
        translation = TranslationFactory.create(
            locale=locale,
            entity__resource=resource,
            date=aware_datetime(1970, 1, 1)
        )

        self.assert_latest_translation(locale, translation)
        self.assert_latest_translation(project, translation)
        self.assert_latest_translation(translatedresource, translation)
Esempio n. 11
0
    def test_save_latest_translation_missing_project_locale(self):
        """
        If a translation is saved for a locale that isn't active on the
        project, do not fail due to a missing ProjectLocale.
        """
        locale = LocaleFactory.create(latest_translation=None)
        project = ProjectFactory.create(latest_translation=None)
        resource = ResourceFactory.create(project=project)
        translatedresource = TranslatedResourceFactory.create(
            locale=locale, resource=resource, latest_translation=None)

        # This calls .save, this should fail if we're not properly
        # handling the missing ProjectLocale.
        translation = TranslationFactory.create(locale=locale,
                                                entity__resource=resource,
                                                date=aware_datetime(
                                                    1970, 1, 1))

        self.assert_latest_translation(locale, translation)
        self.assert_latest_translation(project, translation)
        self.assert_latest_translation(translatedresource, translation)
Esempio n. 12
0
def test_latest_activity(mock_parts_stats, mock_render, client, project_a,
                         locale_a):
    """Ensure that the latest_activity field is added to parts."""
    resource = ResourceFactory.create(project=project_a, path='has/stats.po')
    resource2 = ResourceFactory.create(project=project_a, path='has/stats2.po')

    translation = TranslationFactory.create(entity__resource=resource,
                                            locale=locale_a)
    TranslatedResourceFactory.create(resource=resource2,
                                     locale=locale_a,
                                     latest_translation=translation)

    mock_parts_stats.return_value = [{
        'title': 'has/stats.po',
        'resource__path': 'has/stats.po',
        'resource__total_strings': 1,
        'approved_strings': 0,
        'unreviewed_strings': 1,
        'fuzzy_strings': 0,
        'strings_with_warnings': 0,
        'strings_with_errors': 0,
        'resource__deadline': None,
        'resource__priority': None,
    }, {
        'title': 'no/stats.po',
        'resource__path': 'no/stats.po',
        'resource__total_strings': 1,
        'approved_strings': 0,
        'unreviewed_strings': 0,
        'fuzzy_strings': 0,
        'strings_with_warnings': 0,
        'strings_with_errors': 0,
        'resource__deadline': None,
        'resource__priority': None,
    }]

    client.get(reverse(
        'pontoon.localizations.ajax.resources',
        args=[locale_a.code, project_a.slug],
    ),
               HTTP_X_REQUESTED_WITH='XMLHttpRequest')

    ctx = mock_render.call_args[0][2]

    assert ctx['resources'] == [{
        'latest_activity': translation.latest_activity,
        'title': 'has/stats.po',
        'resource__path': 'has/stats.po',
        'resource__deadline': None,
        'resource__priority': None,
        'resource__total_strings': 1,
        'approved_strings': 0,
        'unreviewed_strings': 1,
        'fuzzy_strings': 0,
        'strings_with_errors': 0,
        'strings_with_warnings': 0,
        'chart': {
            'fuzzy_strings': 0,
            'total_strings': 1,
            'approved_strings': 0,
            'unreviewed_strings': 1,
            'strings_with_errors': 0,
            'strings_with_warnings': 0,
            'approved_share': 0.0,
            'unreviewed_share': 100.0,
            'fuzzy_share': 0.0,
            'warnings_share': 0.0,
            'errors_share': 0.0,
            'completion_percent': 0,
        }
    }, {
        'latest_activity': None,
        'title': 'no/stats.po',
        'resource__path': 'no/stats.po',
        'resource__deadline': None,
        'resource__priority': None,
        'resource__total_strings': 1,
        'approved_strings': 0,
        'unreviewed_strings': 0,
        'fuzzy_strings': 0,
        'strings_with_errors': 0,
        'strings_with_warnings': 0,
        'chart': {
            'fuzzy_strings': 0,
            'total_strings': 1,
            'approved_strings': 0,
            'unreviewed_strings': 0,
            'strings_with_errors': 0,
            'strings_with_warnings': 0,
            'approved_share': 0.0,
            'unreviewed_share': 0.0,
            'fuzzy_share': 0.0,
            'warnings_share': 0.0,
            'errors_share': 0.0,
            'completion_percent': 0,
        }
    }]
Esempio n. 13
0
    def test_latest_activity(self):
        """Ensure that the latest_activity field is added to parts."""
        locale = LocaleFactory.create(code='test')
        project = ProjectFactory.create(locales=[locale], slug='test-project')
        resource = ResourceFactory.create(project=project, path='has/stats.po')
        translation = TranslationFactory.create(entity__resource=resource, locale=locale)
        TranslatedResourceFactory.create(resource=resource, locale=locale, latest_translation=translation)

        with patch.object(Locale, 'parts_stats') as mock_parts_stats, \
                patch('pontoon.base.views.render') as mock_render:
            mock_parts_stats.return_value = [
                {
                    'title': 'has/stats.po',
                    'resource__path': 'has/stats.po',
                    'resource__total_strings': 1,
                    'approved_strings': 0,
                    'translated_strings': 1,
                    'fuzzy_strings': 0,
                },
                {
                    'title': 'no/stats.po',
                    'resource__path': 'no/stats.po',
                    'resource__total_strings': 1,
                    'approved_strings': 0,
                    'translated_strings': 0,
                    'fuzzy_strings': 0,
                }
            ]

            views.locale_project(self.factory.get('/'), locale='test', slug='test-project')
            ctx = mock_render.call_args[0][2]
            assert_equal(ctx['parts'], [
                {
                    'latest_activity': translation.latest_activity,
                    'title': 'has/stats.po',
                    'resource__path': 'has/stats.po',
                    'resource__total_strings': 1,
                    'approved_strings': 0,
                    'translated_strings': 1,
                    'fuzzy_strings': 0,
                    'chart': {
                        'fuzzy_strings': 0,
                        'total_strings': 1,
                        'approved_strings': 0,
                        'translated_strings': 1,
                        'approved_share': 0.0,
                        'translated_share': 100.0,
                        'fuzzy_share': 0.0,
                        'approved_percent': 0
                    }
                },
                {
                    'latest_activity': None,
                    'title': 'no/stats.po',
                    'resource__path': 'no/stats.po',
                    'resource__total_strings': 1,
                    'approved_strings': 0,
                    'translated_strings': 0,
                    'fuzzy_strings': 0,
                    'chart': {
                        'fuzzy_strings': 0,
                        'total_strings': 1,
                        'approved_strings': 0,
                        'translated_strings': 0,
                        'approved_share': 0.0,
                        'translated_share': 0.0,
                        'fuzzy_share': 0.0,
                        'approved_percent': 0
                    }
                }
            ])
Esempio n. 14
0
    def test_latest_activity(self):
        """Ensure that the latest_activity field is added to parts."""
        locale = LocaleFactory.create(code='test')
        project = ProjectFactory.create(locales=[locale], slug='test-project')
        resource = ResourceFactory.create(project=project, path='has/stats.po')
        translation = TranslationFactory.create(entity__resource=resource,
                                                locale=locale)
        TranslatedResourceFactory.create(resource=resource,
                                         locale=locale,
                                         latest_translation=translation)

        with patch.object(Locale, 'parts_stats') as mock_parts_stats, \
                patch('pontoon.base.views.render') as mock_render:
            mock_parts_stats.return_value = [{
                'title': 'has/stats.po',
                'resource__path': 'has/stats.po',
                'resource__total_strings': 1,
                'approved_strings': 0,
                'translated_strings': 1,
                'fuzzy_strings': 0,
            }, {
                'title': 'no/stats.po',
                'resource__path': 'no/stats.po',
                'resource__total_strings': 1,
                'approved_strings': 0,
                'translated_strings': 0,
                'fuzzy_strings': 0,
            }]

            views.locale_project(self.factory.get('/'),
                                 locale='test',
                                 slug='test-project')
            ctx = mock_render.call_args[0][2]
            assert_equal(ctx['parts'], [{
                'latest_activity': translation,
                'title': 'has/stats.po',
                'resource__path': 'has/stats.po',
                'resource__total_strings': 1,
                'approved_strings': 0,
                'translated_strings': 1,
                'fuzzy_strings': 0,
                'chart': {
                    'fuzzy_strings': 0,
                    'total_strings': 1,
                    'approved_strings': 0,
                    'translated_strings': 1,
                    'approved_share': 0.0,
                    'translated_share': 100.0,
                    'fuzzy_share': 0.0,
                    'approved_percent': 0
                }
            }, {
                'latest_activity': None,
                'title': 'no/stats.po',
                'resource__path': 'no/stats.po',
                'resource__total_strings': 1,
                'approved_strings': 0,
                'translated_strings': 0,
                'fuzzy_strings': 0,
                'chart': {
                    'fuzzy_strings': 0,
                    'total_strings': 1,
                    'approved_strings': 0,
                    'translated_strings': 0,
                    'approved_share': 0.0,
                    'translated_share': 0.0,
                    'fuzzy_share': 0.0,
                    'approved_percent': 0
                }
            }])
Esempio n. 15
0
def test_latest_activity(mock_parts_stats, mock_render, client, project_a, locale_a):
    """Ensure that the latest_activity field is added to parts."""
    resource = ResourceFactory.create(project=project_a, path='has/stats.po')
    resource2 = ResourceFactory.create(project=project_a, path='has/stats2.po')

    translation = TranslationFactory.create(entity__resource=resource, locale=locale_a)
    TranslatedResourceFactory.create(
        resource=resource2, locale=locale_a, latest_translation=translation
    )

    mock_parts_stats.return_value = [
        {
            'title': 'has/stats.po',
            'resource__path': 'has/stats.po',
            'resource__total_strings': 1,
            'approved_strings': 0,
            'unreviewed_strings': 1,
            'fuzzy_strings': 0,
            'strings_with_warnings': 0,
            'strings_with_errors': 0,
            'resource__deadline': None,
            'resource__priority': None,
        },
        {
            'title': 'no/stats.po',
            'resource__path': 'no/stats.po',
            'resource__total_strings': 1,
            'approved_strings': 0,
            'unreviewed_strings': 0,
            'fuzzy_strings': 0,
            'strings_with_warnings': 0,
            'strings_with_errors': 0,
            'resource__deadline': None,
            'resource__priority': None,
        }
    ]

    client.get(
        reverse(
            'pontoon.localizations.ajax.resources',
            args=[
                locale_a.code,
                project_a.slug
            ],
        ),
        HTTP_X_REQUESTED_WITH='XMLHttpRequest'
    )

    ctx = mock_render.call_args[0][2]

    assert ctx['resources'] == [
        {
            'latest_activity': translation.latest_activity,
            'title': 'has/stats.po',
            'resource__path': 'has/stats.po',
            'resource__deadline': None,
            'resource__priority': None,
            'resource__total_strings': 1,
            'approved_strings': 0,
            'unreviewed_strings': 1,
            'fuzzy_strings': 0,
            'strings_with_errors': 0,
            'strings_with_warnings': 0,
            'chart': {
                'fuzzy_strings': 0,
                'total_strings': 1,
                'approved_strings': 0,
                'unreviewed_strings': 1,
                'strings_with_errors': 0,
                'strings_with_warnings': 0,
                'approved_share': 0.0,
                'unreviewed_share': 100.0,
                'fuzzy_share': 0.0,
                'warnings_share': 0.0,
                'errors_share': 0.0,
                'completion_percent': 0,
            }
        },
        {
            'latest_activity': None,
            'title': 'no/stats.po',
            'resource__path': 'no/stats.po',
            'resource__deadline': None,
            'resource__priority': None,
            'resource__total_strings': 1,
            'approved_strings': 0,
            'unreviewed_strings': 0,
            'fuzzy_strings': 0,
            'strings_with_errors': 0,
            'strings_with_warnings': 0,
            'chart': {
                'fuzzy_strings': 0,
                'total_strings': 1,
                'approved_strings': 0,
                'unreviewed_strings': 0,
                'strings_with_errors': 0,
                'strings_with_warnings': 0,
                'approved_share': 0.0,
                'unreviewed_share': 0.0,
                'fuzzy_share': 0.0,
                'warnings_share': 0.0,
                'errors_share': 0.0,
                'completion_percent': 0,
            }
        }
    ]
Esempio n. 16
0
def test_latest_activity(mock_parts_stats, mock_render, client, project_a,
                         locale_a):
    """Ensure that the latest_activity field is added to parts."""
    resource = ResourceFactory.create(project=project_a, path="has/stats.po")
    resource2 = ResourceFactory.create(project=project_a, path="has/stats2.po")

    translation = TranslationFactory.create(entity__resource=resource,
                                            locale=locale_a)
    TranslatedResourceFactory.create(resource=resource2,
                                     locale=locale_a,
                                     latest_translation=translation)

    mock_parts_stats.return_value = [
        {
            "title": "has/stats.po",
            "resource__path": "has/stats.po",
            "resource__total_strings": 1,
            "approved_strings": 0,
            "unreviewed_strings": 1,
            "fuzzy_strings": 0,
            "strings_with_warnings": 0,
            "strings_with_errors": 0,
            "resource__deadline": None,
            "resource__priority": None,
        },
        {
            "title": "no/stats.po",
            "resource__path": "no/stats.po",
            "resource__total_strings": 1,
            "approved_strings": 0,
            "unreviewed_strings": 0,
            "fuzzy_strings": 0,
            "strings_with_warnings": 0,
            "strings_with_errors": 0,
            "resource__deadline": None,
            "resource__priority": None,
        },
    ]

    client.get(
        reverse(
            "pontoon.localizations.ajax.resources",
            args=[locale_a.code, project_a.slug],
        ),
        HTTP_X_REQUESTED_WITH="XMLHttpRequest",
    )

    ctx = mock_render.call_args[0][2]

    assert ctx["resources"] == [
        {
            "latest_activity": translation.latest_activity,
            "title": "has/stats.po",
            "resource__path": "has/stats.po",
            "resource__deadline": None,
            "resource__priority": None,
            "resource__total_strings": 1,
            "approved_strings": 0,
            "unreviewed_strings": 1,
            "fuzzy_strings": 0,
            "strings_with_errors": 0,
            "strings_with_warnings": 0,
            "chart": {
                "fuzzy_strings": 0,
                "total_strings": 1,
                "approved_strings": 0,
                "unreviewed_strings": 1,
                "strings_with_errors": 0,
                "strings_with_warnings": 0,
                "approved_share": 0.0,
                "unreviewed_share": 100.0,
                "fuzzy_share": 0.0,
                "warnings_share": 0.0,
                "errors_share": 0.0,
                "completion_percent": 0,
            },
        },
        {
            "latest_activity": None,
            "title": "no/stats.po",
            "resource__path": "no/stats.po",
            "resource__deadline": None,
            "resource__priority": None,
            "resource__total_strings": 1,
            "approved_strings": 0,
            "unreviewed_strings": 0,
            "fuzzy_strings": 0,
            "strings_with_errors": 0,
            "strings_with_warnings": 0,
            "chart": {
                "fuzzy_strings": 0,
                "total_strings": 1,
                "approved_strings": 0,
                "unreviewed_strings": 0,
                "strings_with_errors": 0,
                "strings_with_warnings": 0,
                "approved_share": 0.0,
                "unreviewed_share": 0.0,
                "fuzzy_share": 0.0,
                "warnings_share": 0.0,
                "errors_share": 0.0,
                "completion_percent": 0,
            },
        },
    ]
Esempio n. 17
0
    def test_latest_activity(self):
        """Ensure that the latest_activity field is added to parts."""
        locale = LocaleFactory.create(code='test')
        project = ProjectFactory.create(locales=[locale], slug='test-project')
        resource = ResourceFactory.create(project=project, path='has/stats.po')
        resource2 = ResourceFactory.create(project=project,
                                           path='has/stats2.po')

        translation = TranslationFactory.create(entity__resource=resource,
                                                locale=locale)
        TranslatedResourceFactory.create(resource=resource2,
                                         locale=locale,
                                         latest_translation=translation)

        with patch.object(Locale, 'parts_stats') as mock_parts_stats, \
                patch('pontoon.localizations.views.render') as mock_render:
            mock_parts_stats.return_value = [{
                'title': 'has/stats.po',
                'resource__path': 'has/stats.po',
                'resource__total_strings': 1,
                'approved_strings': 0,
                'unreviewed_strings': 1,
                'fuzzy_strings': 0,
            }, {
                'title': 'no/stats.po',
                'resource__path': 'no/stats.po',
                'resource__total_strings': 1,
                'approved_strings': 0,
                'unreviewed_strings': 0,
                'fuzzy_strings': 0,
            }]
            views.ajax_resources(self.factory.get(
                '/', HTTP_X_REQUESTED_WITH='XMLHttpRequest'),
                                 code=locale.code,
                                 slug=project.slug)
            ctx = mock_render.call_args[0][2]
            assert_equal(ctx['resources'], [{
                'latest_activity': translation.latest_activity,
                'title': 'has/stats.po',
                'resource__path': 'has/stats.po',
                'resource__total_strings': 1,
                'approved_strings': 0,
                'unreviewed_strings': 1,
                'fuzzy_strings': 0,
                'chart': {
                    'fuzzy_strings': 0,
                    'total_strings': 1,
                    'approved_strings': 0,
                    'unreviewed_strings': 1,
                    'approved_share': 0.0,
                    'unreviewed_share': 100.0,
                    'fuzzy_share': 0.0,
                    'completion_percent': 0
                }
            }, {
                'latest_activity': None,
                'title': 'no/stats.po',
                'resource__path': 'no/stats.po',
                'resource__total_strings': 1,
                'approved_strings': 0,
                'unreviewed_strings': 0,
                'fuzzy_strings': 0,
                'chart': {
                    'fuzzy_strings': 0,
                    'total_strings': 1,
                    'approved_strings': 0,
                    'unreviewed_strings': 0,
                    'approved_share': 0.0,
                    'unreviewed_share': 0.0,
                    'fuzzy_share': 0.0,
                    'completion_percent': 0
                }
            }])