"""Test page views and helper methods.""" import re from incorporealcms.pages import generate_parent_navs, resolve_page_file def test_resolve_page_file_dir_to_index(): assert resolve_page_file('foo/') == 'pages/foo/index.md' def test_resolve_page_file_subdir_to_index(): assert resolve_page_file('foo/bar/') == 'pages/foo/bar/index.md' def test_resolve_page_file_other_requests_fine(): assert resolve_page_file('foo/baz') == 'pages/foo/baz.md' def test_page_that_exists(client): response = client.get('/') assert response.status_code == 200 assert b'

test index

' in response.data def test_page_that_doesnt_exist(client): response = client.get('/ohuesthaoeusth') assert response.status_code == 404 def test_page_with_title_metadata(client): response = client.get('/') assert response.status_code == 200 assert b'Index - incorporeal.org' in response.data def test_page_without_title_metadata(client): response = client.get('/no-title') assert response.status_code == 200 assert b'incorporeal.org' in response.data assert b'

this page doesn\'t have a title!

' in response.data def test_page_has_modified_timestamp(client): response = client.get('/') assert response.status_code == 200 assert re.search(r'Last modified: ....-..-.. ..:..:.. ...', response.data.decode()) is not None def test_generate_page_navs_index(app): with app.app_context(): assert generate_parent_navs('/') == [('incorporeal.org', '/')] def test_generate_page_navs_alternate_index(app): with app.app_context(): assert generate_parent_navs('index') == [('incorporeal.org', '/')] def test_generate_page_navs_subdir_index(app): with app.app_context(): assert generate_parent_navs('subdir/') == [('incorporeal.org', '/'), ('/subdir/', '/subdir/')] def test_generate_page_navs_subdir_real_page(app): with app.app_context(): assert generate_parent_navs('subdir/page') == [('incorporeal.org', '/'), ('/subdir/', '/subdir/'), ('Page', '/subdir/page')] def test_generate_page_navs_subdir_with_title_parsing_real_page(app): with app.app_context(): assert generate_parent_navs('subdir-with-title/page') == [ ('incorporeal.org', '/'), ('SUB!', '/subdir-with-title/'), ('/subdir-with-title/page', '/subdir-with-title/page') ]