当前位置: 首页>>代码示例>>Python>>正文


Python tests.UserFactory类代码示例

本文整理汇总了Python中pontoon.base.tests.UserFactory的典型用法代码示例。如果您正苦于以下问题:Python UserFactory类的具体用法?Python UserFactory怎么用?Python UserFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了UserFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_multiple_translations

    def test_multiple_translations(self):
        """
        If there are multiple translations to the same locale, only authors of
        the final approved version should be returned.
        """
        first_author, second_author = UserFactory.create_batch(2)

        TranslationFactory.create(
            locale=self.translated_locale,
            entity=self.main_db_entity,
            user=first_author,
            approved=True
        )
        TranslationFactory.create(
            locale=self.translated_locale,
            entity=self.main_db_entity,
            user=second_author,
            approved=False
        )

        self.changeset.update_vcs_entity(self.translated_locale, self.main_db_entity, MagicMock())

        self.changeset.execute_update_vcs()

        assert_equal(
            self.changeset.commit_authors_per_locale[self.translated_locale.code],
            [first_author]
        )
开发者ID:MikkCZ,项目名称:pontoon,代码行数:28,代码来源:test_changeset.py

示例2: test_plural_translations

    def test_plural_translations(self):
        """
        If entity has some plural translations and approved translations their authors
        should be included in commit message.
        """
        first_author, second_author, third_author = UserFactory.create_batch(3)

        TranslationFactory.create(
            locale=self.translated_locale,
            entity=self.main_db_entity,
            user=first_author,
            approved=True
        )
        TranslationFactory.create(
            locale=self.translated_locale,
            entity=self.main_db_entity,
            user=third_author,
            approved=True,
            plural_form=1
        )
        TranslationFactory.create(
            locale=self.translated_locale,
            entity=self.main_db_entity,
            user=second_author,
            approved=False
        )

        self.changeset.update_vcs_entity(self.translated_locale, self.main_db_entity, MagicMock())

        self.changeset.execute_update_vcs()

        assert_equal(
            set(self.changeset.commit_authors_per_locale[self.translated_locale.code]),
            {first_author, third_author}
        )
开发者ID:MikkCZ,项目名称:pontoon,代码行数:35,代码来源:test_changeset.py

示例3: test_update_db_unapprove_existing

    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)
        )
开发者ID:transforlab,项目名称:pontoon,代码行数:32,代码来源:test_changeset.py

示例4: test_managers_group

    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)
开发者ID:dsaumyajit007,项目名称:pontoon,代码行数:31,代码来源:test_models.py

示例5: setUp

    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()
开发者ID:MekliCZ,项目名称:pontoon,代码行数:9,代码来源:test_adapter.py

示例6: create_contributor_with_translation_counts

 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
开发者ID:dsaumyajit007,项目名称:pontoon,代码行数:9,代码来源:test_models.py

示例7: test_users_without_translations

    def test_users_without_translations(self):
        """
        Checks if user contributors without translations aren't returned.
        """
        active_contributor = TranslationFactory.create(user__email="[email protected]").user
        inactive_contributor = UserFactory.create(email="[email protected]")

        top_contributors = User.translators.with_translation_counts()
        assert_true(active_contributor in top_contributors)
        assert_true(inactive_contributor not in top_contributors)
开发者ID:dsaumyajit007,项目名称:pontoon,代码行数:10,代码来源:test_models.py

示例8: test_non_active_contributor

 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'
         }
     ])
开发者ID:bychek-ru,项目名称:pontoon,代码行数:11,代码来源:test_views.py

示例9: test_basic

    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)
        )
开发者ID:rajul,项目名称:pontoon,代码行数:13,代码来源:test_core.py

示例10: test_commit_changes

    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'
        )
开发者ID:vivekanand1101,项目名称:pontoon,代码行数:14,代码来源:test_sync_projects.py

示例11: test_multiple_authors

    def test_multiple_authors(self):
        """
        Tests if multiple authors are passed to commit message.
        """
        first_author, second_author = UserFactory.create_batch(2)
        self.changeset.commit_authors_per_locale = {
            self.translated_locale.code: [first_author, second_author]
        }
        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(first_author.display_name, second_author.display_name),
            first_author,
            os.path.join(FAKE_CHECKOUT_PATH, self.translated_locale.code)
        )
开发者ID:G33KS44n,项目名称:pontoon,代码行数:16,代码来源:test_core.py

示例12: test_author_with_multiple_contributions

    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)
开发者ID:mastizada,项目名称:pontoon,代码行数:16,代码来源:test_core.py

示例13: test_update_db_reject_approved

    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,
        )
开发者ID:MikkCZ,项目名称:pontoon,代码行数:17,代码来源:test_changeset.py

示例14: test_update_db_reject_approved_skip_fuzzy

    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,
        )
开发者ID:MikkCZ,项目名称:pontoon,代码行数:19,代码来源:test_changeset.py

示例15: test_multiple_authors

    def test_multiple_authors(self):
        """
        Commit message should include authors from translations of separate
        entities.
        """
        first_author, second_author = UserFactory.create_batch(2)
        TranslationFactory.create(
            locale=self.translated_locale,
            entity=self.main_db_entity,
            user=first_author,
            approved=True
        )
        TranslationFactory.create(
            locale=self.translated_locale,
            entity=self.main_db_entity,
            approved=False
        )
        TranslationFactory.create(
            locale=self.translated_locale,
            entity=self.other_db_entity,
            user=second_author,
            approved=True
        )
        TranslationFactory.create(
            locale=self.translated_locale,
            entity=self.other_db_entity,
            approved=False
        )

        self.changeset.update_vcs_entity(self.translated_locale, self.main_db_entity, MagicMock())
        self.changeset.update_vcs_entity(self.translated_locale, self.other_db_entity, MagicMock())

        self.changeset.execute_update_vcs()

        assert_equal(
            self.changeset.commit_authors_per_locale[self.translated_locale.code],
            [first_author, second_author]
        )
开发者ID:MikkCZ,项目名称:pontoon,代码行数:38,代码来源:test_changeset.py


注:本文中的pontoon.base.tests.UserFactory类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。