Beispiel #1
0
    def test_needs_sync(self):
        """
        Project.needs_sync should be True if ChangedEntityLocale objects
        exist for its entities or if Project.has_changed is True.
        """
        assert_true(ProjectFactory.create(has_changed=True).needs_sync)

        project = ProjectFactory.create(has_changed=False)
        ChangedEntityLocaleFactory.create(entity__resource__project=project)
        assert_true(project.needs_sync)
Beispiel #2
0
    def test_needs_sync(self):
        """
        Project.needs_sync should be True if ChangedEntityLocale objects
        exist for its entities or if Project.has_changed is True.
        """
        assert_true(ProjectFactory.create(has_changed=True).needs_sync)

        project = ProjectFactory.create(has_changed=False)
        ChangedEntityLocaleFactory.create(entity__resource__project=project)
        assert_true(project.needs_sync)
Beispiel #3
0
    def test_clear_changed_entities(self):
        """
        Delete all ChangedEntityLocale objects for the project created
        before the sync started after handling it.
        """
        self.now = aware_datetime(1970, 1, 2)
        self.mock_pull_locale_repo_changes.return_value = [
            True,
            {
                self.repository.pk:
                Locale.objects.filter(pk=self.translated_locale.pk)
            },
        ]

        changed1, changed2, changed_after = ChangedEntityLocaleFactory.create_batch(
            3,
            locale=self.translated_locale,
            entity__resource=self.main_db_resource,
            when=aware_datetime(1970, 1, 1),
        )
        changed_after.when = aware_datetime(1970, 1, 3)
        changed_after.save()

        sync_translations(self.db_project, self.project_sync_log, self.now,
                          True)
        with pytest.raises(ChangedEntityLocale.DoesNotExist):
            changed1.refresh_from_db()
        with pytest.raises(ChangedEntityLocale.DoesNotExist):
            changed2.refresh_from_db()
        changed_after.refresh_from_db()  # Should not raise
Beispiel #4
0
    def test_clear_changed_entities(self):
        """
        Delete all ChangedEntityLocale objects for the project created
        before the sync started after handling it.
        """
        self.now = aware_datetime(1970, 1, 2)
        self.mock_pull_changes.return_value = [True, {
            self.repository.pk: Locale.objects.filter(pk=self.translated_locale.pk)
        }]

        changed1, changed2, changed_after = ChangedEntityLocaleFactory.create_batch(3,
            locale=self.translated_locale,
            entity__resource=self.main_db_resource,
            when=aware_datetime(1970, 1, 1)
        )
        changed_after.when = aware_datetime(1970, 1, 3)
        changed_after.save()

        sync_translations(self.db_project.pk, self.project_sync_log.pk,
                          self.now, self.mock_changes)
        with assert_raises(ChangedEntityLocale.DoesNotExist):
            changed1.refresh_from_db()
        with assert_raises(ChangedEntityLocale.DoesNotExist):
            changed2.refresh_from_db()
        changed_after.refresh_from_db()  # Should not raise
    def test_handle_project_db_changed_no_repo_changed(self):
        """
        If the database has changes and VCS doesn't, do not skip syncing
        the project.
        """
        self.create_db_entities_translations()

        self.command.pull_changes = Mock(return_value=False)
        ChangedEntityLocale.objects.all().delete()
        ChangedEntityLocaleFactory.create(
            entity=self.main_db_entity,
            locale=self.translated_locale
        )

        self.command.handle_entity = Mock()
        self.command.handle_project(self.db_project)
        assert_true(self.command.handle_entity.called)
Beispiel #6
0
    def test_handle_project_clear_changed_entities(self):
        """
        Delete all ChangedEntityLocale objects for the project after
        handling it.
        """
        changed1, changed2 = ChangedEntityLocaleFactory.create_batch(2,
            locale=self.translated_locale,
            entity__resource__project=self.db_project
        )

        self.command.handle_project(self.db_project)
        with assert_raises(ChangedEntityLocale.DoesNotExist):
            changed1.refresh_from_db()
        with assert_raises(ChangedEntityLocale.DoesNotExist):
            changed2.refresh_from_db()
    def test_handle_project_clear_changed_entities(self):
        """
        Delete all ChangedEntityLocale objects for the project after
        handling it.
        """
        changed1, changed2 = ChangedEntityLocaleFactory.create_batch(2,
            locale=self.translated_locale,
            entity__resource__project=self.db_project
        )

        self.command.handle_project(self.db_project)
        with assert_raises(ChangedEntityLocale.DoesNotExist):
            changed1.refresh_from_db()
        with assert_raises(ChangedEntityLocale.DoesNotExist):
            changed2.refresh_from_db()
Beispiel #8
0
    def test_clear_changed_entities(self):
        """
        Delete all ChangedEntityLocale objects for the project created
        before the sync started after handling it.
        """
        self.now = aware_datetime(1970, 1, 2)
        changed1, changed2, changed_after = ChangedEntityLocaleFactory.create_batch(3,
            locale=self.translated_locale,
            entity__resource=self.main_db_resource,
            when=aware_datetime(1970, 1, 1)
        )
        changed_after.when = aware_datetime(1970, 1, 3)
        changed_after.save()

        sync_project_repo(self.db_project.pk, self.repository.pk,
                          self.project_sync_log.pk, self.now)
        with assert_raises(ChangedEntityLocale.DoesNotExist):
            changed1.refresh_from_db()
        with assert_raises(ChangedEntityLocale.DoesNotExist):
            changed2.refresh_from_db()
        changed_after.refresh_from_db()  # Should not raise
Beispiel #9
0
    def test_clear_changed_entities(self):
        """
        Delete all ChangedEntityLocale objects for the project created
        before the sync started after handling it.
        """
        self.mock_timezone.return_value = aware_datetime(1970, 1, 2)
        changed1, changed2, changed_after = ChangedEntityLocaleFactory.create_batch(3,
            locale=self.translated_locale,
            entity__resource=self.main_db_resource,
            entity__resource__project=self.db_project,
            when=aware_datetime(1970, 1, 1)
        )
        changed_after.when = aware_datetime(1970, 1, 3)
        changed_after.save()

        sync_project(self.db_project)
        with assert_raises(ChangedEntityLocale.DoesNotExist):
            changed1.refresh_from_db()
        with assert_raises(ChangedEntityLocale.DoesNotExist):
            changed2.refresh_from_db()
        changed_after.refresh_from_db()  # Should not raise