appier 1.34.6__py2.py3-none-any.whl → 1.34.8__py2.py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- appier/__init__.py +1 -1
- appier/api.py +10 -0
- appier/asgi.py +10 -0
- appier/async_neo.py +2 -2
- appier/async_old.py +1 -1
- appier/base.py +15 -2
- appier/bus.py +10 -0
- appier/config.py +409 -401
- appier/data.py +2 -0
- appier/exceptions.py +450 -442
- appier/http.py +1292 -1283
- appier/model.py +7 -2
- appier/mongo.py +24 -0
- appier/scheduler.py +342 -334
- appier/test/data.py +10 -0
- appier/test/error_handler.py +142 -0
- appier/test/exception_handler.py +146 -0
- appier/test/http.py +24 -0
- appier/test/tags.py +109 -0
- appier/util.py +2517 -2503
- {appier-1.34.6.dist-info → appier-1.34.8.dist-info}/METADATA +1 -1
- {appier-1.34.6.dist-info → appier-1.34.8.dist-info}/RECORD +25 -22
- {appier-1.34.6.dist-info → appier-1.34.8.dist-info}/LICENSE +0 -0
- {appier-1.34.6.dist-info → appier-1.34.8.dist-info}/WHEEL +0 -0
- {appier-1.34.6.dist-info → appier-1.34.8.dist-info}/top_level.txt +0 -0
appier/test/data.py
CHANGED
|
@@ -28,6 +28,8 @@ __copyright__ = "Copyright (c) 2008-2024 Hive Solutions Lda."
|
|
|
28
28
|
__license__ = "Apache License, Version 2.0"
|
|
29
29
|
""" The license for the module """
|
|
30
30
|
|
|
31
|
+
import os
|
|
32
|
+
import tempfile
|
|
31
33
|
import unittest
|
|
32
34
|
|
|
33
35
|
import appier
|
|
@@ -40,3 +42,11 @@ class DataTest(unittest.TestCase):
|
|
|
40
42
|
|
|
41
43
|
self.assertEqual(type(identifier), str)
|
|
42
44
|
self.assertEqual(len(identifier), 24)
|
|
45
|
+
|
|
46
|
+
def test_drop_db_missing(self):
|
|
47
|
+
fd, file_path = tempfile.mkstemp()
|
|
48
|
+
os.close(fd)
|
|
49
|
+
adapter = appier.TinyAdapter(file_path=file_path)
|
|
50
|
+
adapter.get_db()
|
|
51
|
+
os.remove(file_path)
|
|
52
|
+
adapter.drop_db()
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
#!/usr/bin/python
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
|
|
4
|
+
# Hive Appier Framework
|
|
5
|
+
# Copyright (c) 2008-2024 Hive Solutions Lda.
|
|
6
|
+
#
|
|
7
|
+
# This file is part of Hive Appier Framework.
|
|
8
|
+
#
|
|
9
|
+
# Hive Appier Framework is free software: you can redistribute it and/or modify
|
|
10
|
+
# it under the terms of the Apache License as published by the Apache
|
|
11
|
+
# Foundation, either version 2.0 of the License, or (at your option) any
|
|
12
|
+
# later version.
|
|
13
|
+
#
|
|
14
|
+
# Hive Appier Framework is distributed in the hope that it will be useful,
|
|
15
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
16
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
17
|
+
# Apache License for more details.
|
|
18
|
+
#
|
|
19
|
+
# You should have received a copy of the Apache License along with
|
|
20
|
+
# Hive Appier Framework. If not, see <http://www.apache.org/licenses/>.
|
|
21
|
+
|
|
22
|
+
__author__ = "João Magalhães <joamag@hive.pt>"
|
|
23
|
+
""" The author(s) of the module """
|
|
24
|
+
|
|
25
|
+
__copyright__ = "Copyright (c) 2008-2024 Hive Solutions Lda."
|
|
26
|
+
""" The copyright for the module """
|
|
27
|
+
|
|
28
|
+
__license__ = "Apache License, Version 2.0"
|
|
29
|
+
""" The license for the module """
|
|
30
|
+
|
|
31
|
+
import unittest
|
|
32
|
+
|
|
33
|
+
import appier
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
class ErrorHandlerTest(unittest.TestCase):
|
|
37
|
+
def setUp(self):
|
|
38
|
+
self._original_handlers = appier.common.base().App._ERROR_HANDLERS
|
|
39
|
+
appier.common.base().App._ERROR_HANDLERS = {}
|
|
40
|
+
self.app = appier.App()
|
|
41
|
+
|
|
42
|
+
def tearDown(self):
|
|
43
|
+
self.app.unload()
|
|
44
|
+
appier.common.base().App._ERROR_HANDLERS = self._original_handlers
|
|
45
|
+
|
|
46
|
+
def test_basic_registration_and_call(self):
|
|
47
|
+
"""
|
|
48
|
+
Decorator should register the handler and it must be invoked by
|
|
49
|
+
:pyfunc:`appier.App.call_error` when an exception matching the provided
|
|
50
|
+
error code is raised.
|
|
51
|
+
|
|
52
|
+
The error handler is a JSON handler by default, to be able to properly
|
|
53
|
+
handle errors in an App.
|
|
54
|
+
"""
|
|
55
|
+
|
|
56
|
+
@appier.error_handler(404, json=True)
|
|
57
|
+
def not_found(_):
|
|
58
|
+
return "resource not found"
|
|
59
|
+
|
|
60
|
+
exc = appier.exceptions.NotFoundError("dummy")
|
|
61
|
+
result = self.app.call_error(exc, code=exc.code, scope=None, json=True)
|
|
62
|
+
self.assertEqual(result, "resource not found")
|
|
63
|
+
|
|
64
|
+
handlers = appier.common.base().App._ERROR_HANDLERS.get(404)
|
|
65
|
+
self.assertNotEqual(handlers, None)
|
|
66
|
+
self.assertEqual(len(handlers), 1)
|
|
67
|
+
|
|
68
|
+
method, scope, json, opts, ctx, priority = handlers[0]
|
|
69
|
+
self.assertEqual(method, not_found)
|
|
70
|
+
self.assertEqual(scope, None)
|
|
71
|
+
self.assertEqual(json, True)
|
|
72
|
+
self.assertEqual(opts, None)
|
|
73
|
+
self.assertEqual(ctx, None)
|
|
74
|
+
self.assertEqual(priority, 1)
|
|
75
|
+
|
|
76
|
+
def test_web_handler(self):
|
|
77
|
+
"""
|
|
78
|
+
Test that in which the error handler is a web handler by default, to be
|
|
79
|
+
able to properly handle errors in an WebApp, because this is a App no
|
|
80
|
+
handler is called.
|
|
81
|
+
"""
|
|
82
|
+
|
|
83
|
+
@appier.error_handler(404, json=False)
|
|
84
|
+
def not_found(_):
|
|
85
|
+
return "resource not found"
|
|
86
|
+
|
|
87
|
+
exc = appier.exceptions.NotFoundError("dummy")
|
|
88
|
+
result = self.app.call_error(exc, code=exc.code, scope=None, json=True)
|
|
89
|
+
self.assertEqual(result, None)
|
|
90
|
+
|
|
91
|
+
handlers = appier.common.base().App._ERROR_HANDLERS.get(404)
|
|
92
|
+
self.assertNotEqual(handlers, None)
|
|
93
|
+
self.assertEqual(len(handlers), 1)
|
|
94
|
+
|
|
95
|
+
method, scope, json, opts, ctx, priority = handlers[0]
|
|
96
|
+
self.assertEqual(method, not_found)
|
|
97
|
+
self.assertEqual(scope, None)
|
|
98
|
+
self.assertEqual(json, False)
|
|
99
|
+
self.assertEqual(opts, None)
|
|
100
|
+
self.assertEqual(ctx, None)
|
|
101
|
+
self.assertEqual(priority, 1)
|
|
102
|
+
|
|
103
|
+
def test_scope_registration(self):
|
|
104
|
+
"""
|
|
105
|
+
When a *scope* argument is provided, it should be stored in the handler
|
|
106
|
+
metadata so that the framework can later match it appropriately.
|
|
107
|
+
|
|
108
|
+
The error handler is a JSON handler by default, to be able to properly
|
|
109
|
+
handle errors in an App.
|
|
110
|
+
"""
|
|
111
|
+
|
|
112
|
+
class DummyScope:
|
|
113
|
+
pass
|
|
114
|
+
|
|
115
|
+
class DummyException(Exception):
|
|
116
|
+
code = 400
|
|
117
|
+
|
|
118
|
+
@appier.error_handler(400, scope=DummyScope)
|
|
119
|
+
def bad_request(_):
|
|
120
|
+
return "bad request"
|
|
121
|
+
|
|
122
|
+
exc = DummyException("dummy")
|
|
123
|
+
result = self.app.call_error(exc, code=exc.code, scope=DummyScope, json=True)
|
|
124
|
+
self.assertEqual(result, "bad request")
|
|
125
|
+
|
|
126
|
+
result = None
|
|
127
|
+
exc = DummyException("dummy")
|
|
128
|
+
result = self.app.call_error(exc, code=exc.code, json=True)
|
|
129
|
+
self.assertEqual(result, None)
|
|
130
|
+
|
|
131
|
+
handlers = appier.common.base().App._ERROR_HANDLERS.get(400)
|
|
132
|
+
self.assertNotEqual(handlers, None)
|
|
133
|
+
self.assertEqual(len(handlers), 1)
|
|
134
|
+
|
|
135
|
+
method, scope, json, opts, ctx, priority = handlers[0]
|
|
136
|
+
|
|
137
|
+
self.assertEqual(method, bad_request)
|
|
138
|
+
self.assertEqual(scope, DummyScope)
|
|
139
|
+
self.assertEqual(json, None)
|
|
140
|
+
self.assertEqual(opts, None)
|
|
141
|
+
self.assertEqual(ctx, None)
|
|
142
|
+
self.assertEqual(priority, 1)
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
#!/usr/bin/python
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
|
|
4
|
+
# Hive Appier Framework
|
|
5
|
+
# Copyright (c) 2008-2024 Hive Solutions Lda.
|
|
6
|
+
#
|
|
7
|
+
# This file is part of Hive Appier Framework.
|
|
8
|
+
#
|
|
9
|
+
# Hive Appier Framework is free software: you can redistribute it and/or modify
|
|
10
|
+
# it under the terms of the Apache License as published by the Apache
|
|
11
|
+
# Foundation, either version 2.0 of the License, or (at your option) any
|
|
12
|
+
# later version.
|
|
13
|
+
#
|
|
14
|
+
# Hive Appier Framework is distributed in the hope that it will be useful,
|
|
15
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
16
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
17
|
+
# Apache License for more details.
|
|
18
|
+
#
|
|
19
|
+
# You should have received a copy of the Apache License along with
|
|
20
|
+
# Hive Appier Framework. If not, see <http://www.apache.org/licenses/>.
|
|
21
|
+
|
|
22
|
+
__author__ = "João Magalhães <joamag@hive.pt>"
|
|
23
|
+
""" The author(s) of the module """
|
|
24
|
+
|
|
25
|
+
__copyright__ = "Copyright (c) 2008-2024 Hive Solutions Lda."
|
|
26
|
+
""" The copyright for the module """
|
|
27
|
+
|
|
28
|
+
__license__ = "Apache License, Version 2.0"
|
|
29
|
+
""" The license for the module """
|
|
30
|
+
|
|
31
|
+
import unittest
|
|
32
|
+
|
|
33
|
+
import appier
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
class ExceptionHandlerTest(unittest.TestCase):
|
|
37
|
+
def setUp(self):
|
|
38
|
+
self._original_handlers = appier.common.base().App._ERROR_HANDLERS
|
|
39
|
+
appier.common.base().App._ERROR_HANDLERS = {}
|
|
40
|
+
self.app = appier.App()
|
|
41
|
+
|
|
42
|
+
def tearDown(self):
|
|
43
|
+
self.app.unload()
|
|
44
|
+
appier.common.base().App._ERROR_HANDLERS = self._original_handlers
|
|
45
|
+
|
|
46
|
+
def test_basic_registration_and_call(self):
|
|
47
|
+
"""
|
|
48
|
+
Decorator should register the handler and it must be invoked by
|
|
49
|
+
:pyfunc:`appier.App.call_error` when an exception matching the provided
|
|
50
|
+
type is raised.
|
|
51
|
+
|
|
52
|
+
The exception handler is a JSON handler by default, to be able to properly
|
|
53
|
+
handle errors in an App.
|
|
54
|
+
"""
|
|
55
|
+
|
|
56
|
+
@appier.exception_handler(appier.exceptions.NotFoundError, json=True)
|
|
57
|
+
def not_found(_):
|
|
58
|
+
return "resource not found"
|
|
59
|
+
|
|
60
|
+
exc = appier.exceptions.NotFoundError("dummy")
|
|
61
|
+
result = self.app.call_error(exc, scope=None, json=True)
|
|
62
|
+
self.assertEqual(result, "resource not found")
|
|
63
|
+
|
|
64
|
+
handlers = appier.common.base().App._ERROR_HANDLERS.get(
|
|
65
|
+
appier.exceptions.NotFoundError
|
|
66
|
+
)
|
|
67
|
+
self.assertNotEqual(handlers, None)
|
|
68
|
+
self.assertEqual(len(handlers), 1)
|
|
69
|
+
|
|
70
|
+
method, scope, json, opts, ctx, priority = handlers[0]
|
|
71
|
+
self.assertEqual(method, not_found)
|
|
72
|
+
self.assertEqual(scope, None)
|
|
73
|
+
self.assertEqual(json, True)
|
|
74
|
+
self.assertEqual(opts, None)
|
|
75
|
+
self.assertEqual(ctx, None)
|
|
76
|
+
self.assertEqual(priority, 1)
|
|
77
|
+
|
|
78
|
+
def test_web_handler(self):
|
|
79
|
+
"""
|
|
80
|
+
Test that in which the exception handler is a web handler by default, to be
|
|
81
|
+
able to properly handle errors in an WebApp, because this is an App no
|
|
82
|
+
handler is called.
|
|
83
|
+
"""
|
|
84
|
+
|
|
85
|
+
@appier.exception_handler(appier.exceptions.NotFoundError, json=False)
|
|
86
|
+
def not_found(_):
|
|
87
|
+
return "resource not found"
|
|
88
|
+
|
|
89
|
+
exc = appier.exceptions.NotFoundError("dummy")
|
|
90
|
+
result = self.app.call_error(exc, scope=None, json=True)
|
|
91
|
+
self.assertEqual(result, None)
|
|
92
|
+
|
|
93
|
+
handlers = appier.common.base().App._ERROR_HANDLERS.get(
|
|
94
|
+
appier.exceptions.NotFoundError
|
|
95
|
+
)
|
|
96
|
+
self.assertNotEqual(handlers, None)
|
|
97
|
+
self.assertEqual(len(handlers), 1)
|
|
98
|
+
|
|
99
|
+
method, scope, json, opts, ctx, priority = handlers[0]
|
|
100
|
+
self.assertEqual(method, not_found)
|
|
101
|
+
self.assertEqual(scope, None)
|
|
102
|
+
self.assertEqual(json, False)
|
|
103
|
+
self.assertEqual(opts, None)
|
|
104
|
+
self.assertEqual(ctx, None)
|
|
105
|
+
self.assertEqual(priority, 1)
|
|
106
|
+
|
|
107
|
+
def test_scope_registration(self):
|
|
108
|
+
"""
|
|
109
|
+
When a *scope* argument is provided, it should be stored in the handler
|
|
110
|
+
metadata so that the framework can later match it appropriately.
|
|
111
|
+
|
|
112
|
+
The exception handler is a JSON handler by default, to be able to properly
|
|
113
|
+
handle errors in an App.
|
|
114
|
+
"""
|
|
115
|
+
|
|
116
|
+
class DummyScope:
|
|
117
|
+
pass
|
|
118
|
+
|
|
119
|
+
class DummyException(Exception):
|
|
120
|
+
code = 400
|
|
121
|
+
|
|
122
|
+
@appier.exception_handler(DummyException, scope=DummyScope)
|
|
123
|
+
def bad_request(_):
|
|
124
|
+
return "bad request"
|
|
125
|
+
|
|
126
|
+
exc = DummyException("dummy")
|
|
127
|
+
result = self.app.call_error(exc, scope=DummyScope, json=True)
|
|
128
|
+
self.assertEqual(result, "bad request")
|
|
129
|
+
|
|
130
|
+
result = None
|
|
131
|
+
exc = DummyException("dummy")
|
|
132
|
+
result = self.app.call_error(exc, json=True)
|
|
133
|
+
self.assertEqual(result, None)
|
|
134
|
+
|
|
135
|
+
handlers = appier.common.base().App._ERROR_HANDLERS.get(DummyException)
|
|
136
|
+
self.assertNotEqual(handlers, None)
|
|
137
|
+
self.assertEqual(len(handlers), 1)
|
|
138
|
+
|
|
139
|
+
method, scope, json, opts, ctx, priority = handlers[0]
|
|
140
|
+
|
|
141
|
+
self.assertEqual(method, bad_request)
|
|
142
|
+
self.assertEqual(scope, DummyScope)
|
|
143
|
+
self.assertEqual(json, None)
|
|
144
|
+
self.assertEqual(opts, None)
|
|
145
|
+
self.assertEqual(ctx, None)
|
|
146
|
+
self.assertEqual(priority, 1)
|
appier/test/http.py
CHANGED
|
@@ -104,6 +104,9 @@ class HTTPTest(unittest.TestCase):
|
|
|
104
104
|
self.assertEqual(params, dict(hello=["world"]))
|
|
105
105
|
|
|
106
106
|
def test_redirect(self):
|
|
107
|
+
if appier.conf("NO_NETWORK", False, cast=bool):
|
|
108
|
+
self.skipTest("Network access is disabled")
|
|
109
|
+
|
|
107
110
|
_data, response = appier.get(
|
|
108
111
|
"https://%s/redirect-to" % self.httpbin,
|
|
109
112
|
params=dict(url="https://%s/" % self.httpbin),
|
|
@@ -135,6 +138,9 @@ class HTTPTest(unittest.TestCase):
|
|
|
135
138
|
self.assertEqual(code, 200)
|
|
136
139
|
|
|
137
140
|
def test_timeout(self):
|
|
141
|
+
if appier.conf("NO_NETWORK", False, cast=bool):
|
|
142
|
+
self.skipTest("Network access is disabled")
|
|
143
|
+
|
|
138
144
|
self.assertRaises(
|
|
139
145
|
BaseException,
|
|
140
146
|
lambda: appier.get(
|
|
@@ -155,6 +161,9 @@ class HTTPTest(unittest.TestCase):
|
|
|
155
161
|
self.assertNotEqual(data, None)
|
|
156
162
|
|
|
157
163
|
def test_get_f(self):
|
|
164
|
+
if appier.conf("NO_NETWORK", False, cast=bool):
|
|
165
|
+
self.skipTest("Network access is disabled")
|
|
166
|
+
|
|
158
167
|
file = appier.get_f("https://%s/image/png" % self.httpbin)
|
|
159
168
|
|
|
160
169
|
self.assertEqual(file.file_name, "default")
|
|
@@ -170,6 +179,9 @@ class HTTPTest(unittest.TestCase):
|
|
|
170
179
|
self.assertEqual(len(file.data_b64) > 100, True)
|
|
171
180
|
|
|
172
181
|
def test_generator(self):
|
|
182
|
+
if appier.conf("NO_NETWORK", False, cast=bool):
|
|
183
|
+
self.skipTest("Network access is disabled")
|
|
184
|
+
|
|
173
185
|
def text_g(message=[b"hello", b" ", b"world"]):
|
|
174
186
|
yield sum(len(value) for value in message)
|
|
175
187
|
for value in message:
|
|
@@ -185,6 +197,9 @@ class HTTPTest(unittest.TestCase):
|
|
|
185
197
|
self.assertEqual(data["data"], "hello world")
|
|
186
198
|
|
|
187
199
|
def test_file(self):
|
|
200
|
+
if appier.conf("NO_NETWORK", False, cast=bool):
|
|
201
|
+
self.skipTest("Network access is disabled")
|
|
202
|
+
|
|
188
203
|
data, response = appier.post(
|
|
189
204
|
"https://%s/post" % self.httpbin,
|
|
190
205
|
data=appier.legacy.BytesIO(b"hello world"),
|
|
@@ -198,6 +213,9 @@ class HTTPTest(unittest.TestCase):
|
|
|
198
213
|
self.assertEqual(data["data"], "hello world")
|
|
199
214
|
|
|
200
215
|
def test_multithread(self):
|
|
216
|
+
if appier.conf("NO_NETWORK", False, cast=bool):
|
|
217
|
+
self.skipTest("Network access is disabled")
|
|
218
|
+
|
|
201
219
|
threads = []
|
|
202
220
|
results = []
|
|
203
221
|
|
|
@@ -230,11 +248,17 @@ class HTTPTest(unittest.TestCase):
|
|
|
230
248
|
self.assertEqual(code, 200)
|
|
231
249
|
|
|
232
250
|
def test_error(self):
|
|
251
|
+
if appier.conf("NO_NETWORK", False, cast=bool):
|
|
252
|
+
self.skipTest("Network access is disabled")
|
|
253
|
+
|
|
233
254
|
self.assertRaises(
|
|
234
255
|
appier.HTTPError, lambda: appier.get("https://%s/status/404" % self.httpbin)
|
|
235
256
|
)
|
|
236
257
|
|
|
237
258
|
def test_invalid(self):
|
|
259
|
+
if appier.conf("NO_NETWORK", False, cast=bool):
|
|
260
|
+
self.skipTest("Network access is disabled")
|
|
261
|
+
|
|
238
262
|
self.assertRaises(
|
|
239
263
|
BaseException, lambda: appier.get("https://invalidlargedomain.org/")
|
|
240
264
|
)
|
appier/test/tags.py
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
#!/usr/bin/python
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
|
|
4
|
+
# Hive Appier Framework
|
|
5
|
+
# Copyright (c) 2008-2024 Hive Solutions Lda.
|
|
6
|
+
#
|
|
7
|
+
# This file is part of Hive Appier Framework.
|
|
8
|
+
#
|
|
9
|
+
# Hive Appier Framework is free software: you can redistribute it and/or modify
|
|
10
|
+
# it under the terms of the Apache License as published by the Apache
|
|
11
|
+
# Foundation, either version 2.0 of the License, or (at your option) any
|
|
12
|
+
# later version.
|
|
13
|
+
#
|
|
14
|
+
# Hive Appier Framework is distributed in the hope that it will be useful,
|
|
15
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
16
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
17
|
+
# Apache License for more details.
|
|
18
|
+
#
|
|
19
|
+
# You should have received a copy of the Apache License along with
|
|
20
|
+
# Hive Appier Framework. If not, see <http://www.apache.org/licenses/>.
|
|
21
|
+
|
|
22
|
+
__author__ = "João Magalhães <joamag@hive.pt>"
|
|
23
|
+
""" The author(s) of the module """
|
|
24
|
+
|
|
25
|
+
__copyright__ = "Copyright (c) 2008-2024 Hive Solutions Lda."
|
|
26
|
+
""" The copyright for the module """
|
|
27
|
+
|
|
28
|
+
__license__ = "Apache License, Version 2.0"
|
|
29
|
+
""" The license for the module """
|
|
30
|
+
|
|
31
|
+
import unittest
|
|
32
|
+
|
|
33
|
+
import appier
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
class TagsTest(unittest.TestCase):
|
|
37
|
+
def setUp(self):
|
|
38
|
+
self.app = appier.App()
|
|
39
|
+
|
|
40
|
+
def tearDown(self):
|
|
41
|
+
self.app.unload()
|
|
42
|
+
|
|
43
|
+
def test_script_tag(self):
|
|
44
|
+
if not self.app.jinja:
|
|
45
|
+
if not hasattr(self, "skipTest"):
|
|
46
|
+
return
|
|
47
|
+
self.skipTest("No Jinja2 template engine present")
|
|
48
|
+
|
|
49
|
+
template = appier.Template("{{ value|script_tag }}")
|
|
50
|
+
result = self.app.template(template, value="/static/app.js")
|
|
51
|
+
self.assertEqual(
|
|
52
|
+
result, '<script type="text/javascript" src="/static/app.js"></script>'
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
template = appier.Template("{{ '/static/app.js'|script_tag }}")
|
|
56
|
+
result = self.app.template(template)
|
|
57
|
+
self.assertEqual(
|
|
58
|
+
result, '<script type="text/javascript" src="/static/app.js"></script>'
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
def test_css_tag(self):
|
|
62
|
+
if not self.app.jinja:
|
|
63
|
+
if not hasattr(self, "skipTest"):
|
|
64
|
+
return
|
|
65
|
+
self.skipTest("No Jinja2 template engine present")
|
|
66
|
+
|
|
67
|
+
template = appier.Template("{{ value|css_tag }}")
|
|
68
|
+
result = self.app.template(template, value="/static/style.css")
|
|
69
|
+
self.assertEqual(
|
|
70
|
+
result, '<link rel="stylesheet" type="text/css" href="/static/style.css" />'
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
template = appier.Template("{{ '/static/style.css'|css_tag }}")
|
|
74
|
+
result = self.app.template(template)
|
|
75
|
+
self.assertEqual(
|
|
76
|
+
result, '<link rel="stylesheet" type="text/css" href="/static/style.css" />'
|
|
77
|
+
)
|
|
78
|
+
|
|
79
|
+
def test_stylesheet_tag(self):
|
|
80
|
+
if not self.app.jinja:
|
|
81
|
+
if not hasattr(self, "skipTest"):
|
|
82
|
+
return
|
|
83
|
+
self.skipTest("No Jinja2 template engine present")
|
|
84
|
+
|
|
85
|
+
template = appier.Template("{{ value|stylesheet_tag }}")
|
|
86
|
+
result = self.app.template(template, value="/static/main.css")
|
|
87
|
+
self.assertEqual(
|
|
88
|
+
result, '<link rel="stylesheet" type="text/css" href="/static/main.css" />'
|
|
89
|
+
)
|
|
90
|
+
|
|
91
|
+
template = appier.Template("{{ '/static/main.css'|stylesheet_tag }}")
|
|
92
|
+
result = self.app.template(template)
|
|
93
|
+
self.assertEqual(
|
|
94
|
+
result, '<link rel="stylesheet" type="text/css" href="/static/main.css" />'
|
|
95
|
+
)
|
|
96
|
+
|
|
97
|
+
def test_asset_url(self):
|
|
98
|
+
if not self.app.jinja:
|
|
99
|
+
if not hasattr(self, "skipTest"):
|
|
100
|
+
return
|
|
101
|
+
self.skipTest("No Jinja2 template engine present")
|
|
102
|
+
|
|
103
|
+
template = appier.Template("{{ filename|asset_url }}")
|
|
104
|
+
result = self.app.template(template, filename="logo.png")
|
|
105
|
+
self.assertEqual(result, "/static/assets/logo.png")
|
|
106
|
+
|
|
107
|
+
template = appier.Template("{{ 'logo.png'|asset_url }}")
|
|
108
|
+
result = self.app.template(template)
|
|
109
|
+
self.assertEqual(result, "/static/assets/logo.png")
|