예제 #1
0
    def test_reset_project_has_changed(self):
        """After syncing, set db_project.has_changed to False."""
        self.db_project.has_changed = True
        self.db_project.save()

        sync_project(self.db_project.pk, self.project_sync_log.sync_log.pk)
        self.db_project.refresh_from_db()
        assert_false(self.db_project.has_changed)
예제 #2
0
    def test_reset_project_has_changed(self):
        """After syncing, set db_project.has_changed to False."""
        self.db_project.has_changed = True
        self.db_project.save()

        sync_project(self.db_project.pk, self.project_sync_log.sync_log.pk)
        self.db_project.refresh_from_db()
        assert_false(self.db_project.has_changed)
예제 #3
0
 def test_missing_log(self):
     """
     If a log with the given PK doesn't exist, log it and exit.
     """
     with patch("pontoon.sync.tasks.log") as mock_log:
         with pytest.raises(SyncLog.DoesNotExist):
             sync_project(self.db_project.pk, 99999)
         mock_log.error.assert_called_with(CONTAINS("99999"))
         assert not self.mock_update_originals.called
예제 #4
0
 def test_missing_project(self):
     """
     If a project with the given PK doesn't exist, log it and exit.
     """
     with patch('pontoon.sync.tasks.log') as mock_log, \
          patch('pontoon.sync.tasks.perform_sync') as mock_perform_sync:
         sync_project(99999)
         mock_log.error.assert_called_with(CONTAINS('99999'))
         assert_false(mock_perform_sync.called)
예제 #5
0
 def test_missing_project(self):
     """
     If a project with the given PK doesn't exist, log it and exit.
     """
     with patch('pontoon.sync.tasks.log') as mock_log:
         with assert_raises(Project.DoesNotExist):
             sync_project(99999, self.sync_log.pk)
         mock_log.error.assert_called_with(CONTAINS('99999'))
         assert_false(self.mock_update_originals.called)
예제 #6
0
 def test_missing_log(self):
     """
     If a log with the given PK doesn't exist, log it and exit.
     """
     with patch('pontoon.sync.tasks.log') as mock_log:
         with assert_raises(SyncLog.DoesNotExist):
             sync_project(self.db_project.pk, 99999)
         mock_log.error.assert_called_with(CONTAINS('99999'))
         assert_false(self.mock_perform_sync_project.called)
예제 #7
0
 def test_missing_log(self):
     """
     If a log with the given PK doesn't exist, log it and exit.
     """
     with patch('pontoon.sync.tasks.log') as mock_log:
         with assert_raises(SyncLog.DoesNotExist):
             sync_project(self.db_project.pk, 99999)
         mock_log.error.assert_called_with(CONTAINS('99999'))
         assert_false(self.mock_perform_sync_project.called)
예제 #8
0
 def test_missing_project(self):
     """
     If a project with the given PK doesn't exist, log it and exit.
     """
     with patch('pontoon.sync.tasks.log') as mock_log:
         with assert_raises(Project.DoesNotExist):
             sync_project(99999, self.sync_log.pk)
         mock_log.error.assert_called_with(CONTAINS('99999'))
         assert_false(self.mock_update_originals.called)
예제 #9
0
    def test_no_changes_force(self):
        """
        If the database and VCS both have no changes, but force is true,
        do not skip sync.
        """
        self.mock_pull_changes.return_value = False
        self.mock_project_needs_sync.return_value = False

        sync_project(self.db_project.pk, self.sync_log.pk, force=True)
        assert_true(self.mock_perform_sync_project.called)
예제 #10
0
    def test_no_changes_force(self):
        """
        If the database and VCS both have no changes, but force is true,
        do not skip syncing resources.
        """
        self.mock_pull_source_repo_changes.return_value = False
        self.mock_project_needs_sync.return_value = False

        sync_project(self.db_project.pk, self.sync_log.pk, force=True)
        assert self.mock_update_originals.called
예제 #11
0
    def test_no_changes_force(self):
        """
        If the database and VCS both have no changes, but force is true,
        do not skip syncing resources.
        """
        self.mock_pull_changes.return_value = [False, {}]
        self.mock_project_needs_sync.return_value = False

        sync_project(self.db_project.pk, self.sync_log.pk, force=True)
        assert_true(self.mock_update_originals.called)
예제 #12
0
    def test_no_changes_force(self):
        """
        If the database and VCS both have no changes, but force is true,
        do not skip sync.
        """
        self.mock_pull_changes.return_value = False
        self.mock_project_needs_sync.return_value = False

        sync_project(self.db_project.pk, self.sync_log.pk, force=True)
        assert_true(self.mock_perform_sync_project.called)
예제 #13
0
    def test_db_changed_no_repo_changed(self):
        """
        If the database has changes and VCS doesn't, do not skip syncing
        the project.
        """
        self.mock_pull_changes.return_value = False
        self.mock_project_needs_sync.return_value = True

        sync_project(self.db_project.pk, self.sync_log.pk)
        assert_true(self.mock_perform_sync_project.called)
예제 #14
0
    def test_db_changed_no_repo_changed(self):
        """
        If the database has changes and VCS doesn't, do not skip syncing
        the project.
        """
        self.mock_pull_changes.return_value = False
        self.mock_project_needs_sync.return_value = True

        sync_project(self.db_project.pk, self.sync_log.pk)
        assert_true(self.mock_perform_sync_project.called)
예제 #15
0
    def test_create_project_log(self):
        assert_false(ProjectSyncLog.objects.exists())

        repo = RepositoryFactory.create()
        self.db_project.repositories = [repo]
        self.db_project.save()
        sync_project(self.db_project.pk, self.sync_log.pk)

        log = ProjectSyncLog.objects.get(project=self.db_project)
        assert_equal(self.mock_sync_translations.delay.call_args[0][1], repo.pk)
        assert_equal(self.mock_sync_translations.delay.call_args[0][2], log.pk)
예제 #16
0
    def test_db_changed_no_repo_changed(self):
        """
        If the database has changes and VCS doesn't, skip syncing
        resources, but sync translations.
        """
        self.mock_pull_source_repo_changes.return_value = False
        self.mock_project_needs_sync.return_value = True

        with patch("pontoon.sync.tasks.log") as mock_log:
            sync_project(self.db_project.pk, self.sync_log.pk)

        sync_project(self.db_project.pk, self.sync_log.pk)
        assert not self.mock_update_originals.called
        mock_log.info.assert_called_with(
            CONTAINS("Skipping syncing sources", self.db_project.slug))
예제 #17
0
    def test_no_changes_skip(self):
        """
        If the database and VCS both have no changes, skip sync and log
        a message.
        """
        self.mock_pull_changes.return_value = False
        self.mock_project_needs_sync.return_value = False

        with patch('pontoon.sync.tasks.log') as mock_log:
            sync_project(self.db_project.pk, self.sync_log.pk)

        assert_false(self.mock_perform_sync_project.called)
        mock_log.info.assert_called_with(
            CONTAINS('Skipping', self.db_project.slug)
        )
예제 #18
0
    def test_db_changed_no_repo_changed(self):
        """
        If the database has changes and VCS doesn't, skip syncing
        resources, but sync translations.
        """
        self.mock_pull_changes.return_value = [False, {}]
        self.mock_project_needs_sync.return_value = True

        with patch('pontoon.sync.tasks.log') as mock_log:
            sync_project(self.db_project.pk, self.sync_log.pk)

        sync_project(self.db_project.pk, self.sync_log.pk)
        assert_false(self.mock_update_originals.called)
        mock_log.info.assert_called_with(
            CONTAINS('Skipping syncing resources', self.db_project.slug)
        )
예제 #19
0
    def test_no_changes_skip(self):
        """
        If the database and the source repository both have no
        changes, and project has a single repository, skip sync.
        """
        self.mock_pull_source_repo_changes.return_value = False
        self.mock_project_needs_sync.return_value = False

        with patch("pontoon.sync.tasks.log") as mock_log:
            sync_project(self.db_project.pk, self.sync_log.pk)

        assert not self.mock_update_originals.called
        mock_log.info.assert_called_with(
            CONTAINS("Skipping project", self.db_project.slug))

        # When skipping, mark the project log properly.
        assert ProjectSyncLog.objects.get(project=self.db_project).skipped
예제 #20
0
    def test_no_changes_skip(self):
        """
        If the database and VCS both have no changes, skip sync and log
        a message.
        """
        self.mock_pull_changes.return_value = (False, {})
        self.mock_project_needs_sync.return_value = False

        with patch('pontoon.sync.tasks.log') as mock_log:
            sync_project(self.db_project.pk, self.sync_log.pk)

        assert_false(self.mock_perform_sync_project.called)
        mock_log.info.assert_called_with(
            CONTAINS('Skipping', self.db_project.slug)
        )

        # When skipping, mark the project log properly.
        assert_true(ProjectSyncLog.objects.get(project=self.db_project).skipped)
예제 #21
0
    def test_no_changes_skip(self):
        """
        If the database and VCS both have no changes, skip sync and log
        a message.
        """
        self.mock_pull_changes.return_value = False
        self.mock_project_needs_sync.return_value = False

        with patch('pontoon.sync.tasks.log') as mock_log:
            sync_project(self.db_project.pk, self.sync_log.pk)

        assert_false(self.mock_perform_sync_project.called)
        mock_log.info.assert_called_with(
            CONTAINS('Skipping', self.db_project.slug)
        )

        # When skipping, mark the project log properly.
        assert_true(ProjectSyncLog.objects.get(project=self.db_project).skipped)
예제 #22
0
    def test_no_changes_skip(self):
        """
        If the database and the source repository both have no
        changes, and project has a single repository, skip sync.
        """
        self.mock_pull_changes.return_value = [False, {}]
        self.mock_project_needs_sync.return_value = False

        with patch('pontoon.sync.tasks.log') as mock_log:
            sync_project(self.db_project.pk, self.sync_log.pk)

        assert_false(self.mock_update_originals.called)
        mock_log.info.assert_called_with(
            CONTAINS('Skipping project', self.db_project.slug)
        )

        # When skipping, mark the project log properly.
        assert_true(ProjectSyncLog.objects.get(project=self.db_project).skipped)
예제 #23
0
 def test_no_pull(self):
     """
     Don't call repo.pull if command.no_pull is True.
     """
     sync_project(self.db_project.pk, self.sync_log.pk, no_pull=True)
     assert not self.mock_pull_source_repo_changes.called
예제 #24
0
    def test_create_project_log(self):
        assert_false(ProjectSyncLog.objects.exists())
        sync_project(self.db_project.pk, self.sync_log.pk)

        log = ProjectSyncLog.objects.get(project=self.db_project)
        assert_equal(self.mock_sync_translations.delay.call_args[0][1], log.pk)
예제 #25
0
    def test_create_project_log(self):
        assert_false(ProjectSyncLog.objects.exists())
        sync_project(self.db_project.pk, self.sync_log.pk)

        log = ProjectSyncLog.objects.get(project=self.db_project)
        assert_equal(self.mock_sync_translations.delay.call_args[0][1], log.pk)
예제 #26
0
 def test_no_pull(self):
     """
     Don't call repo.pull if command.no_pull is True.
     """
     sync_project(self.db_project.pk, self.sync_log.pk, no_pull=True)
     assert_false(self.mock_pull_changes.called)
예제 #27
0
    def test_create_project_log(self):
        assert not ProjectSyncLog.objects.exists()
        sync_project(self.db_project.pk, self.sync_log.pk)

        log = ProjectSyncLog.objects.get(project=self.db_project)
        assert self.mock_sync_translations.call_args[0][1].pk == log.pk