本文整理汇总了Python中utils.factories.UserFactory.create方法的典型用法代码示例。如果您正苦于以下问题:Python UserFactory.create方法的具体用法?Python UserFactory.create怎么用?Python UserFactory.create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类utils.factories.UserFactory
的用法示例。
在下文中一共展示了UserFactory.create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setUp
# 需要导入模块: from utils.factories import UserFactory [as 别名]
# 或者: from utils.factories.UserFactory import create [as 别名]
def setUp(self):
book = factories.BookFactory.create()
user = UserFactory.create(username='phildini')
bookowner = factories.BookOwnerFactory.create(user=user,book=book)
contact = factories.ContactFactory(book=book)
request_factory = RequestFactory()
request = request_factory.get(contact.get_absolute_url())
request.user = UserFactory.create()
self.response = views.contact_views.ContactListView.as_view()(request)
示例2: setUp
# 需要导入模块: from utils.factories import UserFactory [as 别名]
# 或者: from utils.factories.UserFactory import create [as 别名]
def setUp(self):
book = factories.BookFactory.create()
self.user = UserFactory.create(username='phildini')
bookowner = factories.BookOwnerFactory.create(user=self.user,book=book)
self.contact = factories.ContactFactory.create(book=book)
request_factory = RequestFactory()
self.request = request_factory.get(self.contact.get_absolute_url())
示例3: test_contact_detail_view_404_wrong_user
# 需要导入模块: from utils.factories import UserFactory [as 别名]
# 或者: from utils.factories.UserFactory import create [as 别名]
def test_contact_detail_view_404_wrong_user(self):
self.request.user = UserFactory.create()
with self.assertRaises(Http404):
views.contact_views.ContactView.as_view()(
self.request,
pk=self.contact.pk,
)
示例4: test_tag_create_view_bad_book
# 需要导入模块: from utils.factories import UserFactory [as 别名]
# 或者: from utils.factories.UserFactory import create [as 别名]
def test_tag_create_view_bad_book(self):
request = self.factory.post('/api/tags/', {'tag': 'Test tag', 'book': str(self.book.id)}, format='json')
user = UserFactory.create(username='nicholle')
force_authenticate(request, user=user)
view = views.TagListCreateAPIView.as_view()
response = view(request)
response.render()
self.assertEqual(response.status_code, 401)
示例5: setUp
# 需要导入模块: from utils.factories import UserFactory [as 别名]
# 或者: from utils.factories.UserFactory import create [as 别名]
def setUp(self):
self.factory = APIRequestFactory()
self.book = factories.BookFactory.create()
self.user = UserFactory.create(username='phildini')
bookowner = factories.BookOwnerFactory.create(
book=self.book,
user=self.user,
)
示例6: test_tag_list_view_wrong_user_for_book
# 需要导入模块: from utils.factories import UserFactory [as 别名]
# 或者: from utils.factories.UserFactory import create [as 别名]
def test_tag_list_view_wrong_user_for_book(self):
tag = factories.TagFactory.create(book=self.book)
request = self.factory.get('/api/tags/', format='json')
user = UserFactory.create(username='asheesh')
force_authenticate(request, user=user)
response = views.TagListCreateAPIView.as_view()(request)
response.render()
self.assertEqual(response.status_code, 200)
self.assertEqual(len(response.data), 0)
示例7: test_log_delete_view_401_if_wrong_user
# 需要导入模块: from utils.factories import UserFactory [as 别名]
# 或者: from utils.factories.UserFactory import create [as 别名]
def test_log_delete_view_401_if_wrong_user(self):
self.request = self.request_factory.get(
reverse('log-delete', kwargs={'pk': self.log.id})
)
self.request.user = UserFactory.create()
with self.assertRaises(PermissionDenied):
views.log_views.DeleteLogView.as_view()(
self.request,
pk=self.log.pk,
)
示例8: test_tagged_list_view_401_if_wrong_user
# 需要导入模块: from utils.factories import UserFactory [as 别名]
# 或者: from utils.factories.UserFactory import create [as 别名]
def test_tagged_list_view_401_if_wrong_user(self):
request = self.request_factory.get(
reverse('contacts-tagged', kwargs={'pk': self.tag.id})
)
request.user = UserFactory.create()
with self.assertRaises(Http404):
views.contact_views.TaggedContactListView.as_view()(
request,
pk=self.tag.pk,
)
示例9: test_log_list_view_wrong_user_for_book
# 需要导入模块: from utils.factories import UserFactory [as 别名]
# 或者: from utils.factories.UserFactory import create [as 别名]
def test_log_list_view_wrong_user_for_book(self):
request = self.factory.get(self.url, format='json')
user = UserFactory.create(username='asheesh')
force_authenticate(request, user=user)
response = views.LogListCreateAPIView.as_view()(
request,
pk=self.contact.id,
)
response.render()
self.assertEqual(response.status_code, 404)
示例10: test_log_edit_view_401_if_right_user
# 需要导入模块: from utils.factories import UserFactory [as 别名]
# 或者: from utils.factories.UserFactory import create [as 别名]
def test_log_edit_view_401_if_right_user(self):
self.request = self.request_factory.get(
reverse('log-edit', kwargs={'pk': self.log.id})
)
self.request.user = UserFactory.create()
with self.assertRaises(PermissionDenied):
views.log_views.EditLogView.as_view()(
self.request,
pk=self.log.pk,
)
示例11: test_contact_create_view_wrong_book_for_user
# 需要导入模块: from utils.factories import UserFactory [as 别名]
# 或者: from utils.factories.UserFactory import create [as 别名]
def test_contact_create_view_wrong_book_for_user(self):
request = self.factory.post(
'/api/contacts/',
{'name': 'Philip', 'book': str(self.book.id)},
format='json',
)
user = UserFactory.create(username='asheesh')
force_authenticate(request, user=user)
response = views.ContactListCreateAPIView.as_view()(request)
response.render()
self.assertEqual(response.status_code, 401)
示例12: test_log_create_view_wrong_book_for_user
# 需要导入模块: from utils.factories import UserFactory [as 别名]
# 或者: from utils.factories.UserFactory import create [as 别名]
def test_log_create_view_wrong_book_for_user(self):
request = self.factory.post(
'/api/contacts/',
{'contact': str(self.contact.id)},
format='json',
)
user = UserFactory.create(username='asheesh')
force_authenticate(request, user=user)
response = views.LogListCreateAPIView.as_view()(
request,
pk=self.contact.id,
)
response.render()
self.assertEqual(response.status_code, 404)
示例13: test_contact_detail_raises_404_if_wrong_user
# 需要导入模块: from utils.factories import UserFactory [as 别名]
# 或者: from utils.factories.UserFactory import create [as 别名]
def test_contact_detail_raises_404_if_wrong_user(self):
contact = factories.ContactFactory.create(book=self.book)
request = self.factory.get(
'/api/contacts/{}'.format(contact.pk),
format='json',
)
user = UserFactory.create(username="asheesh")
force_authenticate(request, user=user)
response = views.ContactDetailEditAPIView.as_view()(
request,
pk=contact.id,
)
response.render()
self.assertEqual(response.status_code, 404)
示例14: test_contact_list_view_contains_only_what_it_should
# 需要导入模块: from utils.factories import UserFactory [as 别名]
# 或者: from utils.factories.UserFactory import create [as 别名]
def test_contact_list_view_contains_only_what_it_should(self):
book = factories.BookFactory.create()
user = UserFactory.create(username='nicholle')
factories.BookOwnerFactory.create(book=book, user=user)
good_contact = factories.ContactFactory.create(book=book)
bad_contact = factories.ContactFactory.create()
good_tag = factories.TagFactory.create(book=book)
bad_tag = factories.TagFactory.create()
good_contact.tags.add(good_tag)
request_factory = RequestFactory()
request = request_factory.get(reverse('contacts-list'))
request.user = user
response = views.contact_views.ContactListView.as_view()(request)
self.assertEqual(len(response.context_data.get('tags')), 1)
self.assertEqual(len(response.context_data.get('contact_list')), 1)
self.assertEqual(response.context_data.get('tags')[0], good_tag)
self.assertEqual(
response.context_data.get('contact_list')[0], good_contact,
)
示例15: test_review_user_view_200
# 需要导入模块: from utils.factories import UserFactory [as 别名]
# 或者: from utils.factories.UserFactory import create [as 别名]
def test_review_user_view_200(self):
user = UserFactory.create()
user.is_staff = True
self.request.user = user
response = ReviewUserView.as_view()(self.request)
self.assertEqual(response.status_code, 200)