def _get_location_response(source_name, content_item): from piecrust.app import PieCrust pcapp = PieCrust(g.site.root_dir) source = pcapp.getSource(source_name) page = Page(source, content_item) uri = page.getUri() logger.debug("Redirecting to: %s" % uri) r = Response() r.status_code = 201 r.headers.add('Location', uri) return r
def test_default_source_resolve_ref(ref_path, expected_path, expected_metadata): fs = mock_fs() fs.withConfig({ 'site': { 'sources': { 'test': {}}, 'routes': [ {'url': '/%path%', 'source': 'test'}] } }) expected_path = fs.path(expected_path).replace('/', os.sep) with mock_fs_scope(fs): app = PieCrust(fs.path('kitchen'), cache=False) s = app.getSource('test') actual_path, actual_metadata = s.resolveRef(ref_path) assert actual_path == expected_path assert actual_metadata == expected_metadata
def test_default_source_factories(fs, expected_paths, expected_slugs): fs.withConfig({ 'site': { 'sources': { 'test': {}}, 'routes': [ {'url': '/%path%', 'source': 'test'}] } }) fs.withDir('kitchen/test') with mock_fs_scope(fs): app = PieCrust(fs.path('kitchen'), cache=False) s = app.getSource('test') facs = list(s.buildPageFactories()) paths = [f.rel_path for f in facs] assert paths == expected_paths slugs = [f.metadata['slug'] for f in facs] assert slugs == expected_slugs
def test_default_source_resolve_ref(ref_path, expected_path, expected_metadata): fs = mock_fs() fs.withConfig({ 'site': { 'sources': { 'test': {} }, 'routes': [{ 'url': '/%path%', 'source': 'test' }] } }) expected_path = fs.path(expected_path).replace('/', os.sep) with mock_fs_scope(fs): app = PieCrust(fs.path('kitchen'), cache=False) s = app.getSource('test') actual_path, actual_metadata = s.resolveRef(ref_path) assert actual_path == expected_path assert actual_metadata == expected_metadata
def test_default_source_factories(fs, expected_paths, expected_slugs): fs.withConfig({ 'site': { 'sources': { 'test': {} }, 'routes': [{ 'url': '/%path%', 'source': 'test' }] } }) fs.withDir('kitchen/test') with mock_fs_scope(fs): app = PieCrust(fs.path('kitchen'), cache=False) s = app.getSource('test') facs = list(s.buildPageFactories()) paths = [f.rel_path for f in facs] assert paths == expected_paths slugs = [f.metadata['slug'] for f in facs] assert slugs == expected_slugs