本文整理汇总了Python中osf_tests.factories.UserFactory类的典型用法代码示例。如果您正苦于以下问题:Python UserFactory类的具体用法?Python UserFactory怎么用?Python UserFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了UserFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_increment_user_activity_counters
def test_increment_user_activity_counters(self):
user = UserFactory()
date = timezone.now()
assert_equal(user.get_activity_points(db=None), 0)
analytics.increment_user_activity_counters(user._id, 'project_created', date.isoformat(), db=None)
assert_equal(user.get_activity_points(db=None), 1)
示例2: TestDisableUser
class TestDisableUser(AdminTestCase):
def setUp(self):
self.user = UserFactory()
self.request = RequestFactory().post('/fake_path')
self.view = views.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, 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_disable_user(self):
settings.ENABLE_EMAIL_SUBSCRIPTIONS = False
count = AdminLogEntry.objects.count()
self.view().delete(self.request)
self.user.reload()
nt.assert_true(self.user.is_disabled)
nt.assert_equal(AdminLogEntry.objects.count(), count + 1)
def test_reactivate_user(self):
settings.ENABLE_EMAIL_SUBSCRIPTIONS = False
self.view().delete(self.request)
count = AdminLogEntry.objects.count()
self.view().delete(self.request)
self.user.reload()
nt.assert_false(self.user.is_disabled)
nt.assert_equal(AdminLogEntry.objects.count(), count + 1)
def test_no_user(self):
view = setup_view(views.UserDeleteView(), self.request, guid='meh')
with nt.assert_raises(Http404):
view.delete(self.request)
def test_no_user_permissions_raises_error(self):
user = UserFactory()
guid = user._id
request = RequestFactory().get(reverse('users:disable', kwargs={'guid': guid}))
request.user = user
with self.assertRaises(PermissionDenied):
self.view.as_view()(request, guid=guid)
def test_correct_view_permissions(self):
user = UserFactory()
guid = user._id
change_permission = Permission.objects.get(codename='change_osfuser')
user.user_permissions.add(change_permission)
user.save()
request = RequestFactory().get(reverse('users:disable', kwargs={'guid': guid}))
request.user = user
response = self.view.as_view()(request, guid=guid)
self.assertEqual(response.status_code, 200)
示例3: 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)
示例4: test_csrf_cookie_gets_set_on_authd_request
def test_csrf_cookie_gets_set_on_authd_request(self):
user = UserFactory()
# use session auth
session_cookie = user.get_or_create_cookie()
self.app.set_cookie(settings.COOKIE_NAME, str(session_cookie))
res = self.app.get('/settings/')
assert res.status_code == 200
assert api_settings.CSRF_COOKIE_NAME in self.app.cookies
示例5: test_revoke_remote_access_not_called
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)
示例6: test_serialize_user_merged
def test_serialize_user_merged(self):
master = UserFactory()
user = UserFactory()
master.merge_user(user)
d = utils.serialize_user(user, full=True)
assert_true(d['is_merged'])
assert_equal(d['merged_by']['url'], user.merged_by.url)
assert_equal(d['merged_by']['absolute_url'], user.merged_by.absolute_url)
示例7: TestGithubNodeSettings
class TestGithubNodeSettings(unittest.TestCase):
def setUp(self):
super(TestGithubNodeSettings, self).setUp()
self.user = UserFactory()
self.user.add_addon('github')
self.user_settings = self.user.get_addon('github')
self.external_account = factories.GitHubAccountFactory()
self.user_settings.owner.external_accounts.add(self.external_account)
self.user_settings.owner.save()
self.node_settings = factories.GitHubNodeSettingsFactory(user_settings=self.user_settings)
@mock.patch('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('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('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('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)
示例8: 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()
示例9: test_serialize_account_status
def test_serialize_account_status(self):
user = UserFactory()
info = serialize_user(user)
nt.assert_equal(info['disabled'], False)
user.is_disabled = True
info = serialize_user(user)
nt.assert_almost_equal(
int(info['disabled'].strftime('%s')),
int(timezone.now().strftime('%s')),
delta=50)
nt.assert_is_instance(info['disabled'], datetime)
示例10: test_subscribe_fake_email_does_not_throw_validation_error
def test_subscribe_fake_email_does_not_throw_validation_error(self, mock_get_mailchimp_api):
list_name = 'foo'
user = UserFactory(username='[email protected]')
mock_client = mock.MagicMock()
mock_get_mailchimp_api.return_value = mock_client
mock_client.lists.list.return_value = {'data': [{'id': 1, 'list_name': list_name}]}
mock_client.lists.subscribe.side_effect = mailchimp.ValidationError
mailchimp_utils.subscribe_mailchimp(list_name, user._id)
handlers.celery_teardown_request()
user.reload()
assert_false(user.mailchimp_mailing_lists[list_name])
示例11: setUp
def setUp(self):
super(TestInstitutionUsersList, self).setUp()
self.institution = InstitutionFactory()
self.user1 = UserFactory()
self.user1.affiliated_institutions.add(self.institution)
self.user1.save()
self.user2 = UserFactory()
self.user2.affiliated_institutions.add(self.institution)
self.user2.save()
self.institution_user_url = '/{0}institutions/{1}/users/'.format(API_BASE, self.institution._id)
示例12: test_get_total_activity_count
def test_get_total_activity_count(self):
user = UserFactory()
date = timezone.now()
assert_equal(analytics.get_total_activity_count(user._id), 0)
assert_equal(analytics.get_total_activity_count(user._id), user.get_activity_points())
analytics.increment_user_activity_counters(user._id, 'project_created', date.isoformat())
assert_equal(analytics.get_total_activity_count(user._id), 1)
assert_equal(analytics.get_total_activity_count(user._id), user.get_activity_points())
示例13: create_fake_user
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
示例14: TestDisabledUser
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)
示例15: test_region_wb_url_from_creators_defaults
def test_region_wb_url_from_creators_defaults(self):
user = UserFactory()
region = factories.RegionFactory()
user_settings = user.get_addon('osfstorage')
user_settings.default_region = region
user_settings.save()
project = ProjectFactory(creator=user)
node_settings = project.get_addon('osfstorage')
assert node_settings.region_id == region.id