本文整理汇总了Python中django.http.request.HttpRequest类的典型用法代码示例。如果您正苦于以下问题:Python HttpRequest类的具体用法?Python HttpRequest怎么用?Python HttpRequest使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了HttpRequest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_upload_file
def test_upload_file(self):
VARIANT_SET_NAME = 'newVariant'
self.assertEqual(0, VariantSet.objects.count())
refGenome = self.common_entities['reference_genome']
request = HttpRequest()
request.POST = {
'refGenomeUid': refGenome.uid,
'variantSetName': VARIANT_SET_NAME,
'createSetType': 'from-file'
}
request.method = 'POST'
request.user = self.common_entities['user']
authenticate(username=TEST_USERNAME, password=TEST_PASSWORD)
self.assertTrue(request.user.is_authenticated())
#random test file selected
variant_set_file = os.path.join(GD_ROOT, 'test_data',
'recoli_321UAG_variant_set_upload.vcf')
mock_uploaded_file = UploadedFile(
file=StringIO.StringIO(),
name=variant_set_file)
request.FILES['vcfFile'] = mock_uploaded_file
response = create_variant_set(request)
self.assertEqual(STATUS_CODE__SUCCESS, response.status_code)
variantsets = VariantSet.objects.all()
self.assertEqual(1, len(variantsets))
self.assertEqual(VARIANT_SET_NAME, VariantSet.objects.get().label)
self.assertEqual(refGenome, VariantSet.objects.get().reference_genome)
示例2: test_list_owner_is_saved_if_user_is_authenticated
def test_list_owner_is_saved_if_user_is_authenticated(self):
request = HttpRequest()
request.user = User.objects.create(email='[email protected]')
request.POST['text'] = 'new list item'
new_list(request)
list_ = List.objects.first()
self.assertEqual(list_.owner, request.user)
示例3: test_get_ip
def test_get_ip(self):
request = HttpRequest()
request.META['REMOTE_ADDR'] = '1.2.3.4'
self.assertEqual(
get_ip_address(request),
'1.2.3.4'
)
示例4: handle
def handle(self, *args, **options):
# Check params
if len(args) != 4:
raise CommandError('Invalid number of parameters!')
# Get translation object
try:
translation = Translation.objects.get(
subproject__project__slug=args[0],
subproject__slug=args[1],
language__code=args[2],
)
except Translation.DoesNotExist:
raise CommandError('No matching translation project found!')
# Get user
try:
user = User.objects.get(email=options['author'])
except User.DoesNotExist:
raise CommandError('Import user does not exist!')
# Create fake request object
request = HttpRequest()
request.user = user
# Process import
try:
with open(args[3], 'r') as handle:
translation.merge_upload(
request, handle, False, method='suggest',
author=get_author_name(user),
)
except IOError:
raise CommandError('Failed to import translation file!')
示例5: test_mixed
def test_mixed(self):
req = HttpRequest()
req.user = AnonymousUser()
AAAAndAON = And(AlwaysAndAlways, AlwaysOrNever)
AOAAndAAN = And(AlwaysOrAlways, AlwaysAndNever)
self.assertTrue(AAAAndAON(request=req).is_authorized())
self.assertFalse(AOAAndAAN(request=req).is_authorized())
示例6: test_and
def test_and(self):
req = HttpRequest()
req.user = AnonymousUser()
self.assertTrue(AlwaysAndAlways(request=req).is_authorized())
self.assertFalse(AlwaysAndNever(request=req).is_authorized())
self.assertFalse(NeverAndAlways(request=req).is_authorized())
self.assertFalse(NeverAndNever(request=req).is_authorized())
示例7: handle
def handle(self, *args, **options):
# Check params
if len(args) != 4:
raise CommandError('Invalid number of parameters!')
# Get translation object
translation = self.get_translation(args)
# Get user
try:
user = User.objects.get(email=options['author'])
except User.DoesNotExist:
raise CommandError('Import user does not exist!')
# Create fake request object
request = HttpRequest()
request.user = user
# Process import
try:
with open(args[3], 'rb') as handle:
translation.merge_upload(
request, handle, False, method='suggest',
author=get_author_name(user),
)
except IOError:
raise CommandError('Failed to import translation file!')
示例8: test_with_server_name
def test_with_server_name(self):
request = HttpRequest()
request.META = {
'SERVER_NAME': 'example.com',
'SERVER_PORT': 80
}
self.assertEqual(Site.find_for_request(request), self.site)
示例9: test_agent
def test_agent(self):
request = HttpRequest()
request.META['HTTP_USER_AGENT'] = 'agent'
self.assertEqual(
get_user_agent(request),
'Other / Other / Other'
)
示例10: test_movie_no_add_during_get_request
def test_movie_no_add_during_get_request(self):
request = HttpRequest()
request.method = 'GET'
home_page(request)
self.assertEqual(Movie.objects.count(), 0)
示例11: test_agent_long
def test_agent_long(self):
request = HttpRequest()
request.META['HTTP_USER_AGENT'] = 'agent ' * 200
self.assertLess(
len(get_user_agent(request)),
200
)
示例12: test_vocabulary_render_one
def test_vocabulary_render_one(self):
request = HttpRequest()
request.course = self.sample_course
vocabulary = Vocabulary.objects.get(name="shapes")
detail = VocabularyResource().render_one(request, vocabulary)
self.assertEquals(detail['display_name'], "Shapes")
self.assertEquals(len(detail['term_set']), 2)
示例13: test_not
def test_not(self):
req = HttpRequest()
req.user = AnonymousUser()
self.assertFalse(NotAlways(request=req).is_authorized())
self.assertTrue(NotNever(request=req).is_authorized())
self.assertFalse(NotNeverAlways(request=req).is_authorized())
self.assertFalse(NotAlwaysNever(request=req).is_authorized())
self.assertTrue(NotNeverNever(request=req).is_authorized())
示例14: test_calls_auth_login_if_authenticate_returns_a_user
def test_calls_auth_login_if_authenticate_returns_a_user(self,
mock_login,
mock_authenticate):
request = HttpRequest()
request.POST['assertion'] = 'asserted'
mock_user = mock_authenticate.return_value
login(request)
mock_login.assert_called_once_with(request, mock_user)
示例15: test_movie_save_post_content_and_redirect
def test_movie_save_post_content_and_redirect(self):
request = HttpRequest()
request.method = 'POST'
request.POST['movie_name'] = 'Troy'
response = home_page(request)
self.assertEqual(response.status_code, 302)
self.assertEqual(response['location'], "/")