本文整理汇总了Python中pyramid.testing.DummyRequest.POST["date"]方法的典型用法代码示例。如果您正苦于以下问题:Python DummyRequest.POST["date"]方法的具体用法?Python DummyRequest.POST["date"]怎么用?Python DummyRequest.POST["date"]使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyramid.testing.DummyRequest
的用法示例。
在下文中一共展示了DummyRequest.POST["date"]方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_time_slot_receiver_JSON_runs
# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import POST["date"] [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]
示例2: test_time_slot_reciever_JSON
# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import POST["date"] [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
示例3: test_time_slot_receiver_JSON_timestring_failure
# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import POST["date"] [as 别名]
def test_time_slot_receiver_JSON_timestring_failure(self):
"""
This method will test the functionality of the time_slot_receiver_JSON view. The expected result of this test
is for the view to catch an error because the timestring for which the time_slot should be retrieved is in the
wrong format.
"""
# Set up a dummy request for testing poor formatting of the timestring
request = DummyRequest(route='/sheduler.json')
request.POST["date"] = datetime.datetime.now()
# Assert that an exception is thrown due to the timestring not being formatted correctly
try:
response = time_slot_reciever_JSON(request)
except HTTPBadRequest as e:
assert e.args[0] == "Timestring was not formatted correctly!"