本文整理汇总了Python中staticgenerator.StaticGenerator类的典型用法代码示例。如果您正苦于以下问题:Python StaticGenerator类的具体用法?Python StaticGenerator怎么用?Python StaticGenerator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了StaticGenerator类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_delete_from_path
def test_delete_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").AndReturn("test_web_root/some_path")
fs_mock.dirname("test_web_root/some_path").AndReturn("test_web_root")
fs_mock.exists("test_web_root/some_path").AndReturn(True)
fs_mock.remove("test_web_root/some_path")
fs_mock.rmdir("test_web_root")
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.delete_from_path("some_path")
mox.VerifyAll()
开发者ID:Mondego,项目名称:pyreco,代码行数:27,代码来源:allPythonContent.py
示例2: test_delete_ignores_folder_delete_when_unable_to_delete_folder
def test_delete_ignores_folder_delete_when_unable_to_delete_folder():
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/some_path").AndReturn(True)
fs_mock.remove("test_web_root/some_path")
fs_mock.rmdir("test_web_root").AndRaise(OSError())
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.delete_from_path("some_path")
assert True, "Should work even when raising OSError"
开发者ID:mredar,项目名称:django-staticgenerator,代码行数:28,代码来源:test_staticgenerator.py
示例3: test_delete_loops_through_all_resources
def test_delete_loops_through_all_resources():
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/some_path").AndReturn(True)
fs_mock.remove("test_web_root/some_path")
fs_mock.rmdir("test_web_root")
fs_mock.join('test_web_root', 'some_path_2/index.html').AndReturn("test_web_root/some_path_2")
fs_mock.dirname('test_web_root/some_path_2').AndReturn("test_web_root")
fs_mock.exists("test_web_root/some_path_2").AndReturn(True)
fs_mock.remove("test_web_root/some_path_2")
fs_mock.rmdir("test_web_root")
settings = CustomSettings(WEB_ROOT="test_web_root")
mox.ReplayAll()
instance = StaticGenerator("some_path", "some_path_2",
http_request=http_request,
model_base=model_base,
manager=manager,
model=model,
queryset=queryset,
settings=settings,
fs=fs_mock)
instance.delete()
mox.VerifyAll()
开发者ID:mredar,项目名称:django-staticgenerator,代码行数:33,代码来源:test_staticgenerator.py
示例4: test_publish_from_path_hard_links_stale_file
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)
开发者ID:2general,项目名称:staticgenerator,代码行数:7,代码来源:test_staticgenerator.py
示例5: test_delete_raises_when_unable_to_delete_file
def test_delete_raises_when_unable_to_delete_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/some_path").AndReturn(True)
fs_mock.remove("test_web_root/some_path").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.delete_from_path("some_path")
except StaticGeneratorException, e:
assert str(e) == 'Could not delete file: test_web_root/some_path'
mox.VerifyAll()
return
开发者ID:mredar,项目名称:django-staticgenerator,代码行数:29,代码来源:test_staticgenerator.py
示例6: test_publish_from_path_creates_current_file
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())
开发者ID:2general,项目名称:staticgenerator,代码行数:7,代码来源:test_staticgenerator.py
示例7: test_publish_from_path
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()
开发者ID:mredar,项目名称:django-staticgenerator,代码行数:32,代码来源:test_staticgenerator.py
示例8: test_publish_raises_when_unable_to_create_folder
def test_publish_raises_when_unable_to_create_folder():
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/index.html")
fs_mock.dirname("test_web_root/some_path/index.html").AndReturn("test_web_root")
fs_mock.exists("test_web_root").AndReturn(False)
fs_mock.makedirs("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 directory: test_web_root'
mox.VerifyAll()
return
开发者ID:mredar,项目名称:django-staticgenerator,代码行数:29,代码来源:test_staticgenerator.py
示例9: test_get_filename_from_path_when_path_ends_with_slash
def test_get_filename_from_path_when_path_ends_with_slash():
mox = Mox()
http_request, model_base, manager, model, queryset = get_mocks(mox)
settings = CustomSettings(WEB_ROOT="test_web_root")
fs_mock = mox.CreateMockAnything()
fs_mock.join("test_web_root", "foo/bar/index.html").AndReturn("test_web_root/foo/bar/index.html")
fs_mock.dirname("test_web_root/foo/bar/index.html").AndReturn("test_web_root/foo/bar")
path_mock = '/foo/bar/'
mox.ReplayAll()
instance = StaticGenerator(http_request=http_request,
model_base=model_base,
manager=manager,
model=model,
queryset=queryset,
settings=settings,
fs=fs_mock)
result = instance.get_filename_from_path(path_mock)
assert result == ('test_web_root/foo/bar/index.html', 'test_web_root/foo/bar')
mox.VerifyAll()
开发者ID:mredar,项目名称:django-staticgenerator,代码行数:25,代码来源:test_staticgenerator.py
示例10: test_publish_fails_silently_when_unable_to_rename_temp_file
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'))
开发者ID:2general,项目名称:staticgenerator,代码行数:8,代码来源:test_staticgenerator.py
示例11: process_response
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
开发者ID:zerok,项目名称:django-de,代码行数:8,代码来源:middleware.py
示例12: test_get_content_from_path
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)
开发者ID:2general,项目名称:staticgenerator,代码行数:9,代码来源:test_staticgenerator.py
示例13: test_delete_from_path_deletes_current_file
def test_delete_from_path_deletes_current_file(self):
instance = StaticGenerator()
remove = Mock()
with nested(patch('os.path.exists', Mock(return_value=True)),
patch('os.remove', remove)):
instance.delete_from_path('/some_path')
remove.assert_called_once_with('test_web_root/fresh/some_path')
开发者ID:2general,项目名称:staticgenerator,代码行数:9,代码来源:test_staticgenerator.py
示例14: test_delete_from_path_does_not_delete_stale_file
def test_delete_from_path_does_not_delete_stale_file(self):
instance = StaticGenerator()
remove = Mock()
with nested(patch('os.path.exists', Mock(return_value=True)),
patch('os.remove', remove)):
instance.delete_from_path('/some_path')
self.assertNotIn(call('test_web_root/stale/some_path'),
remove.call_args_list)
开发者ID:2general,项目名称:staticgenerator,代码行数:10,代码来源:test_staticgenerator.py
示例15: test_delete_ignores_folder_delete_when_unable_to_delete_folder
def test_delete_ignores_folder_delete_when_unable_to_delete_folder(self):
instance = StaticGenerator()
rmdir = Mock(side_effect=OSError)
with nested(patch('os.path.exists', Mock(return_value=True)),
patch('os.remove'),
patch('os.rmdir', rmdir)):
instance.delete_from_path('/some_path')
rmdir.assert_called_once_with('test_web_root/fresh')
开发者ID:2general,项目名称:staticgenerator,代码行数:10,代码来源:test_staticgenerator.py
示例16: test_delete_loops_through_all_resources
def test_delete_loops_through_all_resources(self):
instance = StaticGenerator('/some_path', '/some_path_2')
remove = Mock()
with nested(patch('os.path.exists', Mock(return_value=True)),
patch('os.remove', remove)):
instance.delete()
remove.assert_has_calls([call('test_web_root/fresh/some_path'),
call('test_web_root/fresh/some_path_2')])
开发者ID:2general,项目名称:staticgenerator,代码行数:10,代码来源:test_staticgenerator.py
示例17: test_publish_raises_when_unable_to_hard_link_stale_file
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)
开发者ID:2general,项目名称:staticgenerator,代码行数:12,代码来源:test_staticgenerator.py
示例18: test_publish_raises_when_unable_to_create_temp_file
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)
开发者ID:2general,项目名称:staticgenerator,代码行数:12,代码来源:test_staticgenerator.py
示例19: test_publish_loops_through_all_resources
def test_publish_loops_through_all_resources(self):
instance = StaticGenerator('/some_path_1', '/some_path_2')
rename = Mock(wraps=os.rename)
with nested(patch('os.rename', rename),
patch.object(instance, 'get_content_from_path',
Mock(return_value='some_content'))):
instance.publish()
rename.assert_has_calls([
call(ANY, 'test_web_root/fresh/some_path_1'),
call(ANY, 'test_web_root/fresh/some_path_2')])
开发者ID:2general,项目名称:staticgenerator,代码行数:12,代码来源:test_staticgenerator.py
示例20: test_get_lang_aware_filename_from_path_when_path_ends_with_slash
def test_get_lang_aware_filename_from_path_when_path_ends_with_slash(self):
for lang in ('uk', 'ru'):
# activate first non-default language
if lang != settings.LANGUAGE_CODE:
activate('ru')
instance = StaticGenerator()
result = instance.get_filename_from_path('/foo/bar/', '')
self.assertEqual('test_web_root/foo/bar/{}.index.html%3F'.format(lang),
result)
开发者ID:mikek,项目名称:staticgenerator,代码行数:12,代码来源:test_staticgenerator.py
注:本文中的staticgenerator.StaticGenerator类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论