本文整理汇总了Python中pontoon.base.tests.UserFactory.create方法的典型用法代码示例。如果您正苦于以下问题:Python UserFactory.create方法的具体用法?Python UserFactory.create怎么用?Python UserFactory.create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pontoon.base.tests.UserFactory
的用法示例。
在下文中一共展示了UserFactory.create方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_update_db_unapprove_existing
# 需要导入模块: from pontoon.base.tests import UserFactory [as 别名]
# 或者: from pontoon.base.tests.UserFactory import create [as 别名]
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)
)
示例2: test_managers_group
# 需要导入模块: from pontoon.base.tests import UserFactory [as 别名]
# 或者: from pontoon.base.tests.UserFactory import create [as 别名]
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)
示例3: create_contributor_with_translation_counts
# 需要导入模块: from pontoon.base.tests import UserFactory [as 别名]
# 或者: from pontoon.base.tests.UserFactory import create [as 别名]
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
示例4: setUp
# 需要导入模块: from pontoon.base.tests import UserFactory [as 别名]
# 或者: from pontoon.base.tests.UserFactory import create [as 别名]
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()
示例5: test_users_without_translations
# 需要导入模块: from pontoon.base.tests import UserFactory [as 别名]
# 或者: from pontoon.base.tests.UserFactory import create [as 别名]
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)
示例6: test_non_active_contributor
# 需要导入模块: from pontoon.base.tests import UserFactory [as 别名]
# 或者: from pontoon.base.tests.UserFactory import create [as 别名]
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'
}
])
示例7: test_basic
# 需要导入模块: from pontoon.base.tests import UserFactory [as 别名]
# 或者: from pontoon.base.tests.UserFactory import create [as 别名]
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)
)
示例8: test_commit_changes
# 需要导入模块: from pontoon.base.tests import UserFactory [as 别名]
# 或者: from pontoon.base.tests.UserFactory import create [as 别名]
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'
)
示例9: test_author_with_multiple_contributions
# 需要导入模块: from pontoon.base.tests import UserFactory [as 别名]
# 或者: from pontoon.base.tests.UserFactory import create [as 别名]
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)
示例10: test_update_db_reject_approved
# 需要导入模块: from pontoon.base.tests import UserFactory [as 别名]
# 或者: from pontoon.base.tests.UserFactory import create [as 别名]
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,
)
示例11: test_update_db_reject_approved_skip_fuzzy
# 需要导入模块: from pontoon.base.tests import UserFactory [as 别名]
# 或者: from pontoon.base.tests.UserFactory import create [as 别名]
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,
)
示例12: test_update_vcs_entity_user
# 需要导入模块: from pontoon.base.tests import UserFactory [as 别名]
# 或者: from pontoon.base.tests.UserFactory import create [as 别名]
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])
示例13: setUp
# 需要导入模块: from pontoon.base.tests import UserFactory [as 别名]
# 或者: from pontoon.base.tests.UserFactory import create [as 别名]
def setUp(self):
self.user = UserFactory.create()
self.client.force_login(self.user)