本文整理汇总了Python中tests.factories.UserFactory类的典型用法代码示例。如果您正苦于以下问题:Python UserFactory类的具体用法?Python UserFactory怎么用?Python UserFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了UserFactory类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: TestSearchExceptions
class TestSearchExceptions(OsfTestCase):
"""
Verify that the correct exception is thrown when the connection is lost
"""
@classmethod
def setUpClass(cls):
logging.getLogger('website.project.model').setLevel(logging.CRITICAL)
super(TestSearchExceptions, cls).setUpClass()
if settings.SEARCH_ENGINE == 'elastic':
cls._es = search.search_engine.es
search.search_engine.es = None
@classmethod
def tearDownClass(cls):
super(TestSearchExceptions, cls).tearDownClass()
if settings.SEARCH_ENGINE == 'elastic':
search.search_engine.es = cls._es
def test_connection_error(self):
# Ensures that saving projects/users doesn't break as a result of connection errors
self.user = UserFactory(usename='Doug Bogie')
self.project = ProjectFactory(
title="Tom Sawyer",
creator=self.user,
is_public=True,
)
self.user.save()
self.project.save()
开发者ID:PatrickEGorman,项目名称:osf.io,代码行数:29,代码来源:test_elastic.py
示例2: test_userfactory
def test_userfactory(session):
user = UserFactory()
user.save()
assert isinstance(user, User)
assert user.id is not None
assert user.email is not None
assert user.active is not None
开发者ID:DBeath,项目名称:flask-feedrsub,代码行数:7,代码来源:factory_test.py
示例3: setUp
def setUp(self):
super(TestMigrateProfileWebsites, self).setUp()
self.user_one = UserFactory.build(
fullname="Martin Luther King",
social=dict(
github="userOneGithub",
scholar="userOneScholar",
personal="http://www.useronewebsite.com",
twitter="userOneTwitter",
linkedIn="userOneLinkedIn",
impactStory="userOneImpactStory",
orcid="userOneOrcid",
researcherId="userOneResearcherId",
),
)
self.user_one.save()
self.user_two = UserFactory.build(
fullname="el-Hajj Malik el-Shabazz",
social=dict(
github="userTwoGithub",
scholar="userTwoScholar",
profileWebsites=["http://www.usertwowebsite.com"],
twitter="userTwoTwitter",
linkedIn="userTwoLinkedIn",
impactStory="userTwoImpactStory",
orcid="userTwoOrcid",
researcherId="userTwoResearcherId",
),
)
self.user_two.save()
self.user_three = UserFactory()
开发者ID:Alpani,项目名称:osf.io,代码行数:33,代码来源:test_migrate_profile_websites.py
示例4: TestDisableUser
class TestDisableUser(AdminTestCase):
def setUp(self):
self.user = UserFactory()
self.request = RequestFactory().post('/fake_path')
self.view = UserDeleteView()
self.view = setup_log_view(self.view, self.request, guid=self.user._id)
def test_get_object(self):
obj = self.view.get_object()
nt.assert_is_instance(obj, User)
def test_get_context(self):
res = self.view.get_context_data(object=self.user)
nt.assert_in('guid', res)
nt.assert_equal(res.get('guid'), self.user._id)
def test_disable_user(self):
settings.ENABLE_EMAIL_SUBSCRIPTIONS = False
count = OSFLogEntry.objects.count()
self.view.delete(self.request)
self.user.reload()
nt.assert_true(self.user.is_disabled)
nt.assert_equal(OSFLogEntry.objects.count(), count + 1)
def test_reactivate_user(self):
settings.ENABLE_EMAIL_SUBSCRIPTIONS = False
self.view.delete(self.request)
count = OSFLogEntry.objects.count()
self.view.delete(self.request)
self.user.reload()
nt.assert_false(self.user.is_disabled)
nt.assert_equal(OSFLogEntry.objects.count(), count + 1)
开发者ID:545zhou,项目名称:osf.io,代码行数:32,代码来源:test_views.py
示例5: test_migration
def test_migration(self):
BoxUserSettings.remove()
user = UserFactory()
node = ProjectFactory(creator=user)
account = BoxAccountFactory()
user.external_accounts = [account]
user.add_addon('box', auth=Auth(user))
user_addon = user.get_addon('box')
user_addon.save()
node.add_addon('box', auth=Auth(user))
node_addon = node.get_addon('box')
node_addon.foreign_user_settings = user_addon
node_addon.folder_id = 'abcdef0'
node_addon.folder_path = '/'
node_addon.folder_name = '/ (Full Box)'
node_addon.save()
assert_equal(node_addon.external_account, None)
assert_equal(node_addon.folder_id, 'abcdef0')
do_migration()
node_addon.reload()
assert_equal(node_addon.external_account, account)
assert_equal(node_addon.folder_id, 'abcdef0')
assert_equal(node_addon.folder_path, '/')
assert_equal(node_addon.folder_name, '/ (Full Box)')
开发者ID:545zhou,项目名称:osf.io,代码行数:32,代码来源:test_box_connect_external_accounts.py
示例6: TestDisableSpamUser
class TestDisableSpamUser(AdminTestCase):
def setUp(self):
self.user = UserFactory()
self.public_node = ProjectFactory(creator=self.user, is_public=True)
self.public_node = ProjectFactory(creator=self.user, is_public=False)
self.request = RequestFactory().post('/fake_path')
self.view = SpamUserDeleteView()
self.view = setup_log_view(self.view, self.request, guid=self.user._id)
def test_get_object(self):
obj = self.view.get_object()
nt.assert_is_instance(obj, User)
def test_get_context(self):
res = self.view.get_context_data(object=self.user)
nt.assert_in('guid', res)
nt.assert_equal(res.get('guid'), self.user._id)
def test_disable_spam_user(self):
settings.ENABLE_EMAIL_SUBSCRIPTIONS = False
count = OSFLogEntry.objects.count()
self.view.delete(self.request)
self.user.reload()
self.public_node.reload()
nt.assert_true(self.user.is_disabled)
nt.assert_false(self.public_node.is_public)
nt.assert_equal(OSFLogEntry.objects.count(), count + 3)
def test_no_user(self):
view = setup_view(UserDeleteView(), self.request, guid='meh')
with nt.assert_raises(Http404):
view.delete(self.request)
开发者ID:baylee-d,项目名称:osf.io,代码行数:32,代码来源:test_views.py
示例7: test_increment_user_activity_counters
def test_increment_user_activity_counters(self):
user = UserFactory()
date = datetime.utcnow()
assert_equal(user.get_activity_points(db=self.db), 0)
analytics.increment_user_activity_counters(user._id, 'project_created', date, db=self.db)
assert_equal(user.get_activity_points(db=self.db), 1)
开发者ID:545zhou,项目名称:osf.io,代码行数:7,代码来源:test_analytics.py
示例8: test_user
def test_user(self):
with self.instance.test_request_context() as request:
u = UserFactory(login='john', email='[email protected]')
self.assertTrue(u.is_authenticated())
self.assertTrue(u.is_active())
self.assertFalse(u.is_anonymous())
开发者ID:clayman74,项目名称:jotun,代码行数:7,代码来源:test_core.py
示例9: setUp
def setUp(self):
super(TestUserNodes, self).setUp()
self.user_one = UserFactory.build()
self.user_one.set_password('justapoorboy')
self.user_one.social['twitter'] = 'howtopizza'
self.user_one.save()
self.auth_one = (self.user_one.username, 'justapoorboy')
self.user_two = UserFactory.build()
self.user_two.set_password('justapoorboy')
self.user_two.save()
self.auth_two = (self.user_two.username, 'justapoorboy')
self.public_project_user_one = ProjectFactory(title="Public Project User One",
is_public=True,
creator=self.user_one)
self.private_project_user_one = ProjectFactory(title="Private Project User One",
is_public=False,
creator=self.user_one)
self.public_project_user_two = ProjectFactory(title="Public Project User Two",
is_public=True,
creator=self.user_two)
self.private_project_user_two = ProjectFactory(title="Private Project User Two",
is_public=False,
creator=self.user_two)
self.deleted_project_user_one = FolderFactory(title="Deleted Project User One",
is_public=False,
creator=self.user_one,
is_deleted=True)
self.folder = FolderFactory()
self.deleted_folder = FolderFactory(title="Deleted Folder User One",
is_public=False,
creator=self.user_one,
is_deleted=True)
self.dashboard = DashboardFactory()
开发者ID:XTech2K,项目名称:osf.io,代码行数:33,代码来源:test_views.py
示例10: test_email_uniqueness_case_insensitive
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."])
开发者ID:inducer,项目名称:relate,代码行数:7,代码来源:test_models.py
示例11: get_redirect_response
class TestSignInRedirect:
def get_redirect_response(self, client, next=None):
password = "password"
self.user = UserFactory()
self.user.set_password(password)
self.user.save()
url = reverse("userena_signin")
if next:
url += f"?next={next}"
return client.post(
url,
data={"identification": self.user.username, "password": password},
follow=True,
)
def test_default_redirect(self, client):
response = self.get_redirect_response(client)
assert response.redirect_chain[0][1] == status.HTTP_302_FOUND
assert response.redirect_chain[0][0] == reverse("profile_redirect")
assert response.status_code == status.HTTP_200_OK
def test_redirect(self, client):
expected_url = "/challenges/"
response = self.get_redirect_response(client, expected_url)
assert response.redirect_chain[0][1] == status.HTTP_302_FOUND
assert response.status_code == status.HTTP_200_OK
assert response.redirect_chain[0][0] == expected_url
def test_no_logout_redirect(self, client):
response = self.get_redirect_response(client, settings.LOGOUT_URL)
assert response.redirect_chain[0][1] == status.HTTP_302_FOUND
assert response.redirect_chain[0][0] == reverse("profile_redirect")
assert response.status_code == status.HTTP_200_OK
开发者ID:comic,项目名称:comic-django,代码行数:34,代码来源:test_views.py
示例12: TestSearchExceptions
class TestSearchExceptions(OsfTestCase):
"""
Verify that the correct exception is thrown when the connection is lost
"""
@classmethod
def setUpClass(cls):
super(TestSearchExceptions, cls).setUpClass()
if settings.SEARCH_ENGINE == "elastic":
cls._es = search.search_engine.es
search.search_engine.es = None
@classmethod
def tearDownClass(cls):
super(TestSearchExceptions, cls).tearDownClass()
if settings.SEARCH_ENGINE == "elastic":
search.search_engine.es = cls._es
def test_connection_error(self):
"""
Ensures that saving projects/users doesn't break as a result of connection errors
"""
self.user = UserFactory(usename="Doug Bogie")
self.project = ProjectFactory(title="Tom Sawyer", creator=self.user, is_public=True)
self.user.save()
self.project.save()
开发者ID:erinmayhood,项目名称:osf.io,代码行数:26,代码来源:test_elastic.py
示例13: setUp
def setUp(self):
super(TestMigrateMailingLists, self).setUp()
self.user1 = UserFactory(mailing_lists={'mail': True})
self.user2 = UserFactory(mailing_lists={'mail': False})
self.user3 = UserFactory()
self.user1.save()
self.user2.save()
开发者ID:545zhou,项目名称:osf.io,代码行数:7,代码来源:test_migrate_mailing_lists_to_mailchimp_field.py
示例14: TestNodeSettings
class TestNodeSettings(OsfTestCase):
def setUp(self):
super(TestNodeSettings, self).setUp()
self.user = UserFactory()
self.project = ProjectFactory(creator=self.user)
self.user.add_addon('s3')
self.project.add_addon('s3', auth=Auth(self.user))
self.user_settings = self.user.get_addon('s3')
self.node_settings = self.project.get_addon('s3')
self.user_settings.access_key = 'We-Will-Rock-You'
self.user_settings.secret_key = 'Idontknowanyqueensongs'
self.user_settings.save()
self.node_settings.bucket = 'Sheer-Heart-Attack'
self.node_settings.user_settings = self.user_settings
self.node_settings.save()
def test_complete_true(self):
assert_true(self.node_settings.has_auth)
assert_true(self.node_settings.complete)
def test_complete_false(self):
self.node_settings.bucket = None
assert_true(self.node_settings.has_auth)
assert_false(self.node_settings.complete)
def test_complete_auth_false(self):
self.node_settings.user_settings = None
assert_false(self.node_settings.has_auth)
assert_false(self.node_settings.complete)
开发者ID:XTech2K,项目名称:osf.io,代码行数:35,代码来源:test_model.py
示例15: setUp
def setUp(self):
super(TestMergingAccounts, self).setUp()
self.user = UserFactory.build()
self.user.set_password('science')
self.user.save()
self.dupe = UserFactory.build()
self.dupe.set_password('example')
self.dupe.save()
开发者ID:rohan-bajaj,项目名称:osf.io,代码行数:8,代码来源:webtest_tests.py
示例16: test_no_two_emails_to_same_person
def test_no_two_emails_to_same_person(self, mock_send):
user = UserFactory()
user.osf_mailing_lists[settings.OSF_HELP_LIST] = True
user.save()
self.queue_mail(user=user)
self.queue_mail(user=user)
main(dry_run=False)
assert_equal(mock_send.call_count, 1)
开发者ID:545zhou,项目名称:osf.io,代码行数:8,代码来源:test_send_queued_mails.py
示例17: test_authenticate_using_token
def test_authenticate_using_token(self):
user = UserFactory.create()
exists, auth_user = User.authenticate(email=user.email, password=UserFactory.get_default_password())
expect(auth_user).not_to_be_null()
auth_user = User.authenticate_with_token(token=auth_user.token)
expect(auth_user).not_to_be_null()
开发者ID:heynemann,项目名称:wight,代码行数:8,代码来源:test_user_model.py
示例18: TestGithubNodeSettings
class TestGithubNodeSettings(OsfTestCase):
def setUp(self):
OsfTestCase.setUp(self)
self.user = UserFactory()
self.user.add_addon('github')
self.user_settings = self.user.get_addon('github')
self.external_account = GitHubAccountFactory()
self.user_settings.owner.external_accounts.append(self.external_account)
self.user_settings.owner.save()
self.node_settings = GitHubNodeSettingsFactory(user_settings=self.user_settings)
@mock.patch('website.addons.github.api.GitHubClient.delete_hook')
def test_delete_hook(self, mock_delete_hook):
self.node_settings.hook_id = 'hook'
self.node_settings.save()
args = (
self.node_settings.user,
self.node_settings.repo,
self.node_settings.hook_id,
)
res = self.node_settings.delete_hook()
assert_true(res)
mock_delete_hook.assert_called_with(*args)
@mock.patch('website.addons.github.api.GitHubClient.delete_hook')
def test_delete_hook_no_hook(self, mock_delete_hook):
res = self.node_settings.delete_hook()
assert_false(res)
assert_false(mock_delete_hook.called)
@mock.patch('website.addons.github.api.GitHubClient.delete_hook')
def test_delete_hook_not_found(self, mock_delete_hook):
self.node_settings.hook_id = 'hook'
self.node_settings.save()
mock_delete_hook.side_effect = NotFoundError
args = (
self.node_settings.user,
self.node_settings.repo,
self.node_settings.hook_id,
)
res = self.node_settings.delete_hook()
assert_false(res)
mock_delete_hook.assert_called_with(*args)
@mock.patch('website.addons.github.api.GitHubClient.delete_hook')
def test_delete_hook_error(self, mock_delete_hook):
self.node_settings.hook_id = 'hook'
self.node_settings.save()
mock_delete_hook.side_effect = GitHubError(mock.Mock())
args = (
self.node_settings.user,
self.node_settings.repo,
self.node_settings.hook_id,
)
res = self.node_settings.delete_hook()
assert_false(res)
mock_delete_hook.assert_called_with(*args)
开发者ID:545zhou,项目名称:osf.io,代码行数:58,代码来源:test_models.py
示例19: setUp
def setUp(self):
super(TestMergingAccounts, self).setUp()
self.user = UserFactory.build()
self.user.fullname = "tess' test string"
self.user.set_password("science")
self.user.save()
self.dupe = UserFactory.build()
self.dupe.set_password("example")
self.dupe.save()
开发者ID:Alpani,项目名称:osf.io,代码行数:9,代码来源:webtest_tests.py
示例20: test_create_user
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
开发者ID:womenhackfornonprofits,项目名称:ocdaction,代码行数:10,代码来源:test_profiles.py
注:本文中的tests.factories.UserFactory类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论