本文整理汇总了Python中tests.factories.UserFactory.create方法的典型用法代码示例。如果您正苦于以下问题:Python UserFactory.create方法的具体用法?Python UserFactory.create怎么用?Python UserFactory.create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tests.factories.UserFactory
的用法示例。
在下文中一共展示了UserFactory.create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_email_uniqueness_case_insensitive
# 需要导入模块: from tests.factories import UserFactory [as 别名]
# 或者: from tests.factories.UserFactory import create [as 别名]
def test_email_uniqueness_case_insensitive(self):
UserFactory.create(email="[email protected]")
with self.assertRaises(ValidationError) as error:
UserFactory.create(email="[email protected]")
self.assertEqual(
error.exception.messages,
["That email address is already in use."])
示例2: test_create_user
# 需要导入模块: from tests.factories import UserFactory [as 别名]
# 或者: from tests.factories.UserFactory import create [as 别名]
def test_create_user():
# Check there are 0 users before a new user is added
number_users = OCDActionUser.objects.count()
assert number_users == 0
# Check there is 1 user after a new user is added
UserFactory.create()
number_users = OCDActionUser.objects.count()
assert number_users == 1
示例3: test_get_email_appellation_priority_list
# 需要导入模块: from tests.factories import UserFactory [as 别名]
# 或者: from tests.factories.UserFactory import create [as 别名]
def test_get_email_appellation_priority_list(self):
user = UserFactory.create(first_name="my_first", last_name="my_last")
from accounts.utils import relate_user_method_settings
relate_user_method_settings.__dict__ = {}
with override_settings(
RELATE_USER_FULL_NAME_FORMAT_METHOD=None):
self.assertEqual(user.get_email_appellation(), "my_first")
relate_user_method_settings.__dict__ = {}
with override_settings(
RELATE_EMAIL_APPELLATION_PRIORITY_LIST=[""]):
relate_user_method_settings.__dict__ = {}
self.assertEqual(user.get_email_appellation(), "my_first")
relate_user_method_settings.__dict__ = {}
with override_settings(
RELATE_EMAIL_APPELLATION_PRIORITY_LIST=["whatever"]):
self.assertEqual(user.get_email_appellation(), "my_first")
relate_user_method_settings.__dict__ = {}
# not a list
with override_settings(
RELATE_EMAIL_APPELLATION_PRIORITY_LIST="whatever"):
self.assertEqual(user.get_email_appellation(), "my_first")
relate_user_method_settings.__dict__ = {}
with override_settings(
RELATE_EMAIL_APPELLATION_PRIORITY_LIST=["full_name"],
RELATE_USER_FULL_NAME_FORMAT_METHOD=None):
self.assertEqual(user.get_email_appellation(), "my_first my_last")
# create a user without first_name
user = UserFactory.create(last_name="my_last")
relate_user_method_settings.__dict__ = {}
# the next appelation is email
with override_settings(
RELATE_USER_FULL_NAME_FORMAT_METHOD=None):
self.assertEqual(user.get_email_appellation(), user.email)
relate_user_method_settings.__dict__ = {}
with override_settings(
RELATE_EMAIL_APPELLATION_PRIORITY_LIST=["full_name", "username"],
RELATE_USER_FULL_NAME_FORMAT_METHOD=None):
# because full_name is None
self.assertEqual(user.get_email_appellation(), user.username)
示例4: test_cant_have_same_member_twice
# 需要导入模块: from tests.factories import UserFactory [as 别名]
# 或者: from tests.factories.UserFactory import create [as 别名]
def test_cant_have_same_member_twice(self):
u1 = UserFactory.create()
u2 = UserFactory.create()
try:
Team.create(name="test-team-same-member-twice", owner=u1, members=[u2, u2])
except ValueError:
ex = sys.exc_info()[1]
expect(ex).to_have_an_error_message_of("Can't have the same user twice in the members collection.")
return
assert False, "Should not have gotten this far"
示例5: test_get_hikes_not_authenticated
# 需要导入模块: from tests.factories import UserFactory [as 别名]
# 或者: from tests.factories.UserFactory import create [as 别名]
def test_get_hikes_not_authenticated(self):
user1 = UserFactory.create()
hike1 = HikeFactory.create(owner=user1)
user2 = UserFactory.create()
hike2 = HikeFactory.create(owner=user2)
url = reverse('hike-list')
self.client.force_authenticate(user=user1)
response = self.client.get(url)
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertContains(response, hike1.uuid)
self.assertNotContains(response, hike2.uuid)
示例6: test_remove_user
# 需要导入模块: from tests.factories import UserFactory [as 别名]
# 或者: from tests.factories.UserFactory import create [as 别名]
def test_remove_user(self):
user = UserFactory.create()
user2 = UserFactory.create()
team = TeamFactory.create(owner=self.user, members=[user2])
response = self.delete("/teams/%s/members" % team.name, user=user2.email)
expect(response.code).to_equal(200)
expect(response.body).to_equal("OK")
team = Team.objects.filter(name=team.name).first()
expect(team).not_to_be_null()
expect(team.members).to_length(0)
expect(team.members).not_to_include(user)
示例7: setUp
# 需要导入模块: from tests.factories import UserFactory [as 别名]
# 或者: from tests.factories.UserFactory import create [as 别名]
def setUp(self):
# feincms page containing zipfelchappe app content
self.page = Page.objects.create(title="Projects", slug="projects")
ct = self.page.content_type_for(ApplicationContent)
ct.objects.create(parent=self.page, urlconf_path=app_settings.ROOT_URLS)
# Fixture Data for following tests
self.project1 = ProjectFactory.create()
self.project2 = ProjectFactory.create()
self.user = UserFactory.create()
self.admin = UserFactory.create(is_superuser=True, is_staff=True)
self.reward = RewardFactory.create(project=self.project1, minimum=20.00, quantity=1)
# Fresh Client for every test
self.client = Client()
示例8: test_after_adding_a_editor_to_a_map_a_editor_added_action_is_triggered
# 需要导入模块: from tests.factories import UserFactory [as 别名]
# 或者: from tests.factories.UserFactory import create [as 别名]
def test_after_adding_a_editor_to_a_map_a_editor_added_action_is_triggered(self):
a_user = UserFactory.create()
a_map = MapFactory.create(creator=a_user)
another_user = UserFactory.create()
a_map.editors.add(another_user)
am = ActivityManager()
added_to_editors = am.added_to_editors(a_user)
self.assertTrue(len(added_to_editors))
action = added_to_editors[0]
self.assertEqual(action.actor, a_user)
self.assertEqual(action.action_object, another_user)
self.assertEqual(action.target, a_map)
self.assertEqual(action.verb, ADDED_TO_EDITORS)
示例9: test_custom_get_full_name_method_failed
# 需要导入模块: from tests.factories import UserFactory [as 别名]
# 或者: from tests.factories.UserFactory import create [as 别名]
def test_custom_get_full_name_method_failed(self):
"""
Test when RELATE_USER_FULL_NAME_FORMAT_METHOD failed, default method
is used.
"""
user = UserFactory.create(first_name="my_first", last_name="my_last")
default_get_full_name = user.get_full_name()
custom_get_full_name_path = (
"tests.resource.my_customized_get_full_name_method")
get_custom_full_name_method_path = (
"accounts.utils.RelateUserMethodSettingsInitializer"
".custom_full_name_method")
with override_settings(
RELATE_USER_FULL_NAME_FORMAT_METHOD=custom_get_full_name_path):
from accounts.utils import relate_user_method_settings
# clear cached value
relate_user_method_settings.__dict__ = {}
# If custom method works, the returned value is different with
# default value.
self.assertNotEqual(default_get_full_name, user.get_full_name())
with mock.patch(get_custom_full_name_method_path) as mock_custom_method:
# clear cached value
relate_user_method_settings.__dict__ = {}
# raise an error when calling custom method
mock_custom_method.side_effect = Exception()
# the value falls back to default value
self.assertEqual(user.get_full_name(), default_get_full_name)
示例10: test_get_authenticated
# 需要导入模块: from tests.factories import UserFactory [as 别名]
# 或者: from tests.factories.UserFactory import create [as 别名]
def test_get_authenticated(self):
"""Authenticated users can view add resource page."""
self.login_user(UserFactory.create())
response = self._get(url=self.url)
self.assertEquals(response.status_code, 200)
self.assertTemplateUsed(response, self.template_name)
self.failUnless('form' in response.context)
示例11: test_get_return_200_if_not_team_owner
# 需要导入模块: from tests.factories import UserFactory [as 别名]
# 或者: from tests.factories.UserFactory import create [as 别名]
def test_get_return_200_if_not_team_owner(self):
self._add_results_for_last()
user = UserFactory.create(with_token=True)
TeamFactory.create(owner=user)
url = "/load-test-result/%s/last/" % self.load_test2.results[1].uuid
response = self.fetch_with_headers(url)
expect(response.code).to_equal(200)
示例12: test_get_notes
# 需要导入模块: from tests.factories import UserFactory [as 别名]
# 或者: from tests.factories.UserFactory import create [as 别名]
def test_get_notes(self):
user1 = UserFactory.create()
note1 = NoteFactory.create(owner=user1)
user2 = UserFactory.create()
note2 = NoteFactory.create(owner=user2)
url = reverse('note-list')
self.client.force_authenticate(user=user1)
response = self.client.get(url)
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertContains(response, note1.uuid)
self.assertContains(response, note1.revision)
self.assertContains(response, note1.text)
self.assertContains(response, note1.title)
self.assertNotContains(response, note2.uuid)
示例13: test_add_team_member_twice
# 需要导入模块: from tests.factories import UserFactory [as 别名]
# 或者: from tests.factories.UserFactory import create [as 别名]
def test_add_team_member_twice(self):
user = UserFactory.create()
team = TeamFactory.create(owner=self.user, members=[user])
response = self.patch("/teams/%s/members" % team.name, user=user.email)
expect(response.code).to_equal(409)
expect(response.body).to_equal("User already team member")
示例14: test_after_removing_a_editor_from_a_map_a_editor_removed_action_is_triggered
# 需要导入模块: from tests.factories import UserFactory [as 别名]
# 或者: from tests.factories.UserFactory import create [as 别名]
def test_after_removing_a_editor_from_a_map_a_editor_removed_action_is_triggered(self):
a_user = UserFactory.create()
a_map = MapFactory.create(creator=a_user)
another_user = UserFactory.create()
a_map.editors.add(another_user)
a_map.editors.remove(another_user)
am = ActivityManager()
removed_from_editors = am.removed_from_editors(a_user)
self.assertTrue(len(removed_from_editors))
action = removed_from_editors[0]
self.assertEqual(action.actor, a_user)
self.assertEqual(action.action_object, another_user)
self.assertEqual(action.target, a_map)
self.assertEqual(action.verb, REMOVED_FROM_EDITORS)
示例15: test_try_to_delete_a_not_owner_team
# 需要导入模块: from tests.factories import UserFactory [as 别名]
# 或者: from tests.factories.UserFactory import create [as 别名]
def test_try_to_delete_a_not_owner_team(self):
team = TeamFactory.create(owner=UserFactory.create(with_token=True))
response = self.delete("/teams/%s" % team.name)
expect(response.code).to_equal(403)
team = Team.objects.filter(name=team.name).first()
expect(team).not_to_be_null()