Ejemplo n.º 1
0
 def test_get_latest_activity_without_latest(self):
     """
     If the project doesn't have a latest_translation and no locale
     is given, return None.
     """
     project = ProjectFactory.create(latest_translation=None)
     assert_is_none(project.get_latest_activity())
Ejemplo n.º 2
0
 def test_get_latest_activity_without_latest(self):
     """
     If the locale doesn't have a latest_translation and no project
     is given, return None.
     """
     locale = LocaleFactory.create(latest_translation=None)
     assert_is_none(locale.get_latest_activity())
Ejemplo n.º 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))
Ejemplo n.º 4
0
 def test_get_latest_activity_without_latest(self):
     """
     If the project doesn't have a latest_translation and no locale
     is given, return None.
     """
     project = ProjectFactory.create(latest_translation=None)
     assert_is_none(project.get_latest_activity())
Ejemplo n.º 5
0
 def test_get_latest_activity_without_latest(self):
     """
     If the locale doesn't have a latest_translation and no project
     is given, return None.
     """
     locale = LocaleFactory.create(latest_translation=None)
     assert_is_none(locale.get_latest_activity())
Ejemplo n.º 6
0
    def test_latest_datetime(self):
        larger = aware_datetime(2015, 1, 1)
        smaller = aware_datetime(2014, 1, 1)

        assert_is_none(latest_datetime([None, None, None]))
        assert_equal(latest_datetime([None, larger]), larger)
        assert_equal(latest_datetime([None, smaller, larger]), larger)
Ejemplo n.º 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))
Ejemplo n.º 8
0
    def test_end_time_unfinished(self):
        """If a job is unfinished, it's end_time is None."""
        sync_log = SyncLogFactory.create()

        # Create repo without existing log so sync is unfinished.
        repo = RepositoryFactory.create()
        ProjectSyncLogFactory.create(sync_log=sync_log, project__repositories=[repo])

        assert_is_none(sync_log.end_time)
Ejemplo n.º 9
0
    def test_end_time_unfinished(self):
        """If a job is unfinished, it's end_time is None."""
        sync_log = SyncLogFactory.create()

        # Create repo without existing log so sync is unfinished.
        repo = RepositoryFactory.create()
        ProjectSyncLogFactory.create(sync_log=sync_log, project__repositories=[repo])

        assert_is_none(sync_log.end_time)
Ejemplo n.º 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))
Ejemplo n.º 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))
Ejemplo n.º 12
0
    def test_save_latest_translation_update(self):
        """
        When a translation is saved, update the latest_translation
        attribute on the related project, locale, stats, and
        project_locale objects.
        """
        locale = LocaleFactory.create(latest_translation=None)
        project = ProjectFactory.create(locales=[locale],
                                        latest_translation=None)
        resource = ResourceFactory.create(project=project)
        stats = StatsFactory.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(stats.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(stats, 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(stats, 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(stats, 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(stats, newer_approved_translation)
        self.assert_latest_translation(project_locale,
                                       newer_approved_translation)
Ejemplo n.º 13
0
    def test_save_latest_translation_update(self):
        """
        When a translation is saved, update the latest_translation
        attribute on the related project, locale, stats, and
        project_locale objects.
        """
        locale = LocaleFactory.create(latest_translation=None)
        project = ProjectFactory.create(locales=[locale], latest_translation=None)
        resource = ResourceFactory.create(project=project)
        stats = StatsFactory.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(stats.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(stats, 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(stats, 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(stats, 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(stats, newer_approved_translation)
        self.assert_latest_translation(project_locale, newer_approved_translation)
Ejemplo n.º 14
0
 def test_end_time_unfinished(self):
     """If a sync is unfinished, it's end_time is None."""
     repo = RepositoryFactory.create()
     project_sync_log = ProjectSyncLogFactory.create(
         project__repositories=[repo])
     assert_is_none(project_sync_log.end_time)
Ejemplo n.º 15
0
 def test_get_object_or_none(self):
     project = ProjectFactory.create(slug='exists')
     assert_is_none(get_object_or_none(Project, slug='does-not-exist'))
     assert_equal(get_object_or_none(Project, slug='exists'), project)
Ejemplo n.º 16
0
 def test_end_time_unfinished(self):
     """If a sync is unfinished, it's end_time is None."""
     repo = RepositoryFactory.create()
     project_sync_log = ProjectSyncLogFactory.create(project__repositories=[repo])
     assert_is_none(project_sync_log.end_time)