本文整理汇总了Python中osf_tests.factories.UserFactory.save方法的典型用法代码示例。如果您正苦于以下问题:Python UserFactory.save方法的具体用法?Python UserFactory.save怎么用?Python UserFactory.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类osf_tests.factories.UserFactory
的用法示例。
在下文中一共展示了UserFactory.save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestHamUserRestore
# 需要导入模块: from osf_tests.factories import UserFactory [as 别名]
# 或者: from osf_tests.factories.UserFactory import save [as 别名]
class TestHamUserRestore(AdminTestCase):
def setUp(self):
self.user = UserFactory()
self.request = RequestFactory().post('/fake_path')
self.view = views.HamUserRestoreView
self.view = setup_log_view(self.view, self.request, guid=self.user._id)
self.spam_confirmed, created = Tag.objects.get_or_create(name='spam_confirmed')
self.ham_confirmed, created = Tag.objects.get_or_create(name='ham_confirmed')
def test_get_object(self):
obj = self.view().get_object()
nt.assert_is_instance(obj, OSFUser)
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_enable_user(self):
self.user.disable_account()
self.user.save()
nt.assert_true(self.user.is_disabled)
self.view().delete(self.request)
self.user.reload()
nt.assert_false(self.user.is_disabled)
nt.assert_false(self.user.all_tags.filter(name=self.spam_confirmed.name).exists())
nt.assert_true(self.user.all_tags.filter(name=self.ham_confirmed.name).exists())
示例2: test_no_two_emails_to_same_person
# 需要导入模块: from osf_tests.factories import UserFactory [as 别名]
# 或者: from osf_tests.factories.UserFactory import save [as 别名]
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)
示例3: test_revoke_remote_access_not_called
# 需要导入模块: from osf_tests.factories import UserFactory [as 别名]
# 或者: from osf_tests.factories.UserFactory import save [as 别名]
def test_revoke_remote_access_not_called(self):
user2 = UserFactory()
user2.external_accounts.add(self.external_account)
user2.save()
with mock.patch.object(self.user_settings, 'revoke_remote_oauth_access') as mock_revoke:
with mock_auth(self.user):
self.user_settings.revoke_oauth_access(self.external_account)
assert_equal(mock_revoke.call_count, 0)
示例4: test_multiple_users_associated
# 需要导入模块: from osf_tests.factories import UserFactory [as 别名]
# 或者: from osf_tests.factories.UserFactory import save [as 别名]
def test_multiple_users_associated(self):
# Create only one ExternalAccount for multiple OSF users
#
# For some providers (ex: GitHub), the act of completing the OAuth flow
# revokes previously generated credentials. In addition, there is often no
# way to know the user's id on the external service until after the flow
# has completed.
#
# Having only one ExternalAccount instance per account on the external
# service means that connecting subsequent OSF users to the same external
# account will not invalidate the credentials used by the OSF for users
# already associated.
user_a = UserFactory()
external_account = ExternalAccountFactory(
provider='mock2',
provider_id='mock_provider_id',
provider_name='Mock Provider',
)
user_a.external_accounts.add(external_account)
user_a.save()
user_b = UserFactory()
# Mock the exchange of the code for an access token
_prepare_mock_oauth2_handshake_response()
# Fake a request context for the callback
with self.app.app.test_request_context(
path="/oauth/callback/mock2/",
query_string="code=mock_code&state=mock_state"
) as ctx:
# make sure the user is logged in
authenticate(user=user_b, access_token=None, response=None)
session.data['oauth_states'] = {
self.provider.short_name: {
'state': 'mock_state',
},
}
session.save()
# do the key exchange
self.provider.auth_callback(user=user_b)
user_a.reload()
user_b.reload()
external_account.reload()
assert_equal(
list(user_a.external_accounts.values_list('pk', flat=True)),
list(user_b.external_accounts.values_list('pk', flat=True)),
)
assert_equal(
ExternalAccount.objects.all().count(),
1
)
示例5: create_fake_user
# 需要导入模块: from osf_tests.factories import UserFactory [as 别名]
# 或者: from osf_tests.factories.UserFactory import save [as 别名]
def create_fake_user():
email = fake_email()
name = fake.name()
user = UserFactory(username=email, fullname=name,
is_registered=True, emails=[email],
date_registered=fake.date_time(tzinfo=pytz.UTC),
)
user.set_password('faker123')
user.save()
logger.info('Created user: {0} <{1}>'.format(user.fullname, user.username))
return user
示例6: TestDisabledUser
# 需要导入模块: from osf_tests.factories import UserFactory [as 别名]
# 或者: from osf_tests.factories.UserFactory import save [as 别名]
class TestDisabledUser(OsfTestCase):
def setUp(self):
super(TestDisabledUser, self).setUp()
self.user = UserFactory()
self.user.set_password('Korben Dallas')
self.user.is_disabled = True
self.user.save()
def test_profile_disabled_returns_401(self):
res = self.app.get(self.user.url, expect_errors=True)
assert_equal(res.status_code, 410)
示例7: test_citation_with_only_fullname
# 需要导入模块: from osf_tests.factories import UserFactory [as 别名]
# 或者: from osf_tests.factories.UserFactory import save [as 别名]
def test_citation_with_only_fullname(self):
user = UserFactory()
user.fullname = 'Martin Luther King, Jr.'
user.family_name = ''
user.given_name = ''
user.middle_names = ''
user.suffix = ''
user.save()
resp = user.csl_name()
family_name = resp['family']
given_name = resp['given']
assert_equal(family_name, 'King')
assert_equal(given_name, 'Martin L, Jr.')
示例8: test_correct_view_permissions
# 需要导入模块: from osf_tests.factories import UserFactory [as 别名]
# 或者: from osf_tests.factories.UserFactory import save [as 别名]
def test_correct_view_permissions(self):
user = UserFactory()
guid = user._id
view_permission = Permission.objects.get(codename='view_osfuser')
user.user_permissions.add(view_permission)
user.save()
request = RequestFactory().get(reverse('users:user', kwargs={'guid': guid}))
request.user = user
response = views.UserView.as_view()(request, guid=guid)
self.assertEqual(response.status_code, 200)
示例9: test_disabled_user_csl
# 需要导入模块: from osf_tests.factories import UserFactory [as 别名]
# 或者: from osf_tests.factories.UserFactory import save [as 别名]
def test_disabled_user_csl(self):
# Tests the csl name for a disabled user
user = UserFactory()
project = NodeFactory(creator=user)
user.disable_account()
user.is_registered = False
user.save()
assert bool(
user.csl_name() ==
{
'given': user.csl_given_name,
'family': user.family_name,
}
)
示例10: test_callback_wrong_user
# 需要导入模块: from osf_tests.factories import UserFactory [as 别名]
# 或者: from osf_tests.factories.UserFactory import save [as 别名]
def test_callback_wrong_user(self):
# Reject temporary credentials not assigned to the user
#
# This prohibits users from associating their external account with
# another user's OSF account by using XSS or similar attack vector to
# complete the OAuth flow using the logged-in user but their own account
# on the external service.
#
# If the OSF were to allow login via OAuth with the provider in question,
# this would allow attackers to hijack OSF accounts with a simple script
# injection.
# mock a successful call to the provider to exchange temp keys for
# permanent keys
responses.add(
responses.Response(
responses.POST,
'http://mock1a.com/callback',
body='oauth_token=perm_token'
'&oauth_token_secret=perm_secret'
'&oauth_callback_confirmed=true',
)
)
user = UserFactory()
account = ExternalAccountFactory(
provider="mock1a",
provider_name='Mock 1A',
oauth_key="temp_key",
oauth_secret="temp_secret"
)
account.save()
# associate this ExternalAccount instance with the user
user.external_accounts.add(account)
user.save()
malicious_user = UserFactory()
# Fake a request context for the callback
with self.app.app.test_request_context(
path="/oauth/callback/mock1a/",
query_string="oauth_token=temp_key&oauth_verifier=mock_verifier"
):
# make sure the user is logged in
authenticate(user=malicious_user, access_token=None, response=None)
with assert_raises(PermissionsError):
# do the key exchange
self.provider.auth_callback(user=malicious_user)
示例11: test_password_change_sends_email
# 需要导入模块: from osf_tests.factories import UserFactory [as 别名]
# 或者: from osf_tests.factories.UserFactory import save [as 别名]
def test_password_change_sends_email(self, mock_mail):
user = UserFactory()
user.set_password('killerqueen')
user.save()
assert_equal(len(mock_mail.call_args_list), 1)
empty, kwargs = mock_mail.call_args
kwargs['user'].reload()
assert_equal(empty, ())
assert_equal(kwargs, {
'user': user,
'mimetype': 'plain',
'mail': mails.PASSWORD_RESET,
'to_addr': user.username,
})
示例12: test_users_list_filter_multiple_field
# 需要导入模块: from osf_tests.factories import UserFactory [as 别名]
# 或者: from osf_tests.factories.UserFactory import save [as 别名]
def test_users_list_filter_multiple_field(self, app, user_one, user_two):
john_doe = UserFactory(fullname='John Doe')
john_doe.given_name = 'John'
john_doe.family_name = 'Doe'
john_doe.save()
doe_jane = UserFactory(fullname='Doe Jane')
doe_jane.given_name = 'Doe'
doe_jane.family_name = 'Jane'
doe_jane.save()
url = '/{}users/?filter[given_name,family_name]=Doe'.format(API_BASE)
res = app.get(url)
data = res.json['data']
assert len(data) == 2
示例13: TestCore
# 需要导入模块: from osf_tests.factories import UserFactory [as 别名]
# 或者: from osf_tests.factories.UserFactory import save [as 别名]
class TestCore(unittest.TestCase):
def setUp(self):
super(TestCore, self).setUp()
self.user = UserFactory()
self.user.add_addon('box')
self.user.save()
self.settings = self.user.get_addon('box')
self.settings.save()
def test_get_addon_returns_box_user_settings(self):
result = self.user.get_addon('box')
assert_true(isinstance(result, UserSettings))
示例14: test_password_change_sends_email
# 需要导入模块: from osf_tests.factories import UserFactory [as 别名]
# 或者: from osf_tests.factories.UserFactory import save [as 别名]
def test_password_change_sends_email(self, mock_mail):
user = UserFactory()
user.set_password('killerqueen')
user.save()
assert_equal(len(mock_mail.call_args_list), 1)
empty, kwargs = mock_mail.call_args
kwargs['user'].reload()
assert_equal(empty, ())
assert_equal(kwargs, {
'user': user,
'mimetype': 'html',
'mail': mails.PASSWORD_RESET,
'to_addr': user.username,
'can_change_preferences': False,
'osf_contact_email': settings.OSF_CONTACT_EMAIL,
})
示例15: TestNodeChanges
# 需要导入模块: from osf_tests.factories import UserFactory [as 别名]
# 或者: from osf_tests.factories.UserFactory import save [as 别名]
class TestNodeChanges(AdminTestCase):
def setUp(self):
super(TestNodeChanges, self).setUp()
self.registration = RegistrationFactory(is_public=True)
self.user = UserFactory()
self.user.is_staff = True
self.user.groups.add(Group.objects.get(name='osf_admin'))
self.user.save()
self.date_valid = self.registration.registered_date + datetime.timedelta(days=365)
self.date_valid2 = self.registration.registered_date + datetime.timedelta(days=375)
self.date_too_late = self.registration.registered_date + datetime.timedelta(days=1825)
self.date_too_soon = self.registration.registered_date + datetime.timedelta(days=-1)
def test_change_embargo_date(self):
assert_false(self.registration.embargo)
assert_true(self.registration.is_public)
# Note: Date comparisons accept a difference up to a day because embargoes start at midnight
# Create an embargo from a registration with none
change_embargo_date(self.registration, self.user, self.date_valid)
assert_almost_equal(self.registration.embargo.end_date, self.date_valid, delta=datetime.timedelta(days=1))
# Make sure once embargo is set, registration is made private
self.registration.reload()
assert_false(self.registration.is_public)
# Update an embargo end date
change_embargo_date(self.registration, self.user, self.date_valid2)
assert_almost_equal(self.registration.embargo.end_date, self.date_valid2, delta=datetime.timedelta(days=1))
# Test invalid dates
with assert_raises(ValidationError):
change_embargo_date(self.registration, self.user, self.date_too_late)
with assert_raises(ValidationError):
change_embargo_date(self.registration, self.user, self.date_too_soon)
# Test that checks user has permission
with assert_raises( PermissionDenied):
change_embargo_date(self.registration, UserFactory(), self.date_valid)
assert_almost_equal(self.registration.embargo.end_date, self.date_valid2, delta=datetime.timedelta(days=1))