2020-03-07 19:37:02 -06:00
|
|
|
"""Test basic configuration stuff."""
|
|
|
|
import os
|
|
|
|
|
|
|
|
from incorporealcms import create_app
|
|
|
|
|
|
|
|
HERE = os.path.dirname(os.path.abspath(__file__))
|
|
|
|
|
|
|
|
|
|
|
|
def test_config():
|
|
|
|
"""Test create_app without passing test config."""
|
|
|
|
instance_path = os.path.join(HERE, 'instance')
|
|
|
|
assert not create_app(instance_path=instance_path).testing
|
|
|
|
assert create_app(instance_path=instance_path, test_config={"TESTING": True}).testing
|
2020-03-07 19:43:24 -06:00
|
|
|
|
|
|
|
|
2020-10-29 23:43:00 -05:00
|
|
|
def test_markdown_meta_extension_always():
|
|
|
|
"""Test that the markdown meta extension is always loaded, even if not specified."""
|
|
|
|
app = create_app(instance_path=os.path.join(HERE, 'instance'),
|
|
|
|
test_config={'MARKDOWN_EXTENSIONS': []})
|
|
|
|
client = app.test_client()
|
|
|
|
response = client.get('/')
|
|
|
|
assert response.status_code == 200
|
|
|
|
assert b'<title>Index - incorporeal.org</title>' in response.data
|
|
|
|
|
|
|
|
|
2021-02-11 19:00:36 -06:00
|
|
|
def test_custom_markdown_extensions_work():
|
|
|
|
"""Test we can change extensions via config, and that they work.
|
|
|
|
|
|
|
|
This used to test smarty, but that's added by default now, so we test
|
|
|
|
that it can be removed by overriding the option.
|
|
|
|
"""
|
2020-10-29 23:43:00 -05:00
|
|
|
app = create_app(instance_path=os.path.join(HERE, 'instance'))
|
|
|
|
client = app.test_client()
|
|
|
|
response = client.get('/mdash-or-triple-dash')
|
|
|
|
assert response.status_code == 200
|
2021-02-11 19:00:36 -06:00
|
|
|
assert b'word — word' in response.data
|
2020-10-29 23:43:00 -05:00
|
|
|
|
|
|
|
app = create_app(instance_path=os.path.join(HERE, 'instance'),
|
2021-02-11 19:00:36 -06:00
|
|
|
test_config={'MARKDOWN_EXTENSIONS': []})
|
2020-10-29 23:43:00 -05:00
|
|
|
client = app.test_client()
|
|
|
|
response = client.get('/mdash-or-triple-dash')
|
|
|
|
assert response.status_code == 200
|
2021-02-11 19:00:36 -06:00
|
|
|
assert b'word --- word' in response.data
|
2020-10-29 23:43:00 -05:00
|
|
|
|
|
|
|
|
2020-03-07 19:43:24 -06:00
|
|
|
def test_title_override():
|
|
|
|
"""Test that a configuration with a specific title overrides the default."""
|
|
|
|
instance_path = os.path.join(HERE, 'instance')
|
|
|
|
app = create_app(instance_path=instance_path, test_config={'TITLE_SUFFIX': 'suou.net'})
|
|
|
|
client = app.test_client()
|
|
|
|
response = client.get('/no-title')
|
|
|
|
assert response.status_code == 200
|
2021-02-20 22:43:42 -06:00
|
|
|
assert b'<title>/no-title - suou.net</title>' in response.data
|
2020-03-08 11:48:49 -05:00
|
|
|
|
|
|
|
|
|
|
|
def test_media_file_access(client):
|
2020-06-17 20:18:43 -05:00
|
|
|
"""Test that media files are served, and properly."""
|
2020-03-08 11:48:49 -05:00
|
|
|
response = client.get('/media/favicon.png')
|
|
|
|
assert response.status_code == 200
|
|
|
|
assert response.headers['content-type'] == 'image/png'
|
2021-02-27 00:10:03 -06:00
|
|
|
|
|
|
|
|
|
|
|
def test_favicon_override():
|
|
|
|
"""Test that a configuration with a specific favicon overrides the default."""
|
|
|
|
instance_path = os.path.join(HERE, 'instance')
|
|
|
|
app = create_app(instance_path=instance_path, test_config={'FAVICON': '/media/foo.png'})
|
|
|
|
client = app.test_client()
|
|
|
|
response = client.get('/no-title')
|
|
|
|
assert response.status_code == 200
|
|
|
|
assert b'<link rel="icon" href="/media/foo.png">' in response.data
|
2021-06-24 09:43:00 -05:00
|
|
|
|
|
|
|
|
|
|
|
def test_misconfigured_markdown_extensions():
|
|
|
|
"""Test that a misconfigured markdown extensions leads to a 500 at render time."""
|
|
|
|
instance_path = os.path.join(HERE, 'instance')
|
|
|
|
app = create_app(instance_path=instance_path, test_config={'MARKDOWN_EXTENSIONS': 'WRONG'})
|
|
|
|
client = app.test_client()
|
|
|
|
response = client.get('/no-title')
|
|
|
|
assert response.status_code == 500
|