本文整理汇总了Python中django.http.request.HttpRequest.method方法的典型用法代码示例。如果您正苦于以下问题:Python HttpRequest.method方法的具体用法?Python HttpRequest.method怎么用?Python HttpRequest.method使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.http.request.HttpRequest
的用法示例。
在下文中一共展示了HttpRequest.method方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_movie_no_add_during_get_request
# 需要导入模块: from django.http.request import HttpRequest [as 别名]
# 或者: from django.http.request.HttpRequest import method [as 别名]
def test_movie_no_add_during_get_request(self):
request = HttpRequest()
request.method = 'GET'
home_page(request)
self.assertEqual(Movie.objects.count(), 0)
示例2: test_upload_file
# 需要导入模块: from django.http.request import HttpRequest [as 别名]
# 或者: from django.http.request.HttpRequest import method [as 别名]
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)
示例3: test_upload_single_sample__unpaired
# 需要导入模块: from django.http.request import HttpRequest [as 别名]
# 或者: from django.http.request.HttpRequest import method [as 别名]
def test_upload_single_sample__unpaired(self):
project = self.common_entities['project']
request = HttpRequest()
request.POST = {
'projectUid': project.uid
}
request.method = 'POST'
request.user = self.common_entities['user']
authenticate(username=TEST_USERNAME, password=TEST_PASSWORD)
self.assertTrue(request.user.is_authenticated())
EXPERIMENT_SAMPLE_LABEL = 'my sample'
request.POST['sampleLabel'] = EXPERIMENT_SAMPLE_LABEL
request.FILES['fastq1'] = UploadedFile(
file=open(TEST_FQ1_FILE),
name='read1.fq')
response = upload_single_sample(request)
self.assertEqual(STATUS_CODE__SUCCESS, response.status_code)
self.assertFalse('error' in json.loads(response.content))
sample = ExperimentSample.objects.get(label=EXPERIMENT_SAMPLE_LABEL)
self.assertTrue(sample)
datasets = sample.dataset_set.all()
# num_datasets: 1 fastq + 1 fastqc = 2
self.assertEqual(2, len(datasets))
for dataset in datasets:
self.assertEqual(Dataset.STATUS.READY, dataset.status)
示例4: get_request
# 需要导入模块: from django.http.request import HttpRequest [as 别名]
# 或者: from django.http.request.HttpRequest import method [as 别名]
def get_request(self):
request = HttpRequest()
request.META['REMOTE_ADDR'] = '1.2.3.4'
request.method = 'POST'
request.session = SessionStore()
request._messages = default_storage(request)
request.user = AnonymousUser()
return request
示例5: test_home_page_redirects_after_POST
# 需要导入模块: from django.http.request import HttpRequest [as 别名]
# 或者: from django.http.request.HttpRequest import method [as 别名]
def test_home_page_redirects_after_POST(self):
request = HttpRequest()
request.method = "POST"
request.POST["item_text"] = 'A new list item'
response = home_page(request)
self.assertEqual(response.status_code, 302)
self.assertEqual(response['location'], '/')
示例6: test_movie_save_post_content_and_redirect
# 需要导入模块: from django.http.request import HttpRequest [as 别名]
# 或者: from django.http.request.HttpRequest import method [as 别名]
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'], "/")
示例7: test_movie_save_post_content_and_return
# 需要导入模块: from django.http.request import HttpRequest [as 别名]
# 或者: from django.http.request.HttpRequest import method [as 别名]
def test_movie_save_post_content_and_return(self):
request = HttpRequest()
request.method = 'POST'
request.POST['movie_name'] = 'Troy'
home_page(request)
self.assertEqual(Movie.objects.count(), 1)
self.assertEqual(Movie.objects.first().name, "Troy")
示例8: test
# 需要导入模块: from django.http.request import HttpRequest [as 别名]
# 或者: from django.http.request.HttpRequest import method [as 别名]
def test(self):
module = PositiveIntegerInputModule()
request = HttpRequest()
request.method = 'GET'
response = module.view(request)
data = json.loads(response.content)
self.assertNotEqual(len(data['module']), 0)
self.assertEqual(data['moduleDisplay'], "1 is a valid positive integer")
self.assertEqual(data['moduleResult'], 1)
request.method = 'POST'
request.POST['value'] = '4'
response = module.view(request)
data = json.loads(response.content)
self.assertEqual(data['moduleDisplay'], "4 is a valid positive integer")
self.assertEqual(data['moduleResult'], 4)
示例9: test_home_page_can_save_a_POST_requeste
# 需要导入模块: from django.http.request import HttpRequest [as 别名]
# 或者: from django.http.request.HttpRequest import method [as 别名]
def test_home_page_can_save_a_POST_requeste(self):
request = HttpRequest()
request.method = "POST"
request.POST["item_text"] = 'A new list item'
response = home_page(request)
self.assertEqual(Item.objects.count(), 1)
newItem = Item.objects.first()
self.assertEqual(newItem.text, 'A new list item')
示例10: test_home_page_can_save_a_POST_request
# 需要导入模块: from django.http.request import HttpRequest [as 别名]
# 或者: from django.http.request.HttpRequest import method [as 别名]
def test_home_page_can_save_a_POST_request(self):
request = HttpRequest()
request.method = 'POST'
request.POST['item_text'] = 'A new list item'
response = home_page(request)
self.assertEqual(Item.objects.all().count(), 1)
new_item = Item.objects.all()[0]
self.assertEqual(new_item.text, 'A new list item')
示例11: test_movie_list_in_table
# 需要导入模块: from django.http.request import HttpRequest [as 别名]
# 或者: from django.http.request.HttpRequest import method [as 别名]
def test_movie_list_in_table(self):
Movie.objects.create(name = "Troy")
Movie.objects.create(name = "Terminator")
request = HttpRequest()
request.method = 'GET'
response = home_page(request)
self.assertIn("Troy", response.content)
self.assertIn("Terminator", response.content)
示例12: setUp
# 需要导入模块: from django.http.request import HttpRequest [as 别名]
# 或者: from django.http.request.HttpRequest import method [as 别名]
def setUp(self):
super(TestGradingViewInternals, self).setUp()
r = HttpRequest()
r.user = User.objects.get(username = "teacher")
r.method = "get"
args = []
kwargs = {"group_id" : self.group.pk, "activity_id": self.activity.pk}
view = GradeGroupActivity()
view.request = r
view.dispatch(r,*args, **kwargs)
self.view = view
示例13: test_add_online_course_save_given_course
# 需要导入模块: from django.http.request import HttpRequest [as 别名]
# 或者: from django.http.request.HttpRequest import method [as 别名]
def test_add_online_course_save_given_course(self):
request = HttpRequest()
request.method = 'POST'
request.POST['course_name'] = 'Apache Spark'
request.POST['course_url'] = 'www.coursera.com/apache_spark'
request.POST['course_description'] = 'Introduction to Apache Spark'
add_online_course(request)
courses = Course.objects.all()
self.assertEqual("Apache Spark",courses[0].name)
self.assertEqual('Introduction to Apache Spark',courses[0].description)
示例14: test_form
# 需要导入模块: from django.http.request import HttpRequest [as 别名]
# 或者: from django.http.request.HttpRequest import method [as 别名]
def test_form(self):
request = HttpRequest()
request.POST = {
'name': 'test form tag',
'app_label': self.committee_content_type.app_label,
'object_type': self.committee_content_type.model,
'object_id': self.committee_meeting.id
}
request.method = 'POST'
request.user = self.user
suggest_tag_post(request)
tag_suggestion = TagSuggestion.objects.get(name='test form tag')
self.assertEqual(tag_suggestion.object, self.committee_meeting)
self.assertEqual(tag_suggestion.suggested_by, self.user)
示例15: test_form
# 需要导入模块: from django.http.request import HttpRequest [as 别名]
# 或者: from django.http.request.HttpRequest import method [as 别名]
def test_form(self):
request = HttpRequest()
request.POST = {
"name": "test form tag",
"app_label": self.committee_content_type.app_label,
"object_type": self.committee_content_type.model,
"object_id": self.committee_meeting.id,
}
request.method = "POST"
request.user = self.user
suggest_tag_post(request)
tag_suggestion = TagSuggestion.objects.get(name="test form tag")
self.assertEqual(tag_suggestion.object, self.committee_meeting)
self.assertEqual(tag_suggestion.suggested_by, self.user)