def test_update_db_unapprove_fuzzy(self):
        """
        If an existing translation is fuzzy and doesn't match anything in VCS,
        unapprove and unfuzzy that translation without rejecting it.
        """
        self.main_db_translation.fuzzy = True
        self.main_db_translation.approved = True
        self.main_db_translation.approved_date = aware_datetime(1970, 1, 1)
        self.main_db_translation.approved_user = UserFactory.create()
        self.main_db_translation.save()
        self.main_vcs_translation.strings[None] = "New Translated String"

        self.update_main_db_entity()
        self.main_db_translation.refresh_from_db()
        assert_attributes_equal(
            self.main_db_translation,
            approved=False,
            approved_user=None,
            approved_date=None,
            rejected=False,
            fuzzy=False,
        )

        assert ActionLog.objects.filter(
            action_type="translation:unapproved",
            translation=self.main_db_translation.pk,
        ).exists()
Example #2
0
    def test_update_db_unapprove_existing(self):
        """
        Any existing translations that don't match anything in VCS get
        unapproved, unless they were created after self.now.
        """
        self.main_db_translation.approved = True
        self.main_db_translation.approved_date = aware_datetime(1970, 1, 1)
        self.main_db_translation.approved_user = UserFactory.create()
        self.main_db_translation.save()
        self.main_vcs_translation.strings[None] = 'New Translated String'

        created_after_translation = TranslationFactory.create(
            entity=self.main_db_entity,
            approved=True,
            approved_date=aware_datetime(1970, 1, 3)
        )

        self.update_main_db_entity()
        self.main_db_translation.refresh_from_db()
        assert_attributes_equal(
            self.main_db_translation,
            approved=False,
            approved_user=None,
            approved_date=None
        )

        created_after_translation.refresh_from_db()
        assert_attributes_equal(
            created_after_translation,
            approved=True,
            approved_date=aware_datetime(1970, 1, 3)
        )
Example #3
0
 def test_update_vcs_entity_user(self):
     """Track translation authors for use in the commit message."""
     user = UserFactory.create()
     self.update_main_vcs_entity(user=user)
     assert_equal(
         self.changeset.commit_authors_per_locale['translated-locale'],
         [user])
Example #4
0
    def test_update_db_unapprove_existing(self):
        """
        Any existing translations that don't match anything in VCS get
        unapproved, unless they were created after self.now.
        """
        self.main_db_translation.approved = True
        self.main_db_translation.approved_date = aware_datetime(1970, 1, 1)
        self.main_db_translation.approved_user = UserFactory.create()
        self.main_db_translation.save()
        self.main_vcs_translation.strings[None] = 'New Translated String'

        created_after_translation = TranslationFactory.create(
            entity=self.main_db_entity,
            approved=True,
            approved_date=aware_datetime(1970, 1, 3)
        )

        self.update_main_db_entity()
        self.main_db_translation.refresh_from_db()
        assert_attributes_equal(
            self.main_db_translation,
            approved=False,
            approved_user=None,
            approved_date=None
        )

        created_after_translation.refresh_from_db()
        assert_attributes_equal(
            created_after_translation,
            approved=True,
            approved_date=aware_datetime(1970, 1, 3)
        )
Example #5
0
    def setUp(self):
        mock_persona_migration = patch.object(middleware.PersonaMigrationMiddleware, 'process_request', return_value=None)
        self.mock_persona_migration = mock_persona_migration.start()
        self.addCleanup(mock_persona_migration.stop)

        self.user = UserFactory.create()
        self.client.force_login(self.user)
Example #6
0
    def test_managers_group(self):
        """
        Tests if user has permission to manage and translate locales after assigment.
        """
        user = UserFactory.create()
        [first_locale, second_locale] = LocaleFactory.create_batch(2)

        assert_equal(user.has_perm("base.can_translate_locale"), False)
        assert_equal(user.has_perm("base.can_translate_locale", first_locale), False)
        assert_equal(user.has_perm("base.can_translate_locale", second_locale), False)
        assert_equal(user.has_perm("base.can_manage_locale"), False)
        assert_equal(user.has_perm("base.can_manage_locale", first_locale), False)
        assert_equal(user.has_perm("base.can_manage_locale", second_locale), False)

        user.groups.add(second_locale.managers_group)

        assert_equal(user.has_perm("base.can_translate_locale"), False)
        assert_equal(user.has_perm("base.can_translate_locale", first_locale), False)
        assert_equal(user.has_perm("base.can_translate_locale", second_locale), True)
        assert_equal(user.has_perm("base.can_manage_locale"), False)
        assert_equal(user.has_perm("base.can_manage_locale", first_locale), False)
        assert_equal(user.has_perm("base.can_manage_locale", second_locale), True)

        user.groups.add(first_locale.managers_group)

        assert_equal(user.has_perm("base.can_translate_locale"), False)
        assert_equal(user.has_perm("base.can_translate_locale", first_locale), True)
        assert_equal(user.has_perm("base.can_translate_locale", second_locale), True)
        assert_equal(user.has_perm("base.can_manage_locale"), False)
        assert_equal(user.has_perm("base.can_manage_locale", first_locale), True)
        assert_equal(user.has_perm("base.can_manage_locale", second_locale), True)
Example #7
0
    def test_translators_group(self):
        """
        Tests if user has permission to translate locales after assigment.
        """
        user = UserFactory.create()
        [first_locale, second_locale] = LocaleFactory.create_batch(2)

        assert_equal(user.has_perm('base.can_translate_locale'), False)
        assert_equal(user.has_perm('base.can_translate_locale', first_locale),
                     False)
        assert_equal(user.has_perm('base.can_translate_locale', second_locale),
                     False)

        user.groups.add(second_locale.translators_group)

        assert_equal(user.has_perm('base.can_translate_locale'), False)
        assert_equal(user.has_perm('base.can_translate_locale', first_locale),
                     False)
        assert_equal(user.has_perm('base.can_translate_locale', second_locale),
                     True)

        user.groups.add(first_locale.translators_group)

        assert_equal(user.has_perm('base.can_translate_locale'), False)
        assert_equal(user.has_perm('base.can_translate_locale', first_locale),
                     True)
        assert_equal(user.has_perm('base.can_translate_locale', second_locale),
                     True)
Example #8
0
    def setUp(self):
        self.log_mock = MagicMock()
        self.user = UserFactory.create()

        mock_messages = patch('pontoon.base.adapter.messages')
        self.mock_messages = mock_messages.start()
        self.addCleanup(mock_messages.stop)

        self.adapter = PontoonSocialAdapter()
Example #9
0
def test_timeline_non_active_contributor(
    contributor_translations, client, mock_profile_render
):
    """Test if backend is able return events for a user without contributions."""
    nonactive_contributor = UserFactory.create()
    client.get("/contributors/{}/timeline/".format(nonactive_contributor.username))
    assert mock_profile_render.call_args[0][2]["events"] == [
        {"date": nonactive_contributor.date_joined, "type": "join"}
    ]
Example #10
0
 def create_contributor_with_translation_counts(self, approved=0, unapproved=0, needs_work=0, **kwargs):
     """
     Helper method, creates contributor with given translations counts.
     """
     contributor = UserFactory.create()
     TranslationFactory.create_batch(approved, user=contributor, approved=True, **kwargs)
     TranslationFactory.create_batch(unapproved, user=contributor, approved=False, fuzzy=False, **kwargs)
     TranslationFactory.create_batch(needs_work, user=contributor, fuzzy=True, **kwargs)
     return contributor
Example #11
0
 def test_non_active_contributor(self):
     """Test if backend is able return events for a user without contributions."""
     nonactive_contributor = UserFactory.create()
     self.client.get(
         "/contributors/{}/timeline/".format(nonactive_contributor.username)
     )
     assert_equal(
         self.mock_render.call_args[0][2]["events"],
         [{"date": nonactive_contributor.date_joined, "type": "join"}],
     )
Example #12
0
 def test_non_active_contributor(self):
     """Test if backend is able return events for a user without contributions."""
     nonactive_contributor = UserFactory.create()
     self.client.get('/contributors/{}/timeline/'.format(
         nonactive_contributor.username))
     assert_equal(self.mock_render.call_args[0][2]['events'],
                  [{
                      'date': nonactive_contributor.date_joined,
                      'type': 'join'
                  }])
Example #13
0
    def test_users_without_translations(self):
        """
        Checks if user contributors without translations aren't returned.
        """
        active_contributor = TranslationFactory.create(user__email="*****@*****.**").user
        inactive_contributor = UserFactory.create(email="*****@*****.**")

        top_contributors = User.translators.with_translation_counts()
        assert_true(active_contributor in top_contributors)
        assert_true(inactive_contributor not in top_contributors)
Example #14
0
    def test_users_without_translations(self):
        """
        Checks if user contributors without translations aren't returned.
        """
        active_contributor = TranslationFactory.create(
            user__email='*****@*****.**').user
        inactive_contributor = UserFactory.create(email='*****@*****.**')

        top_contributors = User.translators.with_translation_counts()
        assert_true(active_contributor in top_contributors)
        assert_true(inactive_contributor not in top_contributors)
Example #15
0
 def test_non_active_contributor(self):
     """Test if backend is able return events for a user without contributions."""
     nonactive_contributor = UserFactory.create()
     self.client.get('/contributors/{}/timeline/'.format(nonactive_contributor.username))
     assert_equal(
         self.mock_render.call_args[0][2]['events'], [
         {
             'date': nonactive_contributor.date_joined,
             'type': 'join'
         }
     ])
Example #16
0
    def test_basic(self):
        user = UserFactory.create()
        self.changeset.commit_authors_per_locale = {
            self.translated_locale.code: [user]
        }
        self.db_project.repository_for_path = Mock(
            return_value=self.repository)

        commit_changes(self.db_project, self.vcs_project, self.changeset)
        self.repository.commit.assert_called_with(
            CONTAINS(user.display_name), user,
            os.path.join(FAKE_CHECKOUT_PATH, self.translated_locale.code))
Example #17
0
    def test_basic(self):
        user = UserFactory.create()
        self.changeset.commit_authors_per_locale = {
            self.translated_locale.code: [user]
        }
        self.db_project.repository_for_path = Mock(return_value=self.repository)

        commit_changes(self.db_project, self.vcs_project, self.changeset)
        self.repository.commit.assert_called_with(
            CONTAINS(user.display_name),
            user,
            os.path.join(FAKE_CHECKOUT_PATH, self.translated_locale.code)
        )
    def test_commit_changes(self):
        user = UserFactory.create()
        self.changeset.commit_authors_per_locale = {
            self.translated_locale.code: [user]
        }

        self.command.commit_changes(self.db_project, self.vcs_project, self.changeset)
        self.mock_commit_to_vcs.assert_called_with(
            'git',
            os.path.join(FAKE_CHECKOUT_PATH, self.translated_locale.code),
            CONTAINS(user.display_name),
            user,
            'https://example.com/git'
        )
Example #19
0
    def test_author_with_multiple_contributions(self):
        """
        Tests if author with multiple contributions occurs once in commit message.
        """
        author = UserFactory.create()
        self.changeset.commit_authors_per_locale = {self.translated_locale.code: [author, author]}
        self.db_project.repository_for_path = Mock(return_value=self.repository)

        commit_changes(self.db_project, self.vcs_project, self.changeset, self.translated_locale)
        self.repository.commit.assert_called_with(
            CONTAINS(author.display_name_and_email),
            author,
            os.path.join(FAKE_CHECKOUT_PATH, self.translated_locale.code),
        )
        commit_message = self.repository.commit.mock_calls[0][1][0]
        assert_equal(commit_message.count(author.display_name_and_email), 1)
Example #20
0
    def test_update_db_reject_approved(self):
        """
        When a translation is submitted through VCS, reject any existing approved translations.
        """
        self.main_db_translation.approved = True
        self.main_db_translation.approved_date = aware_datetime(1970, 1, 1)
        self.main_db_translation.approved_user = UserFactory.create()
        self.main_db_translation.rejected = False
        self.main_db_translation.save()
        self.main_vcs_translation.strings[None] = 'New Translated String'

        self.update_main_db_entity()
        self.main_db_translation.refresh_from_db()
        assert_attributes_equal(
            self.main_db_translation,
            rejected=True,
        )
Example #21
0
    def test_update_db_reject_approved(self):
        """
        When a translation is submitted through VCS, reject any existing approved translations.
        """
        self.main_db_translation.approved = True
        self.main_db_translation.approved_date = aware_datetime(1970, 1, 1)
        self.main_db_translation.approved_user = UserFactory.create()
        self.main_db_translation.rejected = False
        self.main_db_translation.save()
        self.main_vcs_translation.strings[None] = 'New Translated String'

        self.update_main_db_entity()
        self.main_db_translation.refresh_from_db()
        assert_attributes_equal(
            self.main_db_translation,
            rejected=True,
        )
Example #22
0
    def test_author_with_multiple_contributions(self):
        """
        Tests if author with multiple contributions occurs once in commit message.
        """
        author = UserFactory.create()
        self.changeset.commit_authors_per_locale = {
            self.translated_locale.code: [author, author]
        }
        self.db_project.repository_for_path = Mock(
            return_value=self.repository)

        commit_changes(self.db_project, self.vcs_project, self.changeset,
                       self.translated_locale)
        self.repository.commit.assert_called_with(
            CONTAINS(author.display_name_and_email), author,
            os.path.join(FAKE_CHECKOUT_PATH, self.translated_locale.code))
        commit_message = self.repository.commit.mock_calls[0][1][0]
        assert_equal(commit_message.count(author.display_name_and_email), 1)
Example #23
0
    def test_update_db_reject_approved_skip_fuzzy(self):
        """
        When a translation is submitted through VCS, reject any existing approved translations.
        Unless the same translation is submitted and only made fuzzy.
        """
        self.main_db_translation.approved = True
        self.main_db_translation.approved_date = aware_datetime(1970, 1, 1)
        self.main_db_translation.approved_user = UserFactory.create()
        self.main_db_translation.rejected = False
        self.main_db_translation.save()
        self.main_vcs_translation.strings[None] = self.main_db_translation.string
        self.main_vcs_translation.fuzzy = True

        self.update_main_db_entity()
        self.main_db_translation.refresh_from_db()
        assert_attributes_equal(
            self.main_db_translation, rejected=False,
        )
Example #24
0
    def test_update_db_reject_approved_skip_fuzzy(self):
        """
        When a translation is submitted through VCS, reject any existing approved translations.
        Unless the same translation is submitted and only made fuzzy.
        """
        self.main_db_translation.approved = True
        self.main_db_translation.approved_date = aware_datetime(1970, 1, 1)
        self.main_db_translation.approved_user = UserFactory.create()
        self.main_db_translation.rejected = False
        self.main_db_translation.save()
        self.main_vcs_translation.strings[None] = self.main_db_translation.string
        self.main_vcs_translation.fuzzy = True

        self.update_main_db_entity()
        self.main_db_translation.refresh_from_db()
        assert_attributes_equal(
            self.main_db_translation,
            rejected=False,
        )
Example #25
0
    def test_update_db_reject_approved(self):
        """
        When a translation is submitted through VCS, reject any existing approved translations.
        """
        self.main_db_translation.approved = True
        self.main_db_translation.approved_date = aware_datetime(1970, 1, 1)
        self.main_db_translation.approved_user = UserFactory.create()
        self.main_db_translation.rejected = False
        self.main_db_translation.save()
        self.main_vcs_translation.strings[None] = "New Translated String"

        self.update_main_db_entity()
        self.main_db_translation.refresh_from_db()
        assert_attributes_equal(
            self.main_db_translation, rejected=True,
        )

        assert ActionLog.objects.filter(
            action_type=ActionLog.ActionType.TRANSLATION_REJECTED,
            translation=self.main_db_translation.pk,
        ).exists()
Example #26
0
    def test_manage_project_strings(self):
        project = ProjectFactory.create(data_source='database',
                                        repositories=[])
        url = reverse('pontoon.admin.project.strings', args=(project.slug, ))

        # Test with anonymous user.
        response = self.client.get(url)
        assert_code(response, 403)

        # Test with a user that is not a superuser.
        user = UserFactory.create()
        self.client.force_login(user)

        response = self.client.get(url)
        assert_code(response, 403)

        # Test with a superuser.
        user.is_superuser = True
        user.save()

        response = self.client.get(url)
        assert_code(response, 200)
Example #27
0
 def create_contributor_with_translation_counts(self,
                                                approved=0,
                                                unapproved=0,
                                                needs_work=0,
                                                **kwargs):
     """
     Helper method, creates contributor with given translations counts.
     """
     contributor = UserFactory.create()
     TranslationFactory.create_batch(approved,
                                     user=contributor,
                                     approved=True,
                                     **kwargs)
     TranslationFactory.create_batch(unapproved,
                                     user=contributor,
                                     approved=False,
                                     fuzzy=False,
                                     **kwargs)
     TranslationFactory.create_batch(needs_work,
                                     user=contributor,
                                     fuzzy=True,
                                     **kwargs)
     return contributor
Example #28
0
    def test_update_db_unapprove_existing(self):
        """
        Any existing translations that don't match anything in VCS get
        unapproved, unless they were created after self.now.
        """
        self.main_db_translation.approved = True
        self.main_db_translation.approved_date = aware_datetime(1970, 1, 1)
        self.main_db_translation.approved_user = UserFactory.create()
        self.main_db_translation.save()
        self.main_vcs_translation.strings[None] = "New Translated String"

        created_after_translation = TranslationFactory.create(
            entity=self.main_db_entity,
            approved=True,
            approved_date=aware_datetime(1970, 1, 3),
        )

        self.update_main_db_entity()
        self.main_db_translation.refresh_from_db()
        assert_attributes_equal(
            self.main_db_translation,
            approved=False,
            approved_user=None,
            approved_date=None,
        )

        assert ActionLog.objects.filter(
            action_type=ActionLog.ActionType.TRANSLATION_REJECTED,
            translation=self.main_db_translation.pk,
        ).exists()

        created_after_translation.refresh_from_db()
        assert_attributes_equal(
            created_after_translation,
            approved=True,
            approved_date=aware_datetime(1970, 1, 3),
        )
Example #29
0
 def setUp(self):
     self.user = UserFactory.create(is_superuser=True)
     self.client.force_login(self.user)
Example #30
0
 def setUp(self):
     self.user = UserFactory.create()
     self.client.force_login(self.user)
Example #31
0
 def setUp(self):
     self.user = UserFactory.create()
     self.client.force_login(self.user)
Example #32
0
    def setUp(self):
        self.user = UserFactory.create()

        # Sign in but don't migrate account to fxa
        self.client.force_login(self.user)
Example #33
0
 def test_update_vcs_entity_user(self):
     """Track translation authors for use in the commit message."""
     user = UserFactory.create()
     self.update_main_vcs_entity(user=user)
     assert_equal(self.changeset.commit_authors_per_locale['translated-locale'], [user])