本文整理汇总了Python中accounts.factories.UserFactory类的典型用法代码示例。如果您正苦于以下问题:Python UserFactory类的具体用法?Python UserFactory怎么用?Python UserFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了UserFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_buy_a_bet
def test_buy_a_bet(self):
"""
Buy a bet
"""
event = EventFactory()
user = UserFactory(total_cash=event.current_buy_for_price)
old_price = event.current_buy_for_price
bet_user, bet_event, bet = Bet.objects.buy_a_bet(user, event.id, Bet.YES,
event.current_buy_for_price)
self.assertEqual(user, bet_user)
self.assertEqual(event, bet_event)
self.assertEqual(event.current_buy_for_price, bet.bought_avg_price)
self.assertEqual(1, bet.has)
self.assertEqual(1, bet.bought)
self.assertEqual(0, bet_user.total_cash)
self.assertEqual(old_price, bet_user.portfolio_value)
self.assertNotEqual(old_price, bet_event.current_buy_for_price)
self.assertEqual(1, bet_event.turnover)
with self.assertRaises(PriceMismatch):
Bet.objects.buy_a_bet(user, event.id, Bet.YES, old_price)
with self.assertRaises(InsufficientCash):
Bet.objects.buy_a_bet(user, event.id, Bet.YES, bet_event.current_buy_for_price)
user.total_cash = bet_event.current_buy_against_price
user.save()
# TODO should throw exception
Bet.objects.buy_a_bet(user, event.id, Bet.NO, bet_event.current_buy_against_price)
示例2: DocumentDetailTests
class DocumentDetailTests(TestCase):
"""Test action menu items"""
def setUp(self):
self.category = CategoryFactory()
self.user = UserFactory(
name='User',
password='pass',
is_superuser=True,
category=self.category)
self.client.login(username=self.user.email, password='pass')
self.doc = DocumentFactory(
category=self.category,
revision={
'leader': self.user,
}
)
self.url = reverse("document_detail", args=[
self.category.organisation.slug,
self.category.slug,
self.doc.document_key
])
def test_admin_can_delete_document(self):
res = self.client.get(self.url)
self.assertContains(res, delete_button)
def test_simple_user_cannot_delete_document(self):
self.user.is_superuser = False
self.user.save()
res = self.client.get(self.url)
self.assertNotContains(res, delete_button)
示例3: BatchAckOfTransmittalsTests
class BatchAckOfTransmittalsTests(TestCase):
def setUp(self):
self.trs = create_transmittal()
self.category = self.trs.document.category
self.user = UserFactory(
email='[email protected]',
password='pass',
is_superuser=True,
category=self.category)
self.client.login(email=self.user.email, password='pass')
self.url = reverse('transmittal_batch_ack_of_receipt', args=[
self.category.organisation.slug,
self.category.slug,
])
def test_internal_user_cannot_ack_transmittal(self):
res = self.client.post(self.url, {'document_ids': [self.trs.document_id]})
self.assertEqual(res.status_code, 403)
def test_acks_receipt(self):
self.user.is_external = True
self.user.save()
res = self.client.post(
self.url,
{'document_ids': [self.trs.document_id]},
follow=True)
self.assertEqual(res.status_code, 200)
self.trs.refresh_from_db()
self.assertIsNotNone(self.trs.ack_of_receipt_date)
self.assertEqual(self.trs.ack_of_receipt_author, self.user)
示例4: UserApiAclTests
class UserApiAclTests(APITestCase):
def setUp(self):
self.category = CategoryFactory()
self.user = UserFactory(name='user', password='pass', category=self.category)
self.dc_perms = Permission.objects.filter(codename__endswith='_document')
self.dc = UserFactory(name='dc', password='pass', category=self.category)
self.dc.user_permissions = self.dc_perms
self.dc.save()
self.url = reverse('user-list', args=[
self.category.organisation.slug,
self.category.category_template.slug,
])
def test_anonymous_access_forbidden(self):
"""Anonymous cannot access the user api."""
res = self.client.get(self.url)
self.assertEqual(res.status_code, 403)
def test_simple_user_access_forbidden(self):
"""Simple users don't have access to the user api."""
self.client.login(username=self.user.email, password='pass')
res = self.client.get(self.url)
self.assertEqual(res.status_code, 403)
def test_dc_can_access_user_api(self):
"""Document controllers can access the user api."""
self.client.login(username=self.dc.email, password='pass')
res = self.client.get(self.url)
self.assertEqual(res.status_code, 200)
def test_dc_can_only_access_users_from_his_category(self):
other_category = CategoryFactory()
user = UserFactory(name='dc2', password='pass', category=other_category)
user.user_permissions = self.dc_perms
user.save()
self.client.login(username=user.email, password='pass')
res = self.client.get(self.url)
self.assertEqual(res.status_code, 403)
def test_dc_cannot_see_users_from_other_categories(self):
other_category = CategoryFactory()
user1 = UserFactory(name='toto', password='pass', category=other_category)
user1.save()
user2 = UserFactory(name='tata', password='pass', category=self.category)
user2.save()
self.client.login(username=self.dc.email, password='pass')
res = self.client.get(self.url)
self.assertEqual(res.status_code, 200)
self.assertTrue('tata' in res.content)
self.assertTrue('toto' not in res.content)
示例5: test_dc_can_only_access_users_from_his_category
def test_dc_can_only_access_users_from_his_category(self):
other_category = CategoryFactory()
user = UserFactory(name='dc2', password='pass', category=other_category)
user.user_permissions = self.dc_perms
user.save()
self.client.login(username=user.email, password='pass')
res = self.client.get(self.url)
self.assertEqual(res.status_code, 403)
示例6: AdminTest
class AdminTest(FunctionalTest):
def setUp(self):
super().setUp()
# Create a superuser
self.password = '123'
self.admin_user = UserFactory(password=self.password)
self.admin_user.is_admin = True
self.admin_user.save()
# Create packages and doctypes for the new audit
PackageFactory(name='TestPackage')
DoctypeFactory(name='TestDoctype')
def test_can_create_new_audit_via_admin_site(self):
# Gertrude opens her web browser, and goes to the admin page
self.browser.get(self.server_url + '/admin/')
# She sees the familiar 'Django administration' heading
body = self.browser.find_element_by_tag_name('body')
self.assertIn('Django administration', body.text)
# She inserts her email and password
email_input = self.browser.find_element_by_id('id_username')
email_input.send_keys(self.admin_user.email)
password_input = self.browser.find_element_by_id('id_password')
password_input.send_keys(self.password + '\n')
# Aftwer beign logged in, she visits the audit creation page
audit_section = self.browser.find_element_by_css_selector('.model-audit')
audit_section.find_element_by_css_selector('.addlink').click()
# She inserts all the required information in order to create a new audit
self.browser.find_element_by_id('id_name').send_keys('A new test audit')
self.browser.find_element_by_id('id_description').send_keys('A text description for our new audit')
package_dropdown = Select(self.browser.find_element_by_id('id_package'))
package_dropdown.select_by_visible_text('TestPackage')
doctype_selection = Select(self.browser.find_element_by_id('id_required_doctypes'))
doctype_selection.select_by_visible_text('TestDoctype')
runner_dropdown = Select(self.browser.find_element_by_id('id_runner'))
runner_dropdown.select_by_visible_text('DummyAudit')
# She then saves her new audit by clicking on the Save button
self.browser.find_element_by_css_selector('.default').click()
# A list page is displayed, and she can see her newly created audit is in there
self.assertTrue(self.browser.find_element_by_link_text('A new test audit'))
# Finally, she visits to the home page to check if her new audit is displayed
self.browser.find_element_by_link_text('VIEW SITE').click()
page_text = self.browser.find_element_by_tag_name('body').text
self.assertIn('A new test audit', page_text)
示例7: PendingReviewsReminderTests
class PendingReviewsReminderTests(TestCase):
def setUp(self):
self.category = CategoryFactory()
self.user = UserFactory(
email='[email protected]',
password='pass',
is_superuser=True,
category=self.category
)
self.client.login(email=self.user.email, password='pass')
self.doc1 = DocumentFactory(
category=self.category,
revision={
'leader': self.user,
'received_date': datetime.date.today(),
}
)
self.doc2 = DocumentFactory(
category=self.category,
revision={
'leader': self.user,
'received_date': datetime.date.today(),
}
)
def test_empty_reminder_list(self):
call_command('send_review_reminders')
self.assertEqual(len(mail.outbox), 0)
def test_send_reminders(self):
self.doc1.get_latest_revision().start_review()
self.assertEqual(Review.objects.all().count(), 1)
call_command('send_review_reminders')
self.assertEqual(len(mail.outbox), 1)
def test_finished_reviews(self):
rev = self.doc1.get_latest_revision()
rev.start_review()
rev.end_review()
self.assertEqual(Review.objects.all().count(), 1)
call_command('send_review_reminders')
self.assertEqual(len(mail.outbox), 0)
def test_do_not_send_reminder(self):
"""Reminders are not send to users if their mail config says so."""
self.doc1.get_latest_revision().start_review()
self.assertEqual(Review.objects.all().count(), 1)
self.user.send_pending_reviews_mails = False
self.user.save()
call_command('send_review_reminders')
self.assertEqual(len(mail.outbox), 0)
示例8: test_can_get_images_uploaded_by_a_user
def test_can_get_images_uploaded_by_a_user(self):
"""
Tests that the manager can get images specifically uploaded by a user.
"""
user_1 = UserFactory.create()
user_2 = UserFactory.create()
image_1a = ImageFactory.create(uploaded_by=user_1)
image_1b = ImageFactory.create(uploaded_by=user_1)
image_2a = ImageFactory.create(uploaded_by=user_2)
self.assertEquals([image_1b, image_1a], list(Image.objects.filter_uploaded_by(user_1)))
self.assertEquals([image_2a], list(Image.objects.filter_uploaded_by(user_2)))
示例9: FileTransmittedDownloadTests
class FileTransmittedDownloadTests(TestCase):
def setUp(self):
self.trs = create_transmittal()
self.rev = self.trs.latest_revision
self.category = self.trs.document.category
self.user = UserFactory(
email='[email protected]',
password='pass',
is_superuser=True,
is_external=True,
category=self.category)
self.trs.recipient.users.add(self.user)
self.client.login(email=self.user.email, password='pass')
self.linked_rev = self.trs.get_revisions()[0]
self.url = reverse('file_transmitted_download', args=[
self.category.organisation.slug,
self.category.slug,
self.trs.document_number,
self.linked_rev.metadata.document_key,
self.linked_rev.revision,
])
pdf_doc = 'sample_doc_pdf.pdf'
sample_pdf = SimpleUploadedFile(pdf_doc, b'content')
self.linked_rev.file_transmitted = sample_pdf
self.linked_rev.save()
def test_url_is_accessible_to_externals(self):
u"""This download url is for contractors only."""
res = self.client.get(self.url)
self.assertEqual(res.status_code, 200)
self.user.is_external = False
self.user.save()
res = self.client.get(self.url)
self.assertEqual(res.status_code, 404)
def test_that_revision_is_linked_to_transmittal(self):
u"""The file must have been transmitted."""
self.linked_rev.transmittals.clear()
self.linked_rev.save()
res = self.client.get(self.url)
self.assertEqual(res.status_code, 404)
def test_that_contractor_is_in_recipients(self):
u"""The contractor must be allowed to access the transmittal."""
self.trs.recipient.users.clear()
self.trs.recipient.save()
res = self.client.get(self.url)
self.assertEqual(res.status_code, 404)
示例10: test_get_bet_social
def test_get_bet_social(self):
"""
Get bet social
"""
event = EventFactory()
users_yes = UserFactory.create_batch(10)
users_no = UserFactory.create_batch(10)
bets_yes = [BetFactory(user=u, event=event) for u in users_yes]
bets_no = [BetFactory(user=u, event=event, outcome=Bet.NO) for u in users_no]
self.maxDiff = None
social = event.get_bet_social()
self.assertEqual(10, social['yes_count'])
self.assertEqual(bets_yes[:6], list(social['yes_bets']))
self.assertEqual(10, social['no_count'])
self.assertEqual(bets_no[:6], list(social['no_bets']))
示例11: create_admin
def create_admin(self):
# Factory creates simple user, so ``is_staff`` is set later
self.admin = UserFactory(username="admin", password="asdasd")
self.admin.is_staff = True
self.admin.is_superuser = True
self.admin.save()
print("admin user have been created successfully")
示例12: setUp
def setUp(self):
self.moderator = ModeratorFactory()
self.standard_user = UserFactory(
first_name='Firsto',
last_name='Namo',
)
self.invited_pending = InvitedPendingFactory()
self.requested_pending = RequestedPendingFactory()
示例13: test_can_logout
def test_can_logout(self):
"""
Tests the logout view.
"""
user = UserFactory.create()
self.client.login(**{'username': user.username, 'password': 'password'})
response = self.client.get(reverse('accounts:logout'), follow=True)
self.assertRedirects(response, '{0}?next={1}'.format(reverse('accounts:login'), reverse('images:upload')))
self.assertFalse(response.context['user'].is_authenticated())
示例14: AclTests
class AclTests(TestCase):
def setUp(self):
category = CategoryFactory()
self.user = UserFactory(name='User', password='pass', category=category)
self.home_url = reverse('category_document_list', args=[
category.organisation.slug,
category.slug
])
self.create_url = reverse('document_create', args=[
category.organisation.slug,
category.slug
])
self.login_url = '/accounts/login/'
self.dc_perms = Permission.objects.filter(codename__endswith='_document')
def test_anonymous_access(self):
res = self.client.get(self.home_url)
self.assertRedirects(res, '%s?next=%s' % (self.login_url, self.home_url))
res = self.client.get(self.create_url)
self.assertRedirects(res, '%s?next=%s' % (self.login_url, self.create_url))
def test_authenticated_user_access(self):
self.client.login(username=self.user.email, password='pass')
res = self.client.get(self.home_url)
self.assertEqual(res.status_code, 200)
res = self.client.get(self.create_url)
self.assertRedirects(res, '%s?next=%s' % (self.login_url, self.create_url))
def test_document_controller_access(self):
self.user.user_permissions = self.dc_perms
self.user.save()
self.client.login(username=self.user.email, password='pass')
res = self.client.get(self.home_url)
self.assertEqual(res.status_code, 200)
res = self.client.get(self.create_url)
self.assertEqual(res.status_code, 200)
示例15: AckReceiptOfTransmittalTests
class AckReceiptOfTransmittalTests(TestCase):
def setUp(self):
self.trs = create_transmittal()
self.category = self.trs.document.category
self.user = UserFactory(
email='[email protected]',
password='pass',
is_superuser=True,
category=self.category)
self.client.login(email=self.user.email, password='pass')
self.url = reverse('transmittal_ack_of_receipt', args=[
self.category.organisation.slug,
self.category.slug,
self.trs.document.document_key
])
def test_non_contractor_acks_receipt(self):
"""Non contractor cannot ack receipt of transmittals."""
res = self.client.post(self.url)
self.assertEqual(res.status_code, 403)
def test_acks_receipt(self):
self.assertIsNone(self.trs.ack_of_receipt_date)
self.assertIsNone(self.trs.ack_of_receipt_author)
self.user.is_external = True
self.user.save()
res = self.client.post(self.url, follow=True)
self.assertEqual(res.status_code, 200)
self.trs.refresh_from_db()
self.assertIsNotNone(self.trs.ack_of_receipt_date)
self.assertEqual(self.trs.ack_of_receipt_author, self.user)
def test_acks_receipt_twice_fails(self):
self.user.is_external = True
self.user.save()
self.trs.ack_receipt(self.user)
res = self.client.post(self.url, follow=True)
self.assertEqual(res.status_code, 403)