incorporeal-cms/tests/test_factory.py

57 lines
2.1 KiB
Python

"""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
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
def test_extra_markdown_extensions_work():
"""Test we can load more extensions via config, and that they work."""
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
assert b'word --- word' in response.data
app = create_app(instance_path=os.path.join(HERE, 'instance'),
test_config={'MARKDOWN_EXTENSIONS': ['smarty']})
client = app.test_client()
response = client.get('/mdash-or-triple-dash')
assert response.status_code == 200
assert b'word &mdash; word' in response.data
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
assert b'<title>suou.net</title>' in response.data
def test_media_file_access(client):
"""Test that media files are served, and properly."""
response = client.get('/media/favicon.png')
assert response.status_code == 200
assert response.headers['content-type'] == 'image/png'