本文整理汇总了Python中remo.profiles.tests.UserFactory类的典型用法代码示例。如果您正苦于以下问题:Python UserFactory类的具体用法?Python UserFactory怎么用?Python UserFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了UserFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_update_valid_groups
def test_update_valid_groups(self):
model = ContentType.objects.get_for_model(Poll)
items = ActionItem.objects.filter(content_type=model)
ok_(not items.exists())
council = Group.objects.get(name='Council')
reps = Group.objects.get(name='Rep')
UserFactory.create_batch(3, groups=['Council'])
UserFactory.create_batch(4, groups=['Rep'])
start = now() - timedelta(hours=3)
poll = PollFactory.create(valid_groups=council, start=start)
create_poll_action_items()
poll.valid_groups = reps
poll.save()
items = ActionItem.objects.filter(content_type=model,
object_id=poll.id)
eq_(items.count(), 4)
for user in reps.user_set.all():
ok_(items.filter(user=user).exists())
for user in council.user_set.all():
ok_(not items.filter(user=user).exists())
示例2: test_send_mail
def test_send_mail(self, fake_messages):
"""Test EmailRepsForm email sending functionality."""
data = {'subject': 'Test email subject',
'body': 'Test email body',
'functional_area': self.functional_area.id}
form = EmailRepsForm(data=data)
ok_(form.is_valid())
area = self.functional_area
UserFactory.create_batch(20, userprofile__functional_areas=[area])
factory = RequestFactory()
request = factory.request()
request.user = UserFactory.create()
reps = User.objects.filter(userprofile__functional_areas__name=area)
form.send_email(request, reps)
eq_(len(mail.outbox), 20)
def format_name(user):
return '%s %s <%s>' % (user.first_name, user.last_name, user.email)
recipients = map(format_name, reps)
receivers = []
for i in range(0, len(mail.outbox)):
eq_(mail.outbox[i].subject, data['subject'])
eq_(mail.outbox[i].body, data['body'])
receivers.append(mail.outbox[i].to[0])
eq_(set(receivers), set(recipients))
fake_messages.assert_called_with(ANY, 'Email sent successfully.')
示例3: test_send_mail
def test_send_mail(self, fake_messages):
"""Test EmailRepsForm email sending functionality."""
data = {"subject": "Test email subject", "body": "Test email body", "functional_area": self.functional_area.id}
form = EmailRepsForm(data=data)
ok_(form.is_valid())
area = self.functional_area
UserFactory.create_batch(20, userprofile__functional_areas=[area])
factory = RequestFactory()
request = factory.request()
request.user = UserFactory.create()
reps = User.objects.filter(userprofile__functional_areas__name=area)
form.send_email(request, reps)
eq_(len(mail.outbox), 20)
address = lambda u: "%s %s <%s>" % (u.first_name, u.last_name, u.email)
recipients = map(address, reps)
receivers = []
for i in range(0, len(mail.outbox)):
eq_(mail.outbox[i].subject, data["subject"])
eq_(mail.outbox[i].body, data["body"])
receivers.append(mail.outbox[i].to[0])
eq_(set(receivers), set(recipients))
fake_messages.assert_called_with(ANY, "Email sent successfully.")
示例4: test_view_dashboard_page
def test_view_dashboard_page(self):
"""Get dashboard page."""
c = Client()
# Get as anonymous user.
response = c.get(reverse('dashboard'), follow=True)
eq_(response.status_code, 200)
self.assertJinja2TemplateUsed(response, 'main.jinja')
# Get as logged in rep.
rep = UserFactory.create(groups=['Rep'])
with self.login(rep) as client:
response = client.get(reverse('dashboard'))
eq_(response.status_code, 200)
self.assertJinja2TemplateUsed(response, 'dashboard_reps.jinja')
# Get as logged in mentor.
mentor = UserFactory.create(groups=['Mentor'])
with self.login(mentor) as client:
response = client.get(reverse('dashboard'))
eq_(response.status_code, 200)
self.assertJinja2TemplateUsed(response, 'dashboard_reps.jinja')
# Get as logged in counselor.
councelor = UserFactory.create(groups=['Council'])
with self.login(councelor) as client:
response = client.get(reverse('dashboard'))
eq_(response.status_code, 200)
self.assertJinja2TemplateUsed(response, 'dashboard_reps.jinja')
示例5: test_dry_run
def test_dry_run(self):
"""Test sending of first notification with debug activated."""
mentor = UserFactory.create(groups=['Mentor'])
rep = UserFactory.create(groups=['Rep'], userprofile__mentor=mentor)
ReportFactoryWithoutSignals.create(user=rep)
management.call_command('send_first_report_notification', dry_run=True)
eq_(len(mail.outbox), 0)
示例6: test_resolve_mentor_validation
def test_resolve_mentor_validation(self):
model = ContentType.objects.get_for_model(Bug)
items = ActionItem.objects.filter(content_type=model)
ok_(not items.exists())
mentor = UserFactory.create(groups=['Rep', 'Mentor'])
UserFactory.create(groups=['Rep'], userprofile__mentor=mentor)
bug = BugFactory.build(pending_mentor_validation=True,
assigned_to=mentor)
bug.save()
items = ActionItem.objects.filter(content_type=model)
eq_(items.count(), 1)
eq_(items[0].name, 'Waiting mentor validation for ' + bug.summary)
eq_(items[0].user, mentor)
eq_(items[0].priority, ActionItem.BLOCKER)
bug.pending_mentor_validation = False
bug.save()
items = ActionItem.objects.filter(content_type=model, object_id=bug.id)
for item in items:
ok_(item.completed)
ok_(item.resolved)
示例7: test_get_nominee_right_split
def test_get_nominee_right_split(self):
UserFactory.create(first_name='Foo', last_name='Foo Bar',
groups=['Rep'])
user = get_nominee('Foo Foo Bar')
ok_(user)
eq_(user.first_name, 'Foo')
eq_(user.last_name, 'Foo Bar')
示例8: test_comment_multiple_users
def test_comment_multiple_users(self):
"""Test sending email when a new comment is added on a NGReport
and the users have the option enabled in their settings.
"""
commenter = UserFactory.create()
reporter = UserFactory.create(
userprofile__receive_email_on_add_comment=True)
report = NGReportFactory.create(user=reporter)
users_with_comments = UserFactory.create_batch(
2, userprofile__receive_email_on_add_comment=True)
# disconnect the signals in order to add two users in NGReportComment
for user_obj in users_with_comments:
NGReportCommentFactoryNoSignals.create(
user=user_obj, report=report, comment='This is a comment')
NGReportCommentFactory.create(user=commenter, report=report,
comment='This is a comment')
eq_(len(mail.outbox), 3)
recipients = ['%s <%s>' % (reporter.get_full_name(), reporter.email),
'%s <%s>' % (users_with_comments[0].get_full_name(),
users_with_comments[0].email),
'%s <%s>' % (users_with_comments[1].get_full_name(),
users_with_comments[1].email)]
receivers = [mail.outbox[0].to[0], mail.outbox[1].to[0],
mail.outbox[2].to[0]]
eq_(set(recipients), set(receivers))
msg = ('[Report] User {0} commented on {1}'
.format(commenter.get_full_name(), report))
eq_(mail.outbox[0].subject, msg)
示例9: test_comment_multiple_users
def test_comment_multiple_users(self):
"""Test sending email when a new comment is added on a Poll
and the users have the option enabled in their settings.
"""
commenter = UserFactory.create()
creator = UserFactory.create(
userprofile__receive_email_on_add_voting_comment=True)
poll = PollFactoryNoSignals.create(created_by=creator)
users_with_comments = UserFactory.create_batch(
2, userprofile__receive_email_on_add_voting_comment=True)
# disconnect the signals in order to add two users in PollComment
for user_obj in users_with_comments:
PollCommentFactoryNoSignals.create(
user=user_obj, poll=poll, comment='This is a comment')
PollCommentFactory.create(user=commenter, poll=poll,
comment='This is a comment')
eq_(len(mail.outbox), 3)
recipients = ['%s <%s>' % (creator.get_full_name(), creator.email),
'%s <%s>' % (users_with_comments[0].get_full_name(),
users_with_comments[0].email),
'%s <%s>' % (users_with_comments[1].get_full_name(),
users_with_comments[1].email)]
receivers = [mail.outbox[0].to[0], mail.outbox[1].to[0],
mail.outbox[2].to[0]]
eq_(set(recipients), set(receivers))
msg = ('[Voting] User {0} commented on {1}'
.format(commenter.get_full_name(), poll))
eq_(mail.outbox[0].subject, msg)
示例10: test_send_notification
def test_send_notification(self):
"""Test sending of first notification to Reps to fill reports."""
mentor = UserFactory.create(groups=['Mentor'])
rep = UserFactory.create(groups=['Rep'], userprofile__mentor=mentor)
ReportFactoryWithoutSignals.create(user=rep)
management.call_command('send_first_report_notification', [], {})
eq_(len(mail.outbox), 1)
示例11: test_base
def test_base(self):
mentor = UserFactory.create()
rep = UserFactory.create(userprofile__mentor=mentor)
UserStatusFactory.create(user=rep, start_date=get_date(days=-1), is_unavailable=False)
set_unavailability_flag()
status = UserStatus.objects.get(user=rep)
ok_(status.is_unavailable)
示例12: test_list_no_alumni
def test_list_no_alumni(self):
"""Test page header context for rep."""
UserFactory.create(groups=['Rep'])
response = self.get(reverse('profiles_alumni'))
self.assertTemplateUsed(response, 'profiles_list_alumni.html')
eq_(response.status_code, 200)
ok_(not response.context['objects'].object_list)
示例13: test_base
def test_base(self):
mentor = UserFactory.create()
user = UserFactory.create(userprofile__mentor=mentor)
event = EventFactory.create()
functional_areas = [FunctionalAreaFactory.create()]
campaign = CampaignFactory.create()
activity = ActivityFactory.create()
report = NGReportFactory.create(
functional_areas=functional_areas, mentor=mentor,
campaign=campaign, user=user, event=event, activity=activity)
url = '/api/beta/activities/%s' % report.id
request = RequestFactory().get(url)
data = ActivitiesDetailedSerializer(report,
context={'request': request}).data
eq_(data['user']['first_name'], user.first_name)
eq_(data['user']['last_name'], user.last_name)
eq_(data['user']['display_name'], user.userprofile.display_name)
ok_(data['user']['_url'])
eq_(data['activity'], activity.name)
eq_(data['initiative'], campaign.name)
eq_(data['functional_areas'][0]['name'], functional_areas[0].name)
eq_(data['activity_description'], report.activity_description)
eq_(data['location'], report.location)
eq_(data['latitude'], float(report.latitude))
eq_(data['longitude'], float(report.longitude))
eq_(data['report_date'], report.report_date.strftime('%Y-%m-%d'))
eq_(data['link'], report.link)
eq_(data['link_description'], report.link_description)
eq_(data['mentor']['first_name'], mentor.first_name)
eq_(data['mentor']['last_name'], mentor.last_name)
eq_(data['mentor']['display_name'], mentor.userprofile.display_name)
ok_(data['mentor']['_url'])
eq_(data['passive_report'], report.is_passive)
eq_(data['event']['name'], event.name)
ok_(data['event']['_url'])
示例14: test_extend_voting_period_majority
def test_extend_voting_period_majority(self):
bug = BugFactory.create()
start = now().replace(microsecond=0)
end = datetime.combine(get_date(days=1), datetime.min.time())
user = UserFactory.create(groups=['Admin'])
group = Group.objects.get(name='Council')
User.objects.filter(groups__name='Council').delete()
UserFactory.create_batch(9, groups=['Council'])
automated_poll = PollFactoryNoSignals.create(name='poll',
start=start, end=end,
valid_groups=group,
created_by=user,
automated_poll=True,
bug=bug)
radio_poll = RadioPollFactory.create(poll=automated_poll,
question='Budget Approval')
RadioPollChoiceFactory.create(answer='Approved', votes=5,
radio_poll=radio_poll)
RadioPollChoiceFactory.create(answer='Denied', votes=3,
radio_poll=radio_poll)
extend_voting_period()
poll = Poll.objects.get(pk=automated_poll.id)
eq_(poll.end.year, end.year)
eq_(poll.end.month, end.month)
eq_(poll.end.day, end.day)
eq_(poll.end.hour, 0)
eq_(poll.end.minute, 0)
eq_(poll.end.second, 0)
ok_(not poll.is_extended)
示例15: test_send_mail
def test_send_mail(self, fake_messages):
"""Test EmailRepsForm email sending functionality."""
data = {'subject': 'Test email subject',
'body': 'Test email body',
'functional_area': self.functional_area.id}
form = EmailRepsForm(data=data)
ok_(form.is_valid())
area = self.functional_area
UserFactory.create_batch(20, userprofile__functional_areas=[area])
factory = RequestFactory()
request = factory.request()
request.user = UserFactory.create()
reps = User.objects.filter(userprofile__functional_areas__name=area)
form.send_email(request, reps)
eq_(len(mail.outbox), 1)
address = lambda u: '%s %s <%s>' % (u.first_name, u.last_name, u.email)
recipients = map(address, reps)
eq_(set(mail.outbox[0].to), set(recipients))
eq_(mail.outbox[0].subject, data['subject'])
eq_(mail.outbox[0].body, data['body'])
fake_messages.assert_called_with(ANY, 'Email sent successfully.')