本文整理汇总了Python中staticgenerator.StaticGenerator.publish_from_path方法的典型用法代码示例。如果您正苦于以下问题:Python StaticGenerator.publish_from_path方法的具体用法?Python StaticGenerator.publish_from_path怎么用?Python StaticGenerator.publish_from_path使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类staticgenerator.StaticGenerator
的用法示例。
在下文中一共展示了StaticGenerator.publish_from_path方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_publish_from_path_hard_links_stale_file
# 需要导入模块: from staticgenerator import StaticGenerator [as 别名]
# 或者: from staticgenerator.StaticGenerator import publish_from_path [as 别名]
def test_publish_from_path_hard_links_stale_file(self):
instance = StaticGenerator()
instance.publish_from_path('/some_path', content='some_content')
self.assertEqual(os.stat('test_web_root/fresh/some_path').st_ino,
os.stat('test_web_root/stale/some_path').st_ino)
示例2: test_publish_from_path
# 需要导入模块: from staticgenerator import StaticGenerator [as 别名]
# 或者: from staticgenerator.StaticGenerator import publish_from_path [as 别名]
def test_publish_from_path():
mox = Mox()
http_request, model_base, manager, model, queryset = get_mocks(mox)
fs_mock = mox.CreateMockAnything()
fs_mock.join("test_web_root", "some_path/index.html").AndReturn("test_web_root/some_path")
fs_mock.dirname("test_web_root/some_path").AndReturn("test_web_root")
fs_mock.exists("test_web_root").AndReturn(True)
f = mox.CreateMockAnything()
filename = "some_temp_file"
fs_mock.tempfile(directory="test_web_root").AndReturn([f, filename])
fs_mock.write(f, "some_content")
fs_mock.close(f)
fs_mock.chmod(filename, stat.S_IREAD | stat.S_IWRITE | stat.S_IWUSR | stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP | stat.S_IROTH)
fs_mock.rename('some_temp_file', 'test_web_root/some_path')
settings = CustomSettings(WEB_ROOT="test_web_root")
mox.ReplayAll()
instance = StaticGenerator(http_request=http_request,
model_base=model_base,
manager=manager,
model=model,
queryset=queryset,
settings=settings,
fs=fs_mock)
instance.publish_from_path("some_path", content="some_content")
mox.VerifyAll()
示例3: test_publish_from_path_creates_current_file
# 需要导入模块: from staticgenerator import StaticGenerator [as 别名]
# 或者: from staticgenerator.StaticGenerator import publish_from_path [as 别名]
def test_publish_from_path_creates_current_file(self):
instance = StaticGenerator()
instance.publish_from_path('/some_path', content='some_content')
self.assertEqual('some_content',
open('test_web_root/fresh/some_path').read())
示例4: test_publish_raises_when_unable_to_create_temp_file
# 需要导入模块: from staticgenerator import StaticGenerator [as 别名]
# 或者: from staticgenerator.StaticGenerator import publish_from_path [as 别名]
def test_publish_raises_when_unable_to_create_temp_file():
mox = Mox()
http_request, model_base, manager, model, queryset = get_mocks(mox)
fs_mock = mox.CreateMockAnything()
fs_mock.join("test_web_root", "some_path/index.html").AndReturn("test_web_root/some_path")
fs_mock.dirname("test_web_root/some_path").AndReturn("test_web_root")
fs_mock.exists("test_web_root").AndReturn(True)
fs_mock.tempfile(directory="test_web_root").AndRaise(ValueError())
settings = CustomSettings(WEB_ROOT="test_web_root")
mox.ReplayAll()
instance = StaticGenerator(http_request=http_request,
model_base=model_base,
manager=manager,
model=model,
queryset=queryset,
settings=settings,
fs=fs_mock)
try:
instance.publish_from_path("some_path", content="some_content")
except StaticGeneratorException, e:
assert str(e) == 'Could not create the file: test_web_root/some_path'
mox.VerifyAll()
return
示例5: test_publish_fails_silently_when_unable_to_rename_temp_file
# 需要导入模块: from staticgenerator import StaticGenerator [as 别名]
# 或者: from staticgenerator.StaticGenerator import publish_from_path [as 别名]
def test_publish_fails_silently_when_unable_to_rename_temp_file(self):
instance = StaticGenerator()
with patch('os.rename') as rename:
rename.side_effect = ValueError('message')
instance.publish_from_path('/some_path', content='some_content')
self.assertFalse(os.path.exists('test_web_root/fresh/some_path'))
示例6: process_response
# 需要导入模块: from staticgenerator import StaticGenerator [as 别名]
# 或者: from staticgenerator.StaticGenerator import publish_from_path [as 别名]
def process_response(self, request, response):
if response.status_code == 200:
for url in self.urls:
if url.match(request.path):
gen = StaticGenerator()
gen.publish_from_path(request.path, response.content)
break
return response
示例7: test_publish_raises_when_unable_to_hard_link_stale_file
# 需要导入模块: from staticgenerator import StaticGenerator [as 别名]
# 或者: from staticgenerator.StaticGenerator import publish_from_path [as 别名]
def test_publish_raises_when_unable_to_hard_link_stale_file(self):
instance = StaticGenerator()
with nested(patch('os.link'),
self.assertRaises(StaticGeneratorException)
) as (link, cm):
link.side_effect = OSError(2, 'message')
instance.publish_from_path('/some_path', content='some_content')
self.assertEqual('Could not link file', str(cm.exception))
self.assertEqual('test_web_root/fresh/some_path', cm.exception.src)
self.assertEqual('test_web_root/stale/some_path', cm.exception.dst)
示例8: test_publish_raises_when_unable_to_create_temp_file
# 需要导入模块: from staticgenerator import StaticGenerator [as 别名]
# 或者: from staticgenerator.StaticGenerator import publish_from_path [as 别名]
def test_publish_raises_when_unable_to_create_temp_file(self):
instance = StaticGenerator()
with nested(patch('tempfile.mkstemp'),
self.assertRaises(StaticGeneratorException)
) as (mkstemp, cm):
mkstemp.side_effect = ValueError('message')
instance.publish_from_path('/some_path', content='some_content')
self.assertEqual('Could not write temporary fresh file',
str(cm.exception))
self.assertEqual('test_web_root/fresh', cm.exception.fresh_directory)
示例9: test_publish_raises_when_unable_to_create_current_folder
# 需要导入模块: from staticgenerator import StaticGenerator [as 别名]
# 或者: from staticgenerator.StaticGenerator import publish_from_path [as 别名]
def test_publish_raises_when_unable_to_create_current_folder(self):
instance = StaticGenerator()
with nested(patch('os.path.exists'),
patch('os.makedirs'),
self.assertRaises(StaticGeneratorException)
) as (exists, makedirs, cm):
exists.return_value = False
makedirs.side_effect = ValueError('message')
instance.publish_from_path('/some_path', content='some_content')
self.assertEqual('Could not create directory', str(cm.exception))
self.assertEqual('test_web_root/fresh', cm.exception.directory)
示例10: test_publish_raises_when_unable_to_create_stale_folder
# 需要导入模块: from staticgenerator import StaticGenerator [as 别名]
# 或者: from staticgenerator.StaticGenerator import publish_from_path [as 别名]
def test_publish_raises_when_unable_to_create_stale_folder(self):
real_makedirs = os.makedirs
def makedirs_mock(directory, *args):
if directory == 'test_web_root/stale':
raise ValueError()
real_makedirs(directory, *args)
instance = StaticGenerator()
with nested(patch('os.path.exists'),
patch('os.makedirs'),
self.assertRaises(StaticGeneratorException)
) as (exists, makedirs, cm):
exists.return_value = False
makedirs.side_effect = makedirs_mock
instance.publish_from_path('/some_path', content='some_content')
self.assertEqual('Could not create directory', str(cm.exception))
self.assertEqual('test_web_root/stale', cm.exception.directory)
示例11: test_publish_from_path_serves_stale_file_temporarily
# 需要导入模块: from staticgenerator import StaticGenerator [as 别名]
# 或者: from staticgenerator.StaticGenerator import publish_from_path [as 别名]
def test_publish_from_path_serves_stale_file_temporarily(self):
instance = StaticGenerator()
os.makedirs('test_web_root/stale')
open('test_web_root/stale/some_path', 'w').write('stale content')
def handler(_request):
"""A mock request handler
At the time of the request, the current content should be hard
linked to the stale version.
"""
current_content = open('test_web_root/fresh/some_path').read()
return Mock(content=('this content replaces {0!r}'
.format(current_content)),
status_code=200)
with patch.object(staticgenerator, 'DummyHandler') as DummyHandler:
DummyHandler.return_value = handler
instance.publish_from_path('/some_path')
self.assertEqual("this content replaces 'stale content'",
open('test_web_root/fresh/some_path').read())