-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
test_app.py
82 lines (65 loc) · 2.42 KB
/
test_app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
""" Smoke test site runner """
# pylint:disable=invalid-name
import logging
import os
try:
import authl.flask
except ImportError:
authl = None
try:
import whoosh
except ImportError:
whoosh = None
import flask
import publ
import publ.image
APP_PATH = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'tests')
logging.basicConfig(level=logging.DEBUG if 'FLASK_DEBUG' in os.environ else logging.WARNING)
config = {
'database_config': {
'provider': 'sqlite',
'filename': os.path.join(APP_PATH, '..', 'index.db')
},
'content_folder': os.path.join(APP_PATH, 'content'),
'template_folder': os.path.join(APP_PATH, 'templates'),
'static_folder': os.path.join(APP_PATH, 'static'),
'cache': {
'CACHE_TYPE': os.environ['TEST_CACHING'],
'CACHE_DEFAULT_TIMEOUT': 600,
'CACHE_THRESHOLD': 20
} if os.environ.get('TEST_CACHING') else {
'CACHE_TYPE': 'NullCache',
'CACHE_NO_NULL_WARNING': True,
'CACHE_DEFAULT_TIMEOUT': 720
},
'auth': {
'TEST_ENABLED': True,
'INDIEAUTH_CLIENT_ID': authl.flask.client_id if authl else None,
'FEDIVERSE_NAME': 'Publ test suite',
'TWITTER_CLIENT_KEY': os.environ.get('TWITTER_CLIENT_KEY'),
'TWITTER_CLIENT_SECRET': os.environ.get('TWITTER_CLIENT_SECRET'),
'EMAIL_SENDMAIL': lambda message: print(message.get_payload(decode=True).decode('utf-8')),
'EMAIL_FROM': '[email protected]',
'EMAIL_SUBJECT': 'Log in to authl test',
'EMAIL_CHECK_MESSAGE': 'Use the link printed to the test console',
} if authl else {},
'user_list': os.path.join(APP_PATH, 'users.cfg'),
'layout': {
'max_width': 768,
},
'search_index': '_index' if whoosh else None,
'index_enable_watchdog': True,
'secret_key': "We are insecure",
}
app = publ.Publ(__name__, config)
@app.route('/favicon.<ext>')
def favicon(ext):
""" render a favicon """
logo = publ.image.get_image('images/rawr.jpg', 'tests/content')
img, _ = logo.get_rendition(format=ext, width=128, height=128, resize='fill')
return flask.redirect(img), {'Cache-Control': 'public, max-age=86400'}
@app.path_alias_regex(r'(.*)/date/([0-9]+)')
def date_view(match):
""" Simple test of regex path aliases, maps e.g. /foo/date/2020 to /foo/?date=2020 """
return flask.url_for('category', category=match.group(1),
date=match.group(2)), True