本文整理汇总了Python中pyramid.testing.DummyRequest.content_type方法的典型用法代码示例。如果您正苦于以下问题:Python DummyRequest.content_type方法的具体用法?Python DummyRequest.content_type怎么用?Python DummyRequest.content_type使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyramid.testing.DummyRequest
的用法示例。
在下文中一共展示了DummyRequest.content_type方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_mapped_values_request
# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import content_type [as 别名]
def test_mapped_values_request() -> None:
"""Test that values are correctly mapped from pyramid's Request."""
pyramid_request = DummyRequest(path="/foo")
pyramid_request.matched_route = DummyRoute(name="foo", pattern="/foo")
pyramid_request.matchdict["foo"] = "bar"
pyramid_request.headers["X-Foo"] = "Bar"
pyramid_request.cookies["tasty-foo"] = "tasty-bar"
pyramid_request.content_type = "text/html"
assert pyramid_request.host_url == "http://example.com"
assert pyramid_request.path == "/foo"
assert pyramid_request.method == "GET"
openapi_request = PyramidOpenAPIRequest(pyramid_request)
assert openapi_request.request == pyramid_request
assert openapi_request.host_url == "http://example.com"
assert openapi_request.path == "/foo"
assert openapi_request.method == "get"
assert openapi_request.path_pattern == "/foo"
assert openapi_request.body == ""
assert openapi_request.mimetype == "text/html"
assert openapi_request.parameters == {
"cookies": {"tasty-foo": "tasty-bar"},
"headers": {"X-Foo": "Bar"},
"path": {"foo": "bar"},
"query": {},
}
示例2: test_time_slot_receiver_JSON_runs
# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import content_type [as 别名]
def test_time_slot_receiver_JSON_runs(self):
"""
This method tests the time slot receiver JSON view when there are runs in the server-side database. The
expected result of this pattern is for the correct JSON response to be retrieved.
"""
request = DummyRequest(route='/scheduler.json')
if project_config["start_date"]:
input_date = datetime.datetime.combine(project_config["start_date"], datetime.time())
else:
input_date = datetime.datetime.today() + datetime.timedelta(hours=1)
user_input = int(time.mktime(input_date.timetuple()) * 1000)
request.content_type = "application/json"
request.POST["date"] = str(user_input)
# Insert runs that will the next hour with even minutes that are a multiple of 10
with transaction.manager:
runs = []
for minutes in range(0, 60, 10):
runs.append(Run(create_input_pattern(), datetime.datetime(input_date.year, input_date.month,
input_date.day, input_date.hour, minutes), ""))
DBSession.add_all(runs)
DBSession.commit()
response = time_slot_reciever_JSON(request)
# Assert that a response has been received.
assert response
response_dict = eval(str(response))
for min in range(0, 60, 10):
# Assert that the given slot is not in the response (means there is a run at this point)
assert min not in response_dict[input_date.hour]
示例3: test_time_slot_reciever_JSON
# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import content_type [as 别名]
def test_time_slot_reciever_JSON(self):
"""
This method will test the time slot receiver JSON view of the scheduling page. The expected result of this test
is for the correct JSON response to be retrieved.
"""
request = DummyRequest(route='/scheduler.json')
if project_config["start_date"]:
input_date = datetime.datetime.combine(project_config["start_date"], datetime.time())
else:
input_date = datetime.datetime.today() + datetime.timedelta(days=1)
user_input = int(time.mktime(input_date.timetuple()) * 1000)
request.content_type = "application/json"
request.POST["date"] = str(user_input)
response = time_slot_reciever_JSON(request)
# Assert that a response has been retrieved.
assert response
response_dict = eval(str(response))
no_of_hours = math.ceil(((project_config["closing_time"].hour*60 + project_config["closing_time"].minute) -
(project_config["starting_time"].hour*60 + project_config["starting_time"].minute)) / 60)
# Assert the response holds the correct data.
assert len(response_dict["hours"]) == no_of_hours
示例4: test_pattern_clearer_JSON
# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import content_type [as 别名]
def test_pattern_clearer_JSON(self):
"""
This method tests the JSON clearer view linked to the pattern input page. The expected result of this test
is for the correct JSON response to be retrieved.
"""
# Setup
request = DummyRequest(route='/pattern_clearer.json')
input = create_input_pattern()
request.body = json.dumps(input)
request.content_type = "application/json"
request.json_body = input
request.session["pattern"] = input
response = pattern_input_clearer_JSON(request)
# Assert that the pattern has been removed from the session
assert "pattern" not in response.keys()
示例5: test_pattern_input_receiver_JSON
# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import content_type [as 别名]
def test_pattern_input_receiver_JSON(self):
"""
This method tests the JSON receiver view linked to the pattern input page. The expected result of this test
is for the correct JSON response to be retrieved.
"""
# Setup
request = DummyRequest(route='/pattern_receiver.json')
input = create_input_pattern()
request.body = json.dumps(input)
request.content_type = "application/json"
request.json_body = input
response = pattern_input_receiver_JSON(request)
# Assert that there is a pattern in the session.
assert request.session["pattern"] == input
responseDict = response
# Assert that the correct number of turns has been calculated and stored.
assert responseDict["turns"] == 53
# Assert that the correct run time has been calculated and stored.
assert responseDict["runtime"] == SLEEP_TIME * 53