本文整理汇总了Python中staticgenerator.StaticGenerator.get_content_from_path方法的典型用法代码示例。如果您正苦于以下问题:Python StaticGenerator.get_content_from_path方法的具体用法?Python StaticGenerator.get_content_from_path怎么用?Python StaticGenerator.get_content_from_path使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类staticgenerator.StaticGenerator
的用法示例。
在下文中一共展示了StaticGenerator.get_content_from_path方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_not_found_raises_proper_exception
# 需要导入模块: from staticgenerator import StaticGenerator [as 别名]
# 或者: from staticgenerator.StaticGenerator import get_content_from_path [as 别名]
def test_not_found_raises_proper_exception(self):
response_mock = Mock(content='foo', status_code=404)
instance = StaticGenerator()
with nested(patch('staticgenerator.DummyHandler'),
self.assertRaises(StaticGeneratorException)
) as (handler_mock, cm):
handler_mock.return_value = Mock(return_value=response_mock)
instance.get_content_from_path('/some_path')
self.assertEqual(('The requested page("/some_path") returned '
'http code 404. Static Generation failed.'),
str(cm.exception))
示例2: test_request_exception_raises_proper_exception
# 需要导入模块: from staticgenerator import StaticGenerator [as 别名]
# 或者: from staticgenerator.StaticGenerator import get_content_from_path [as 别名]
def test_request_exception_raises_proper_exception(self):
instance = StaticGenerator()
with nested(patch('staticgenerator.DummyHandler'),
self.assertRaises(StaticGeneratorException)
) as (handler_mock, cm):
handler_mock.return_value = Mock(
side_effect=ValueError('exception'))
instance.get_content_from_path('/some_path')
self.assertEqual('The requested page("/some_path") raised an '
'exception. Static Generation failed. '
'Error: exception',
str(cm.exception))
示例3: test_get_content_from_path
# 需要导入模块: from staticgenerator import StaticGenerator [as 别名]
# 或者: from staticgenerator.StaticGenerator import get_content_from_path [as 别名]
def test_get_content_from_path(self):
response_mock = Mock(content='foo', status_code=200)
instance = StaticGenerator()
with patch.object(staticgenerator, 'DummyHandler') as DummyHandler:
DummyHandler().return_value = response_mock
result = instance.get_content_from_path('/some_path')
self.assertEqual('foo', result)
示例4: test_not_found_raises_proper_exception
# 需要导入模块: from staticgenerator import StaticGenerator [as 别名]
# 或者: from staticgenerator.StaticGenerator import get_content_from_path [as 别名]
def test_not_found_raises_proper_exception():
mox = Mox()
http_request, model_base, manager, model, queryset = get_mocks(mox)
settings = CustomSettings(WEB_ROOT="test_web_root")
path_mock = 'some_path'
request_mock = mox.CreateMockAnything()
request_mock.META = mox.CreateMockAnything()
request_mock.META.setdefault('SERVER_PORT', 80)
request_mock.META.setdefault('SERVER_NAME', 'localhost')
http_request.__call__().AndReturn(request_mock)
response_mock = mox.CreateMockAnything()
response_mock.content = 'foo'
response_mock.status_code = 404
handler_mock = mox.CreateMockAnything()
handler_mock.__call__().AndReturn(handler_mock)
handler_mock.__call__(request_mock).AndReturn(response_mock)
mox.ReplayAll()
try:
dummy_handler = staticgenerator.DummyHandler
staticgenerator.DummyHandler = handler_mock
instance = StaticGenerator(http_request=http_request,
model_base=model_base,
manager=manager,
model=model,
queryset=queryset,
settings=settings)
result = instance.get_content_from_path(path_mock)
except StaticGeneratorException, e:
assert str(e) == 'The requested page("some_path") returned http code 404. Static Generation failed.'
mox.VerifyAll()
return
示例5: test_get_content_from_path
# 需要导入模块: from staticgenerator import StaticGenerator [as 别名]
# 或者: from staticgenerator.StaticGenerator import get_content_from_path [as 别名]
def test_get_content_from_path():
mox = Mox()
http_request, model_base, manager, model, queryset = get_mocks(mox)
settings = CustomSettings(WEB_ROOT="test_web_root")
path_mock = 'some_path'
request_mock = mox.CreateMockAnything()
request_mock.META = mox.CreateMockAnything()
request_mock.META.setdefault('SERVER_PORT', 80)
request_mock.META.setdefault('SERVER_NAME', 'localhost')
response_mock = mox.CreateMockAnything()
response_mock.content = 'foo'
response_mock.status_code = 200
http_request.__call__().AndReturn(request_mock)
handler_mock = mox.CreateMockAnything()
handler_mock.__call__().AndReturn(handler_mock)
handler_mock.__call__(request_mock).AndReturn(response_mock)
mox.ReplayAll()
try:
dummy_handler = staticgenerator.DummyHandler
staticgenerator.DummyHandler = handler_mock
instance = StaticGenerator(http_request=http_request,
model_base=model_base,
manager=manager,
model=model,
queryset=queryset,
settings=settings)
result = instance.get_content_from_path(path_mock)
finally:
staticgenerator.DummyHandler = dummy_handler
assert result == 'foo'
mox.VerifyAll()