def test_sitemap_generation(self): """Generated sitemap should match pages in the filesystem.""" sitemap = SiteMapView.generate_sitemap() # pylint: disable=C0301 # pylint: disable=E501 self.assertEqual(sitemap, '''<?xml version="1.0" encoding="utf-8"?> <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd"> <url> <loc>http://localhost/</loc> <lastmod>2015-06-26T11:21:15+0000</lastmod> <changefreq>daily</changefreq> <priority>0.9</priority> </url><url> <loc>http://localhost/about</loc> <lastmod>2015-06-26T12:21:15+0000</lastmod> </url><url> <loc>http://localhost/contact</loc> <lastmod>2015-06-26T13:22:15+0000</lastmod> </url><url> <loc>http://localhost/contact/eastcoast</loc> <lastmod>2015-06-26T15:24:15+0000</lastmod> </url><url> <loc>http://localhost/contact/westcoast</loc> <lastmod>2015-06-26T14:23:15+0000</lastmod> </url><url> <loc>http://localhost/order/digitalprints</loc> <lastmod>2015-06-26T20:28:15+0000</lastmod> </url><url> <loc>http://localhost/order/framed</loc> <lastmod>2015-06-26T21:28:15+0000</lastmod> </url><url> <loc>http://localhost/work/portfolio</loc> <lastmod>2015-06-26T16:25:15+0000</lastmod> </url><url> <loc>http://localhost/work/portfolio/landscapes</loc> <lastmod>2015-06-26T17:26:15+0000</lastmod> </url><url> <loc>http://localhost/work/portfolio/nature</loc> <lastmod>2015-06-26T19:28:15+0000</lastmod> </url><url> <loc>http://localhost/work/portfolio/portraits</loc> <lastmod>2015-06-26T18:27:15+0000</lastmod> </url> </urlset>''')
def _stage_create_app(self): """Create the Flask application.""" # Setup special root-level asset routes # NOTE: The usage of url_for doesn't work here. Rather, use a view with # send_from_directory() - http://stackoverflow.com/a/20648053/1436323 def special_root_file(filename): """Root file Flask view.""" return send_file(os.path.join(self.config['CONTENT_PATH'], filename)) for asset in self.ROOT_LEVEL_ASSETS: self.add_url_rule('/%s' % asset, view_func=special_root_file, defaults={'filename': asset}) # Setup content asset route def custom_static(filename): """Custom static file Flask view.""" return send_from_directory(self.config['CONTENT_ASSET_PATH'], filename) self.add_url_rule('/contentassets/<path:filename>', view_func=custom_static) # Sitemap route self.add_url_rule('/sitemap.xml', view_func=SiteMapView.as_view('sitemap')) # Route all remaining requests to the index view self.add_url_rule('/', view_func=Index.as_view('index'), defaults={'path': ''}) self.add_url_rule('/<path:path>', view_func=Index.as_view('index_with_path')) # Setup error handler pages self.error_handler_spec[None][404] = self.error_page_not_found # Setup logging log_level = getattr(logging, self.site_options['logging_level']) logging.basicConfig(level=log_level, format='%(asctime)s - %(message)s', datefmt='%Y-%m-%d %H:%M:%S')