Exemple #1
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
Exemple #2
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)
        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
Exemple #3
0
    def test_exception_during_sync(self):
        """
        Any error during performing synchronization should release the lock.
        """
        @serial_task(100)
        def exception_task(self):
            raise UserError

        first_call = exception_task.delay()
        second_call = exception_task.delay()

        assert_true(first_call.failed())
        assert_true(second_call.failed())
        assert_raises(UserError, first_call.get)
        assert_raises(UserError, second_call.get)
    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()
Exemple #5
0
    def test_exception_during_sync(self):
        """
        Any error during performing synchronization should release the lock.
        """
        @serial_task(100)
        def exception_task(self):
            raise UserError

        first_call = exception_task.delay()
        second_call = exception_task.delay()

        assert_true(first_call.failed())
        assert_true(second_call.failed())
        assert_raises(UserError, first_call.get)
        assert_raises(UserError, second_call.get)
Exemple #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()
Exemple #7
0
    def test_always_close(self):
        """Ensure that the connection is closed even if an exception is thrown."""
        self.channel.queue_declare.side_effect = IOError

        with assert_raises(IOError):
            shove.send_command('my_queue', 'my_project', 'asdf', 75)
        assert_true(self.connection.close.called)
 def test_handle_entity_none(self):
     """
     If both the db_entity and vcs_entity are None, raise a
     CommandError, as that should never happen.
     """
     with assert_raises(CommandError):
         self.call_handle_entity('key', None, None)
Exemple #9
0
 def test_no_matching_projects(self):
     """
     If no projects are found that match the given slugs, raise a
     CommandError.
     """
     with assert_raises(CommandError):
         self.execute_command("does-not-exist")
Exemple #10
0
 def test_repository_for_path_none(self):
     """
     If the project has no matching repositories, raise a ValueError.
     """
     project = ProjectFactory.create(repositories=[])
     with assert_raises(ValueError):
         project.repository_for_path('doesnt/exist')
Exemple #11
0
 def test_none(self):
     """
     If both the db_entity and vcs_entity are None, raise a
     CommandError, as that should never happen.
     """
     with assert_raises(ValueError):
         self.call_update_entities([('key', None, None)])
Exemple #12
0
 def test_no_matching_projects(self):
     """
     If no projects are found that match the given slugs, raise a
     CommandError.
     """
     with assert_raises(CommandError):
         self.execute_command(projects="does-not-exist")
Exemple #13
0
 def test_repository_for_path_none(self):
     """
     If the project has no matching repositories, raise a ValueError.
     """
     project = ProjectFactory.create(repositories=[])
     with assert_raises(ValueError):
         project.repository_for_path("doesnt/exist")
Exemple #14
0
 def test_none(self):
     """
     If both the db_entity and vcs_entity are None, raise a
     CommandError, as that should never happen.
     """
     with assert_raises(ValueError):
         self.call_handle_entity('key', None, None)
Exemple #15
0
 def test_init_invalid_resource(self):
     """
     If no parser cannot be found for the translated resource,
     raise a ParseError.
     """
     path = self.get_invalid_file_path()
     with assert_raises(ParseError):
         compare_locales.CompareLocalesResource(path, source_resource=None)
 def test_init_missing_resource(self):
     """
     If the translated resource doesn't exist and no source resource
     is given, raise an IOError.
     """
     path = os.path.join(tempfile.mkdtemp(), 'does', 'not', 'exist.dtd')
     with assert_raises(IOError):
         silme.SilmeResource(DTDParser, path, source_resource=None)
Exemple #17
0
 def test_init_missing_resource(self):
     """
     If the translated resource doesn't exist and no source resource is
     given, raise a ParseError.
     """
     path = self.get_nonexistant_file_path()
     with assert_raises(ParseError):
         compare_locales.CompareLocalesResource(path, source_resource=None)
Exemple #18
0
 def test_init_missing_resource(self):
     """
     If the translated resource doesn't exist and no source resource
     is given, raise an IOError.
     """
     path = os.path.join(tempfile.mkdtemp(), 'does', 'not', 'exist.dtd')
     with assert_raises(IOError):
         silme.SilmeResource(DTDParser, path, source_resource=None)
Exemple #19
0
 def test_init_missing_resource(self):
     """
     If the FTLResource file doesn't exist and no source resource is
     given, raise a IOError.
     """
     path = self.get_nonexistant_file_path()
     with assert_raises(IOError):
         ftl.FTLResource(path, locale=None, source_resource=None)
Exemple #20
0
 def test_init_missing_resource(self):
     """
     If the FTLResource file doesn't exist and no source resource is
     given, raise a IOError.
     """
     path = self.get_nonexistant_file_path()
     with assert_raises(IOError):
         ftl.FTLResource(path, locale=None, source_resource=None)
 def test_init_missing_resource(self):
     """
     If the translated resource doesn't exist and no source resource is
     given, raise a ParseError.
     """
     path = self.get_nonexistant_file_path()
     with assert_raises(ParseError):
         compare_locales.CompareLocalesResource(path, source_resource=None)
Exemple #22
0
    def test_url_for_path_no_match(self):
        """
        If no active locale matches the given path, raise a ValueError.
        """
        repo = RepositoryFactory.create(project__locales=[], url="https://example.com/path/to/{locale_code}/")

        with assert_raises(ValueError):
            repo.url_for_path("/media/root/path/to/match/foo/bar.po")
Exemple #23
0
    def test_serial_task(self):
        """
        Test if sync will create lock in cache and release this after task is done.
        """
        @serial_task(100)
        def test_task(self, callback):
            return callback()

        def execute_second_inner_task():
            return test_task.delay(lambda: None)

        first_call = test_task.delay(execute_second_inner_task)
        second_call = first_call.get()

        assert_true(first_call.successful())
        assert_true(second_call.failed())
        assert_raises(RuntimeError, second_call.get)
Exemple #24
0
    def test_serial_task(self):
        """
        Test if sync will create lock in cache and release this after task is done.
        """
        @serial_task(100)
        def test_task(self, callback):
            return callback()

        def execute_second_inner_task():
            return test_task.delay(lambda: None)

        first_call = test_task.delay(execute_second_inner_task)
        second_call = first_call.get()

        assert_true(first_call.successful())
        assert_true(second_call.failed())
        assert_raises(RuntimeError, second_call.get)
Exemple #25
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)
Exemple #26
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_perform_sync_project.called)
Exemple #27
0
 def test_unapproved_translation_in_memory(self):
     """
     Unapproved translation shouldn't be in the translation memory.
     """
     translation = TranslationFactory.create(approved=False)
     with assert_raises(TranslationMemoryEntry.DoesNotExist):
         TranslationMemoryEntry.objects.get(
             source=translation.entity.string, target=translation.string, locale=translation.locale
         )
Exemple #28
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)
Exemple #29
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_update_originals.called)
Exemple #30
0
    def test_serial_task(self):
        """
        Test if sync will create lock in cache and release this after task is done.
        """
        @serial_task(100)
        def test_task(self, call_subtask):
            if call_subtask:
                return subtask()

        def subtask():
            return test_task.delay()

        first_call = test_task.delay(call_subtask=True)
        second_call = first_call.get()

        assert_true(first_call.successful())
        assert_true(second_call.failed())
        assert_raises(RuntimeError, second_call.get)
Exemple #31
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)
Exemple #32
0
 def test_unapproved_translation_in_memory(self):
     """
     Unapproved translation shouldn't be in the translation memory.
     """
     translation = TranslationFactory.create(approved=False)
     with assert_raises(TranslationMemoryEntry.DoesNotExist):
         TranslationMemoryEntry.objects.get(
             source=translation.entity.string,
             target=translation.string,
             locale=translation.locale)
 def test_parse_no_comments_no_sources(self):
     with assert_raises(ParseError):
         self.parse_string(
             dedent("""
             {
               "NoComments": {
                 "message": "Translated No Comments"
               }
             }
         """))
Exemple #34
0
    def test_send_command_no_permission(self):
        """
        If the user doesn't have permission to run a command for this project, raise
        PermissionDenied.
        """
        user = UserFactory.create()
        project = ProjectFactory.create()

        with assert_raises(PermissionDenied):
            project.send_command(user, 'asdf')
Exemple #35
0
    def test_url_for_path_no_match(self):
        """
        If no active locale matches the given path, raise a ValueError.
        """
        repo = RepositoryFactory.create(
            project__locales=[],
            url='https://example.com/path/to/{locale_code}/',
        )

        with assert_raises(ValueError):
            repo.url_for_path('/media/root/path/to/match/foo/bar.po')
Exemple #36
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
    def test_send_command_inactive_shoves(self):
        """
        If any of the shove instances given are not in the set of active
        shove instances for this project, raise a ValueError.
        """
        user = UserFactory.create()
        project = ProjectFactory.create()
        assign_perm('can_run_commands', user, project)

        instance1, instance2 = ShoveInstanceFactory.create_batch(2, active=True)
        project.shove_instances.add(instance1)
        with assert_raises(ValueError):
            project.send_command(user, 'asdf', [instance1, instance2])

        # Now try with an inactive instance that is part of the
        # project's instances.
        instance2.active = False
        instance2.save()
        project.shove_instances.add(instance2)
        with assert_raises(ValueError):
            project.send_command(user, 'asdf', [instance1, instance2])
Exemple #38
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
    def test_handle_delete_translations(self):
        """
        After syncing, delete any translations that are marked for
        deletion.
        """
        self.create_db_entities_translations()
        self.main_db_translation.deleted = aware_datetime(1970, 1, 1)
        self.main_db_translation.save()

        self.command.handle_project = Mock()
        self.execute_command()
        with assert_raises(Translation.DoesNotExist):
            self.main_db_translation.refresh_from_db()
Exemple #40
0
    def test_handle_delete_translations(self):
        """
        After syncing, delete any translations that are marked for
        deletion.
        """
        self.create_db_entities_translations()
        self.main_db_translation.deleted = aware_datetime(1970, 1, 1)
        self.main_db_translation.save()

        self.command.handle_project = Mock()
        self.execute_command()
        with assert_raises(Translation.DoesNotExist):
            self.main_db_translation.refresh_from_db()
    def test_parse_empty_translation(self):
        """
        If an entity has an empty translation, parse should raise a
        ParseError.
        """
        with assert_raises(ParseError):
            self.parse_string(dedent("""
                # Comment
                ;Source
                Translated

                ;Empty

                ;Not Empty
                Nope
            """))
Exemple #42
0
 def test_execute_called_once(self):
     """Raise a RuntimeError if execute is called more than once."""
     self.changeset.execute()
     with assert_raises(RuntimeError):
         self.changeset.execute()
Exemple #43
0
 def test_locale_checkout_path_non_multi_locale(self):
     """If the repo isn't multi-locale, throw a ValueError."""
     repo = RepositoryFactory.create(multi_locale=False)
     locale = LocaleFactory.create()
     with assert_raises(ValueError):
         repo.locale_checkout_path(locale)
Exemple #44
0
 def test_locale_url_non_multi_locale(self):
     """If the repo isn't multi-locale, throw a ValueError."""
     repo = RepositoryFactory.create()
     locale = LocaleFactory.create()
     with assert_raises(ValueError):
         repo.locale_url(locale)
Exemple #45
0
 def test_execute_called_once(self):
     """Raise a RuntimeError if execute is called more than once."""
     self.changeset.execute()
     with assert_raises(RuntimeError):
         self.changeset.execute()
Exemple #46
0
 def test_locale_url_non_multi_locale(self):
     """If the repo isn't multi-locale, throw a ValueError."""
     repo = RepositoryFactory.create()
     locale = LocaleFactory.create()
     with assert_raises(ValueError):
         repo.locale_url(locale)