本文整理汇总了Python中mozillians.users.tests.UserFactory类的典型用法代码示例。如果您正苦于以下问题:Python UserFactory类的具体用法?Python UserFactory怎么用?Python UserFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了UserFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: invalidate_group_pending_terms
def invalidate_group_pending_terms(self, mail_task):
"""Invalidate a group where a user has not yet accepted the terms.
Type is indifferent for this test.
"""
member = UserFactory.create(vouched=True)
curator = UserFactory.create(vouched=True)
group = GroupFactory.create(name='Foo', invalidation_days=5)
group.curators.add(curator.userprofile)
group.add_member(curator.userprofile)
GroupMembership.objects.create(userprofile=member.userprofile, group=group,
status=GroupMembership.PENDING_TERMS,
updated_on=datetime.now() - timedelta(days=10))
curator_membership = group.groupmembership_set.filter(userprofile=curator.userprofile)
curator_membership.update(updated_on=datetime.now() - timedelta(days=10))
eq_(curator_membership[0].status, GroupMembership.MEMBER)
invalidate_group_membership()
ok_(group.groupmembership_set.filter(userprofile=member.userprofile,
status=GroupMembership.PENDING_TERMS).exists())
ok_(group.groupmembership_set.filter(userprofile=curator.userprofile).exists())
ok_(not mail_task.called)
示例2: test_send_renewal_notification_inviters_email
def test_send_renewal_notification_inviters_email(self, mock_now, mock_send_mail):
"""Test renewal notification functionality for curators"""
curator1 = UserFactory.create(email='[email protected]')
curator2 = UserFactory.create(email='[email protected]')
curator3 = UserFactory.create(email='[email protected]')
member = UserFactory.create(userprofile={'full_name': 'Example Name'})
group = GroupFactory.create(name='foobar', invalidation_days=365,
accepting_new_members=Group.CLOSED)
group.curators.add(curator1.userprofile)
group.curators.add(curator2.userprofile)
group.curators.add(curator3.userprofile)
group.add_member(member.userprofile)
InviteFactory.create(inviter=curator3.userprofile, redeemer=member.userprofile,
group=group)
datetime_now = now() + timedelta(days=351)
mock_now.return_value = datetime_now
notify_membership_renewal()
ok_(mock_send_mail.called)
eq_(2, len(mock_send_mail.mock_calls))
# Check email for inviter
name, args, kwargs = mock_send_mail.mock_calls[1]
subject, body, from_addr, to_list = args
eq_(subject, '[Mozillians][foobar] Membership of "Example Name" is about to expire')
eq_(from_addr, settings.FROM_NOREPLY)
eq_(list(to_list), [u'[email protected]'])
示例3: invalidate_closed_group
def invalidate_closed_group(self, mail_task):
member = UserFactory.create(vouched=True)
curator = UserFactory.create(vouched=True)
group = GroupFactory.create(name='Foo', invalidation_days=5,
accepting_new_members=Group.CLOSED)
group.curators.add(curator.userprofile)
group.add_member(curator.userprofile)
group.add_member(member.userprofile)
membership = group.groupmembership_set.filter(userprofile=member.userprofile)
curator_membership = group.groupmembership_set.filter(userprofile=curator.userprofile)
membership.update(updated_on=datetime.now() - timedelta(days=10))
curator_membership.update(updated_on=datetime.now() - timedelta(days=10))
eq_(membership[0].status, GroupMembership.MEMBER)
eq_(curator_membership[0].status, GroupMembership.MEMBER)
invalidate_group_membership()
ok_(group.groupmembership_set.filter(userprofile=member.userprofile,
status=GroupMembership.PENDING).exists())
ok_(group.groupmembership_set.filter(userprofile=curator.userprofile).exists())
mail_task.delay.assert_called_once_with(group.id, member.id, GroupMembership.MEMBER,
GroupMembership.PENDING)
示例4: test_list_mozillians_in_location_region_n_city_vouched
def test_list_mozillians_in_location_region_n_city_vouched(self):
user_listed = UserFactory.create(userprofile={'is_vouched': True,
'country': 'it',
'region': 'Florence',
'city': 'madova'})
UserFactory.create(userprofile={'is_vouched': True,
'country': 'it',
'region': 'florence',
'city': 'foo'})
UserFactory.create(userprofile={'is_vouched': True})
UserFactory.create()
UserFactory.create(userprofile={'country': 'gr'})
user = UserFactory.create(userprofile={'is_vouched': True})
with self.login(user) as client:
url = reverse('phonebook:list_region_city', kwargs={'country': 'it',
'region': 'florence',
'city': 'Madova'})
response = client.get(url, follow=True)
eq_(response.status_code, 200)
self.assertTemplateUsed(response, 'phonebook/location-list.html')
eq_(response.context['country_name'], 'Italy')
eq_(response.context['city_name'], 'Madova')
eq_(response.context['region_name'], 'florence')
eq_(response.context['people'].count(), 1)
eq_(response.context['people'][0], user_listed.userprofile)
示例5: test_voucher_set_null_on_user_delete
def test_voucher_set_null_on_user_delete(self):
voucher = UserFactory.create()
vouchee = UserFactory.create(vouched=False)
vouchee.userprofile.vouch(voucher.userprofile)
voucher.delete()
vouch = Vouch.objects.get(vouchee=vouchee)
eq_(vouch.voucher, None)
示例6: test_email_now_vouched_with_voucher
def test_email_now_vouched_with_voucher(self, send_mail_mock):
voucher = UserFactory.create()
user = UserFactory.create(vouched=False)
user.userprofile._email_now_vouched(voucher.userprofile)
ok_(send_mail_mock.called)
eq_(send_mail_mock.call_args[0][3], [user.email])
ok_(voucher.userprofile.full_name in send_mail_mock.call_args[0][1])
示例7: test_voucher_nonpublic
def test_voucher_nonpublic(self):
voucher = UserFactory.create()
user = UserFactory.create(userprofile={"is_vouched": True, "vouched_by": voucher.userprofile})
user_profile = user.userprofile
user_profile.set_instance_privacy_level(PUBLIC)
eq_(user_profile.vouched_by, None)
示例8: setUp
def setUp(self):
voucher = UserFactory.create(userprofile={'is_vouched': True})
self.user = UserFactory.create(
userprofile={'is_vouched': True,
'vouched_by': voucher.userprofile})
group = GroupFactory.create()
self.user.userprofile.groups.add(group)
skill = SkillFactory.create()
self.user.userprofile.skills.add(skill)
language = LanguageFactory.create()
self.user.userprofile.languages.add(language)
self.resource_url = reverse(
'api_dispatch_list',
kwargs={'api_name': 'v1', 'resource_name': 'users'})
self.mozilla_app = APIAppFactory.create(
owner=self.user, is_mozilla_app=True)
self.mozilla_resource_url = urlparams(
self.resource_url, app_name=self.mozilla_app.name,
app_key=self.mozilla_app.key)
self.community_app = APIAppFactory.create(
owner=self.user, is_mozilla_app=False)
self.community_resource_url = urlparams(
self.resource_url, app_name=self.community_app.name,
app_key=self.community_app.key)
示例9: test_vouched
def test_vouched(self):
vouched_user = UserFactory.create()
UserFactory.create(vouched=False)
UserFactory.create(userprofile={'full_name': ''})
queryset = UserProfile.objects.vouched()
eq_(queryset.count(), 1)
eq_(queryset[0], vouched_user.userprofile)
示例10: test_invalidate_open_group
def test_invalidate_open_group(self, mail_task):
member = UserFactory.create(vouched=True)
curator = UserFactory.create(vouched=True)
# Group of type Group.OPEN
group = GroupFactory.create(name='Foo', terms='Example terms.', invalidation_days=5,
accepting_new_members=Group.OPEN)
group.curators.add(curator.userprofile)
group.add_member(member.userprofile)
group.add_member(curator.userprofile)
membership = group.groupmembership_set.filter(userprofile=member.userprofile)
curator_membership = group.groupmembership_set.filter(userprofile=curator.userprofile)
membership.update(updated_on=datetime.now() - timedelta(days=10))
curator_membership.update(updated_on=datetime.now() - timedelta(days=10))
eq_(membership[0].status, GroupMembership.MEMBER)
eq_(curator_membership[0].status, GroupMembership.MEMBER)
invalidate_group_membership()
ok_(not group.groupmembership_set.filter(userprofile=member.userprofile).exists())
ok_(group.groupmembership_set.filter(userprofile=curator.userprofile).exists())
mail_task.delay.assert_called_once_with(group.id, member.id, GroupMembership.MEMBER, None)
示例11: setUp
def setUp(self):
voucher = UserFactory.create()
self.user = UserFactory.create(
userprofile={'is_vouched': True,
'vouched_by': voucher.userprofile})
group = GroupFactory.create()
group.add_member(self.user.userprofile)
skill = SkillFactory.create()
self.user.userprofile.skills.add(skill)
self.user.userprofile.externalaccount_set.create(type=ExternalAccount.TYPE_SUMO,
identifier='Apitest')
self.resource_url = reverse(
'api_dispatch_list',
kwargs={'api_name': 'v1', 'resource_name': 'users'})
self.mozilla_app = APIAppFactory.create(
owner=self.user, is_mozilla_app=True)
self.mozilla_resource_url = urlparams(
self.resource_url, app_name=self.mozilla_app.name,
app_key=self.mozilla_app.key)
self.community_app = APIAppFactory.create(
owner=self.user, is_mozilla_app=False)
self.community_resource_url = urlparams(
self.resource_url, app_name=self.community_app.name,
app_key=self.community_app.key)
示例12: test_list_mozillians_in_location_region_vouched
def test_list_mozillians_in_location_region_vouched(self):
country = CountryFactory.create()
country2 = CountryFactory.create()
region = RegionFactory.create(country=country)
region2 = RegionFactory.create(country=country)
user_listed = UserFactory.create(
userprofile={'geo_country': country,
'geo_region': region})
UserFactory.create(
userprofile={'geo_country': country,
'geo_region': region2})
UserFactory.create()
UserFactory.create(vouched=False)
UserFactory.create(vouched=False, userprofile={'geo_country': country2})
user = UserFactory.create()
with self.login(user) as client:
url = reverse(
'phonebook:list_region',
kwargs={'country': country.name, 'region': region.name})
response = client.get(url, follow=True)
eq_(response.status_code, 200)
self.assertTemplateUsed(response, 'phonebook/location_list.html')
eq_(response.context['country_name'], country.name)
eq_(response.context['city_name'], None)
eq_(response.context['region_name'], region.name)
eq_(response.context['people'].paginator.count, 1)
eq_(response.context['people'].object_list[0], user_listed.userprofile)
示例13: test_sending_pending_email_already_sent
def test_sending_pending_email_already_sent(self):
# If a curated group has a pending membership, but it was added before the
# last time a reminder email was sent, do not send the curator an email.
# curated group:
group = GroupFactory.create()
group.curators.add(UserFactory.create().userprofile)
# Pending membership
user1 = UserFactory.create()
group.add_member(user1.userprofile, GroupMembership.PENDING)
membership = GroupMembership.objects.get(userprofile=user1.userprofile, group=group)
membership.save()
# Send email. This should update the field remembering the max pending request pk.
tasks.send_pending_membership_emails()
# Non-pending membership
user2 = UserFactory.create()
group.add_member(user2.userprofile, GroupMembership.MEMBER)
# None of this should trigger an email send
with patch('mozillians.groups.tasks.send_mail', autospec=True) as mock_send_mail:
tasks.send_pending_membership_emails()
ok_(not mock_send_mail.called)
示例14: test_email_in_identity_belongs_to_other_user
def test_email_in_identity_belongs_to_other_user(self, jws_mock, request_post_mock,
msg_mock):
"""Test adding a stronger identity and changing the primary email."""
UserFactory.create(email='[email protected]')
user1 = UserFactory.create(email='[email protected]')
(jws_mock.from_compact.return_value).payload = json.dumps({
'email': '[email protected]',
'email_verified': True,
'sub': 'ad|ldap'
})
post_json_mock = Mock()
post_json_mock.json.return_value = {
'id_token': 'id_token'
}
with self.login(user1) as client:
session = client.session
session['oidc_verify_nonce'] = 'nonce'
session['oidc_verify_state'] = 'state'
session.save()
response = client.get(self.url, self.get_data, follow=True)
msg = 'The email in this identity is used by another user.'
msg_mock.error.assert_called_once_with(ANY, msg)
with override_script_prefix('/en-US/'):
url = reverse('phonebook:profile_edit')
self.assertRedirects(response, url)
示例15: test_invalidate_group_accepts_all
def test_invalidate_group_accepts_all(self, mock_send_mail):
member = UserFactory.create(vouched=True)
curator = UserFactory.create(vouched=True)
group = GroupFactory.create(name='Foo', invalidation_days=5)
group.curators.add(curator.userprofile)
group.add_member(curator.userprofile)
group.add_member(member.userprofile)
membership = group.groupmembership_set.filter(userprofile=member.userprofile)
curator_membership = group.groupmembership_set.filter(userprofile=curator.userprofile)
membership.update(updated_on=datetime.now() - timedelta(days=10))
curator_membership.update(updated_on=datetime.now() - timedelta(days=10))
eq_(membership[0].status, GroupMembership.MEMBER)
eq_(curator_membership[0].status, GroupMembership.MEMBER)
invalidate_group_membership()
ok_(not group.groupmembership_set.filter(userprofile=member.userprofile).exists())
ok_(group.groupmembership_set.filter(userprofile=curator.userprofile).exists())
subject = 'Removed from Mozillians group "foo"'
mock_send_mail.assert_called_once_with(subject, ANY, '[email protected]',
[member.email], fail_silently=False)