本文整理汇总了Python中django.test.Client方法的典型用法代码示例。如果您正苦于以下问题:Python test.Client方法的具体用法?Python test.Client怎么用?Python test.Client使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.test
的用法示例。
在下文中一共展示了test.Client方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: client
# 需要导入模块: from django import test [as 别名]
# 或者: from django.test import Client [as 别名]
def client():
"""Django Test Client, with some convenient overriden methods.
"""
from django.test import Client
class _Client(Client):
@property
def json(self):
"""Add json method on the client for sending json type request.
Usages:
>>> import json
>>> url = reverse("phone-verify")
>>> client.json.get(url)
>>> client.json.post(url, data=json.dumps(payload))
"""
return PartialMethodCaller(
obj=self, content_type='application/json;charset="utf-8"'
)
return _Client()
示例2: setUp
# 需要导入模块: from django import test [as 别名]
# 或者: from django.test import Client [as 别名]
def setUp(self):
self.c = Client()
self.credentials = {
'username': 'voteusername',
'password': 'password'
}
author = RedditUser.objects.create(
user=User.objects.create_user(
**self.credentials
)
)
submission = Submission.objects.create(
author=author,
author_name=author.user.username,
title="vote testing"
)
Comment.create(author=author,
raw_comment="root comment",
parent=submission).save()
示例3: setUp
# 需要导入模块: from django import test [as 别名]
# 或者: from django.test import Client [as 别名]
def setUp(self):
self.c = Client()
author = RedditUser.objects.create(
user=User.objects.create_user(username="username",
password="password"))
for i in range(50):
Submission.objects.create(score=50 - i,
title=get_random_string(length=20),
author=author).save()
for i in range(1, 50, 10):
# [1, 11, 21] [31, 41] have upvotes (lists demonstrate pages)
Vote.create(user=author,
vote_object=Submission.objects.get(id=i),
vote_value=1).save()
for i in range(2, 50, 15):
# [2, 17] [32, 47] have downvotes (lists demonstrate pages)
Vote.create(user=author,
vote_object=Submission.objects.get(id=i),
vote_value=-1).save()
示例4: testNoEncryptMessageNoMdn
# 需要导入模块: from django import test [as 别名]
# 或者: from django.test import Client [as 别名]
def testNoEncryptMessageNoMdn(self):
""" Test Permutation 1: Sender sends un-encrypted data and does NOT request a receipt. """
# Create the partner with appropriate settings for this case
partner = models.Partner.objects.create(name='Client Partner',
as2_name='as2server',
target_url='http://localhost:8080/pyas2/as2receive',
compress=False,
mdn=False)
# Build and send the message to server
message_id = emailutils.make_msgid().strip('<>')
in_message, response = self.buildSendMessage(message_id, partner)
# Check if a 200 response was received
self.assertEqual(response.status_code, 200)
# Check if message was processed successfully
out_message = models.Message.objects.get(message_id=message_id)
self.assertEqual(out_message.status, 'S')
# Check if input and output files are the same
self.assertTrue(AS2SendReceiveTest.compareFiles(self.payload.file, out_message.payload.file))
示例5: setUp
# 需要导入模块: from django import test [as 别名]
# 或者: from django.test import Client [as 别名]
def setUp(self):
self.client = Client()
self.user = User.objects.create(
first_name='Ravi',
last_name='G',
email='ravi@micropyramid.com',
username='ravi@micropyramid.com',
is_superuser=True
)
self.password = 'secret'
self.user.set_password(self.password)
self.user.save()
self.category = ForumCategory.objects.create(
created_by=self.user,
title='Python',
is_active=True,
slug='python',
description='dynamic programming language'
)
示例6: setUp
# 需要导入模块: from django import test [as 别名]
# 或者: from django.test import Client [as 别名]
def setUp(self):
self.client = Client()
self.token = generate_token()
示例7: setUp
# 需要导入模块: from django import test [as 别名]
# 或者: from django.test import Client [as 别名]
def setUp(self):
self.client = Client()
self.job = Job()
self.job.position = "test"
self.job.company_name = "company test"
self.job.website = "pythonjobs.ie"
self.job.category = "full"
self.job.description = "Testing"
self.job.email = "test@test.com"
self.job.location = "Testing"
self.job.save()
示例8: setUp
# 需要导入模块: from django import test [as 别名]
# 或者: from django.test import Client [as 别名]
def setUp(self):
# Every test needs access to the request factory.
self.factory = RequestFactory()
self.user = User.objects.create_user(
username='John Doe',
email='',
password='test')
self.c = Client()
示例9: test_supports_cors
# 需要导入模块: from django import test [as 别名]
# 或者: from django.test import Client [as 别名]
def test_supports_cors(self):
client = Client()
response = client.options('/', HTTP_ORIGIN='https://example.com/', secure=True)
self.assertEqual(response.status_code, 200)
self.assertEqual(response['Access-Control-Allow-Origin'], '*')
示例10: setUp
# 需要导入模块: from django import test [as 别名]
# 或者: from django.test import Client [as 别名]
def setUp(self):
self.client = Client()
示例11: setUp
# 需要导入模块: from django import test [as 别名]
# 或者: from django.test import Client [as 别名]
def setUp(self):
demo = User()
demo.username = 'demo'
demo.first_name = 'Demo'
demo.last_name = 'Last'
demo.set_password('demo123')
demo.is_staff = False
demo.save()
self.user = demo
self.user_path = os.path.join('data', 'users', 'demo')
self.chrome = Client()
self.upload_files = []
示例12: setUp
# 需要导入模块: from django import test [as 别名]
# 或者: from django.test import Client [as 别名]
def setUp(self):
self.client = Client()
self.user = User.objects.create_user('testname', 'test@test.com', 'testpassword')
self.client.login(username='testname', password='testpassword')
示例13: setUp
# 需要导入模块: from django import test [as 别名]
# 或者: from django.test import Client [as 别名]
def setUp(self):
from core.urls import BASE
# store the base object from the server to allow mocking and direct method access
self.base = BASE
self.client = Client()
util.admin_login(self.client)
self.base.musiq.playback.start_loop()
示例14: setUp
# 需要导入模块: from django import test [as 别名]
# 或者: from django.test import Client [as 别名]
def setUp(self):
self.client = Client()
self.user = User.objects.create_user(USERNAME_PRIMARY, f'{USERNAME_PRIMARY}@thebeatles.com', PASSWORD)
self.other = User.objects.create_user(USERNAME_OTHER, f'{USERNAME_OTHER}@thebeatles.com', PASSWORD)
示例15: setUp
# 需要导入模块: from django import test [as 别名]
# 或者: from django.test import Client [as 别名]
def setUp(self):
super().setUp()
self.client = Client()