appier 1.31.4__py2.py3-none-any.whl → 1.32.0__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 +333 -52
- appier/amqp.py +29 -30
- appier/api.py +214 -212
- appier/asgi.py +54 -55
- appier/async_neo.py +46 -35
- appier/async_old.py +55 -42
- appier/asynchronous.py +7 -13
- appier/base.py +1762 -1429
- appier/bus.py +51 -52
- appier/cache.py +99 -84
- appier/common.py +9 -11
- appier/component.py +17 -19
- appier/compress.py +25 -28
- appier/config.py +96 -73
- appier/controller.py +9 -15
- appier/crypt.py +25 -21
- appier/data.py +73 -57
- appier/defines.py +191 -226
- appier/exceptions.py +103 -63
- appier/execution.py +94 -88
- appier/export.py +90 -88
- appier/extra.py +6 -13
- appier/extra_neo.py +8 -11
- appier/extra_old.py +18 -16
- appier/geo.py +57 -47
- appier/git.py +101 -90
- appier/graph.py +23 -24
- appier/http.py +520 -398
- appier/legacy.py +373 -180
- appier/log.py +90 -97
- appier/meta.py +42 -42
- appier/mock.py +32 -34
- appier/model.py +793 -681
- appier/model_a.py +208 -183
- appier/mongo.py +183 -107
- appier/observer.py +39 -31
- appier/part.py +23 -24
- appier/preferences.py +44 -47
- appier/queuing.py +78 -96
- appier/redisdb.py +40 -35
- appier/request.py +227 -175
- appier/scheduler.py +13 -18
- appier/serialize.py +37 -31
- appier/session.py +161 -147
- appier/settings.py +2 -11
- appier/smtp.py +53 -49
- appier/storage.py +39 -33
- appier/structures.py +50 -45
- appier/test/__init__.py +2 -11
- appier/test/base.py +111 -108
- appier/test/cache.py +28 -35
- appier/test/config.py +10 -19
- appier/test/crypt.py +3 -12
- appier/test/data.py +3 -12
- appier/test/exceptions.py +8 -17
- appier/test/export.py +16 -33
- appier/test/graph.py +27 -60
- appier/test/http.py +42 -54
- appier/test/legacy.py +20 -30
- appier/test/log.py +14 -35
- appier/test/mock.py +27 -123
- appier/test/model.py +79 -91
- appier/test/part.py +5 -14
- appier/test/preferences.py +5 -13
- appier/test/queuing.py +29 -37
- appier/test/request.py +61 -73
- appier/test/serialize.py +12 -23
- appier/test/session.py +10 -19
- appier/test/smtp.py +8 -14
- appier/test/structures.py +20 -24
- appier/test/typesf.py +14 -28
- appier/test/util.py +480 -438
- appier/typesf.py +251 -171
- appier/util.py +578 -407
- appier/validation.py +280 -143
- {appier-1.31.4.dist-info → appier-1.32.0.dist-info}/METADATA +6 -1
- appier-1.32.0.dist-info/RECORD +86 -0
- appier-1.31.4.dist-info/RECORD +0 -86
- {appier-1.31.4.dist-info → appier-1.32.0.dist-info}/LICENSE +0 -0
- {appier-1.31.4.dist-info → appier-1.32.0.dist-info}/WHEEL +0 -0
- {appier-1.31.4.dist-info → appier-1.32.0.dist-info}/top_level.txt +0 -0
appier/test/base.py
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
# -*- coding: utf-8 -*-
|
|
3
3
|
|
|
4
4
|
# Hive Appier Framework
|
|
5
|
-
# Copyright (c) 2008-
|
|
5
|
+
# Copyright (c) 2008-2024 Hive Solutions Lda.
|
|
6
6
|
#
|
|
7
7
|
# This file is part of Hive Appier Framework.
|
|
8
8
|
#
|
|
@@ -22,16 +22,7 @@
|
|
|
22
22
|
__author__ = "João Magalhães <joamag@hive.pt>"
|
|
23
23
|
""" The author(s) of the module """
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
""" The version of the module """
|
|
27
|
-
|
|
28
|
-
__revision__ = "$LastChangedRevision$"
|
|
29
|
-
""" The revision number of the module """
|
|
30
|
-
|
|
31
|
-
__date__ = "$LastChangedDate$"
|
|
32
|
-
""" The last change date of the module """
|
|
33
|
-
|
|
34
|
-
__copyright__ = "Copyright (c) 2008-2022 Hive Solutions Lda."
|
|
25
|
+
__copyright__ = "Copyright (c) 2008-2024 Hive Solutions Lda."
|
|
35
26
|
""" The copyright for the module """
|
|
36
27
|
|
|
37
28
|
__license__ = "Apache License, Version 2.0"
|
|
@@ -41,8 +32,8 @@ import unittest
|
|
|
41
32
|
|
|
42
33
|
import appier
|
|
43
34
|
|
|
44
|
-
class BaseTest(unittest.TestCase):
|
|
45
35
|
|
|
36
|
+
class BaseTest(unittest.TestCase):
|
|
46
37
|
def setUp(self):
|
|
47
38
|
self.app = appier.App()
|
|
48
39
|
|
|
@@ -51,137 +42,137 @@ class BaseTest(unittest.TestCase):
|
|
|
51
42
|
|
|
52
43
|
def test_locale(self):
|
|
53
44
|
self.app.locales = ("en_us", "pt_pt", "es_es")
|
|
54
|
-
self.app._register_bundle(dict(hello
|
|
55
|
-
self.app._register_bundle(dict(hello
|
|
56
|
-
self.app._register_bundle(dict(hello
|
|
45
|
+
self.app._register_bundle(dict(hello="Hello"), "en_us")
|
|
46
|
+
self.app._register_bundle(dict(hello="Olá"), "pt_pt")
|
|
47
|
+
self.app._register_bundle(dict(hello="Bonjour"), "fr")
|
|
57
48
|
|
|
58
49
|
result = self.app.to_locale("hello")
|
|
59
50
|
self.assertEqual(result, "Hello")
|
|
60
51
|
|
|
61
|
-
result = self.app.to_locale("hello", locale
|
|
52
|
+
result = self.app.to_locale("hello", locale="en_us")
|
|
62
53
|
self.assertEqual(result, "Hello")
|
|
63
54
|
|
|
64
|
-
result = self.app.to_locale("hello", locale
|
|
55
|
+
result = self.app.to_locale("hello", locale="en-us")
|
|
65
56
|
self.assertEqual(result, "Hello")
|
|
66
57
|
|
|
67
|
-
result = self.app.to_locale("hello", locale
|
|
58
|
+
result = self.app.to_locale("hello", locale="pt_pt")
|
|
68
59
|
self.assertEqual(result, "Olá")
|
|
69
60
|
|
|
70
|
-
result = self.app.to_locale("hello", locale
|
|
61
|
+
result = self.app.to_locale("hello", locale="pt-pt")
|
|
71
62
|
self.assertNotEqual(result, "Olá")
|
|
72
63
|
self.assertEqual(result, "Hello")
|
|
73
64
|
|
|
74
|
-
result = self.app.to_locale("hello", locale
|
|
65
|
+
result = self.app.to_locale("hello", locale="fr_fr")
|
|
75
66
|
self.assertEqual(result, "Bonjour")
|
|
76
67
|
|
|
77
|
-
result = self.app.to_locale("hello", locale
|
|
68
|
+
result = self.app.to_locale("hello", locale="fr")
|
|
78
69
|
self.assertEqual(result, "Bonjour")
|
|
79
70
|
|
|
80
|
-
result = self.app.to_locale("hello", locale
|
|
71
|
+
result = self.app.to_locale("hello", locale="es_es")
|
|
81
72
|
self.assertNotEqual(result, "Hola")
|
|
82
73
|
self.assertEqual(result, "Hello")
|
|
83
74
|
|
|
84
|
-
result = self.app.has_locale("hello", locale
|
|
75
|
+
result = self.app.has_locale("hello", locale="pt_pt")
|
|
85
76
|
self.assertEqual(result, True)
|
|
86
77
|
|
|
87
|
-
result = self.app.has_locale("Hello", locale
|
|
78
|
+
result = self.app.has_locale("Hello", locale="pt_pt")
|
|
88
79
|
self.assertEqual(result, False)
|
|
89
80
|
|
|
90
|
-
result = self.app.has_locale("hello", locale
|
|
81
|
+
result = self.app.has_locale("hello", locale="fr_fr")
|
|
91
82
|
self.assertEqual(result, True)
|
|
92
83
|
|
|
93
|
-
result = self.app.has_locale("hello", locale
|
|
84
|
+
result = self.app.has_locale("hello", locale="fr")
|
|
94
85
|
self.assertEqual(result, True)
|
|
95
86
|
|
|
96
|
-
result = self.app.has_locale("Hello", locale
|
|
87
|
+
result = self.app.has_locale("Hello", locale="fr")
|
|
97
88
|
self.assertEqual(result, False)
|
|
98
89
|
|
|
99
|
-
result = self.app.has_locale("hello", locale
|
|
90
|
+
result = self.app.has_locale("hello", locale="es_es")
|
|
100
91
|
self.assertEqual(result, False)
|
|
101
92
|
|
|
102
|
-
result = self.app.has_locale("Hello", locale
|
|
93
|
+
result = self.app.has_locale("Hello", locale="es_es")
|
|
103
94
|
self.assertEqual(result, False)
|
|
104
95
|
|
|
105
|
-
self.app._register_bundle(dict(hello
|
|
96
|
+
self.app._register_bundle(dict(hello="Hola"), "es_es")
|
|
106
97
|
|
|
107
|
-
result = self.app.to_locale("hello", locale
|
|
98
|
+
result = self.app.to_locale("hello", locale="es_es")
|
|
108
99
|
self.assertEqual(result, "Hola")
|
|
109
100
|
|
|
110
|
-
result = self.app.to_locale("hello", locale
|
|
101
|
+
result = self.app.to_locale("hello", locale="en")
|
|
111
102
|
self.assertEqual(result, "Hello")
|
|
112
103
|
|
|
113
|
-
result = self.app.to_locale("hello", locale
|
|
104
|
+
result = self.app.to_locale("hello", locale="pt")
|
|
114
105
|
self.assertEqual(result, "Olá")
|
|
115
106
|
|
|
116
|
-
result = self.app.to_locale("hello", locale
|
|
107
|
+
result = self.app.to_locale("hello", locale="es")
|
|
117
108
|
self.assertEqual(result, "Hola")
|
|
118
109
|
|
|
119
110
|
result = self.app.to_locale("bye")
|
|
120
111
|
self.assertEqual(result, "bye")
|
|
121
112
|
|
|
122
|
-
result = self.app.to_locale("bye", locale
|
|
113
|
+
result = self.app.to_locale("bye", locale="cn")
|
|
123
114
|
self.assertEqual(result, "bye")
|
|
124
115
|
|
|
125
|
-
self.app._register_bundle(dict(bye
|
|
116
|
+
self.app._register_bundle(dict(bye="Bye"), "en_us")
|
|
126
117
|
|
|
127
118
|
result = self.app.to_locale("bye")
|
|
128
119
|
self.assertEqual(result, "Bye")
|
|
129
120
|
|
|
130
|
-
result = self.app.to_locale("bye", locale
|
|
121
|
+
result = self.app.to_locale("bye", locale="en_us")
|
|
131
122
|
self.assertEqual(result, "Bye")
|
|
132
123
|
|
|
133
|
-
result = self.app.to_locale("bye", locale
|
|
124
|
+
result = self.app.to_locale("bye", locale="pt_pt")
|
|
134
125
|
self.assertEqual(result, "Bye")
|
|
135
126
|
|
|
136
|
-
result = self.app.to_locale("bye", locale
|
|
127
|
+
result = self.app.to_locale("bye", locale="pt_pt", fallback=False)
|
|
137
128
|
self.assertEqual(result, "bye")
|
|
138
129
|
|
|
139
|
-
result = self.app.has_locale("bye", locale
|
|
130
|
+
result = self.app.has_locale("bye", locale="en_us")
|
|
140
131
|
self.assertEqual(result, True)
|
|
141
132
|
|
|
142
|
-
result = self.app.has_locale("Bye", locale
|
|
133
|
+
result = self.app.has_locale("Bye", locale="en_us")
|
|
143
134
|
self.assertEqual(result, False)
|
|
144
135
|
|
|
145
|
-
result = self.app.has_locale("bye", locale
|
|
136
|
+
result = self.app.has_locale("bye", locale="pt_pt")
|
|
146
137
|
self.assertEqual(result, False)
|
|
147
138
|
|
|
148
|
-
result = self.app.has_locale("Bye", locale
|
|
139
|
+
result = self.app.has_locale("Bye", locale="pt_pt")
|
|
149
140
|
self.assertEqual(result, False)
|
|
150
141
|
|
|
151
142
|
def test_locale_context(self):
|
|
152
143
|
self.app.locales = ("en_us", "pt_pt", "es_es")
|
|
153
|
-
self.app._register_bundle(dict(hello
|
|
144
|
+
self.app._register_bundle(dict(hello="Hello"), "en_us", context="extra")
|
|
154
145
|
|
|
155
146
|
result = self.app.to_locale("hello")
|
|
156
147
|
self.assertEqual(result, "Hello")
|
|
157
148
|
|
|
158
|
-
result = self.app.to_locale("hello", context
|
|
149
|
+
result = self.app.to_locale("hello", context="extra")
|
|
159
150
|
self.assertEqual(result, "Hello")
|
|
160
151
|
|
|
161
|
-
result = self.app.to_locale("hello", context
|
|
152
|
+
result = self.app.to_locale("hello", context="other")
|
|
162
153
|
self.assertEqual(result, "hello")
|
|
163
154
|
|
|
164
|
-
result = self.app.has_locale("hello", context
|
|
155
|
+
result = self.app.has_locale("hello", context="extra")
|
|
165
156
|
self.assertEqual(result, True)
|
|
166
157
|
|
|
167
|
-
result = self.app.has_locale("hello", context
|
|
158
|
+
result = self.app.has_locale("hello", context="other")
|
|
168
159
|
self.assertEqual(result, False)
|
|
169
160
|
|
|
170
|
-
self.app._unregister_bundle(dict(hello
|
|
161
|
+
self.app._unregister_bundle(dict(hello="Hello"), "en_us", context="extra")
|
|
171
162
|
|
|
172
|
-
result = self.app.has_locale("hello", context
|
|
163
|
+
result = self.app.has_locale("hello", context="extra")
|
|
173
164
|
self.assertEqual(result, False)
|
|
174
165
|
|
|
175
166
|
def test_field(self):
|
|
176
167
|
request = appier.Request("GET", "/")
|
|
177
168
|
request.set_params(
|
|
178
169
|
dict(
|
|
179
|
-
name
|
|
180
|
-
message
|
|
181
|
-
valid_email
|
|
182
|
-
invalid_email
|
|
183
|
-
valid_length
|
|
184
|
-
invalid_length
|
|
170
|
+
name=["john doe"],
|
|
171
|
+
message=[""],
|
|
172
|
+
valid_email=["john@doe.com"],
|
|
173
|
+
invalid_email=["john"],
|
|
174
|
+
valid_length=["1234"],
|
|
175
|
+
invalid_length=["12345"],
|
|
185
176
|
),
|
|
186
177
|
)
|
|
187
178
|
self.app._request = request
|
|
@@ -189,53 +180,49 @@ class BaseTest(unittest.TestCase):
|
|
|
189
180
|
value = self.app.field("name")
|
|
190
181
|
self.assertEqual(value, "john doe")
|
|
191
182
|
|
|
192
|
-
value = self.app.field("message", mandatory
|
|
183
|
+
value = self.app.field("message", mandatory=True)
|
|
193
184
|
self.assertEqual(value, "")
|
|
194
185
|
|
|
195
186
|
value = self.app.field(
|
|
196
|
-
"valid_email",
|
|
197
|
-
mandatory = True,
|
|
198
|
-
not_empty = True,
|
|
199
|
-
validation = (appier.is_email,)
|
|
187
|
+
"valid_email", mandatory=True, not_empty=True, validation=(appier.is_email,)
|
|
200
188
|
)
|
|
201
189
|
self.assertEqual(value, "john@doe.com")
|
|
202
190
|
|
|
203
191
|
value = self.app.field(
|
|
204
192
|
"valid_length",
|
|
205
|
-
mandatory
|
|
206
|
-
not_empty
|
|
207
|
-
validation
|
|
193
|
+
mandatory=True,
|
|
194
|
+
not_empty=True,
|
|
195
|
+
validation=((appier.string_lt, 5),),
|
|
208
196
|
)
|
|
209
197
|
self.assertEqual(value, "1234")
|
|
210
198
|
|
|
211
199
|
self.assertRaises(
|
|
212
|
-
appier.OperationalError,
|
|
213
|
-
lambda: self.app.field("other", mandatory = True)
|
|
200
|
+
appier.OperationalError, lambda: self.app.field("other", mandatory=True)
|
|
214
201
|
)
|
|
215
202
|
|
|
216
203
|
self.assertRaises(
|
|
217
204
|
appier.OperationalError,
|
|
218
|
-
lambda: self.app.field("message", mandatory
|
|
205
|
+
lambda: self.app.field("message", mandatory=True, not_empty=True),
|
|
219
206
|
)
|
|
220
207
|
|
|
221
208
|
self.assertRaises(
|
|
222
209
|
appier.ValidationInternalError,
|
|
223
210
|
lambda: self.app.field(
|
|
224
211
|
"invalid_email",
|
|
225
|
-
mandatory
|
|
226
|
-
not_empty
|
|
227
|
-
validation
|
|
228
|
-
)
|
|
212
|
+
mandatory=True,
|
|
213
|
+
not_empty=True,
|
|
214
|
+
validation=(appier.is_email,),
|
|
215
|
+
),
|
|
229
216
|
)
|
|
230
217
|
|
|
231
218
|
self.assertRaises(
|
|
232
219
|
appier.ValidationInternalError,
|
|
233
220
|
lambda: self.app.field(
|
|
234
221
|
"invalid_length",
|
|
235
|
-
mandatory
|
|
236
|
-
not_empty
|
|
237
|
-
validation
|
|
238
|
-
)
|
|
222
|
+
mandatory=True,
|
|
223
|
+
not_empty=True,
|
|
224
|
+
validation=((appier.string_lt, 5),),
|
|
225
|
+
),
|
|
239
226
|
)
|
|
240
227
|
|
|
241
228
|
def test_slugify(self):
|
|
@@ -249,7 +236,8 @@ class BaseTest(unittest.TestCase):
|
|
|
249
236
|
|
|
250
237
|
def test_pyslugify(self):
|
|
251
238
|
if not self.app.pyslugify:
|
|
252
|
-
if not hasattr(self, "skipTest"):
|
|
239
|
+
if not hasattr(self, "skipTest"):
|
|
240
|
+
return
|
|
253
241
|
self.skipTest("No python-slugify engine present")
|
|
254
242
|
|
|
255
243
|
result = self.app.slugify_pyslugify("hello world")
|
|
@@ -263,13 +251,16 @@ class BaseTest(unittest.TestCase):
|
|
|
263
251
|
result = self.app.slugify_pyslugify("你好世界")
|
|
264
252
|
self.assertEqual(result, "ni-hao-shi-jie")
|
|
265
253
|
|
|
266
|
-
result = self.app.slugify_pyslugify(
|
|
254
|
+
result = self.app.slugify_pyslugify(
|
|
255
|
+
appier.legacy.bytes("你好世界", encoding="utf-8")
|
|
256
|
+
)
|
|
267
257
|
self.assertEqual(type(result), str)
|
|
268
258
|
self.assertEqual(result, "ni-hao-shi-jie")
|
|
269
259
|
|
|
270
260
|
def test_slugier(self):
|
|
271
261
|
if not self.app.slugier:
|
|
272
|
-
if not hasattr(self, "skipTest"):
|
|
262
|
+
if not hasattr(self, "skipTest"):
|
|
263
|
+
return
|
|
273
264
|
self.skipTest("No slugier engine present")
|
|
274
265
|
|
|
275
266
|
result = self.app.slugify_slugier("hello world")
|
|
@@ -284,7 +275,7 @@ class BaseTest(unittest.TestCase):
|
|
|
284
275
|
self.assertEqual(type(result), str)
|
|
285
276
|
self.assertEqual(result, "%e4%bd%a0%e5%a5%bd%e4%b8%96%e7%95%8c")
|
|
286
277
|
|
|
287
|
-
result = self.app.slugify_slugier(appier.legacy.bytes("你好世界", encoding
|
|
278
|
+
result = self.app.slugify_slugier(appier.legacy.bytes("你好世界", encoding="utf-8"))
|
|
288
279
|
self.assertEqual(type(result), str)
|
|
289
280
|
self.assertEqual(result, "%e4%bd%a0%e5%a5%bd%e4%b8%96%e7%95%8c")
|
|
290
281
|
|
|
@@ -293,92 +284,104 @@ class BaseTest(unittest.TestCase):
|
|
|
293
284
|
self.assertEqual(type(result), str)
|
|
294
285
|
self.assertEqual(result, "/login")
|
|
295
286
|
|
|
296
|
-
result = self.app.url_for("app.login", query
|
|
287
|
+
result = self.app.url_for("app.login", query="query_string")
|
|
297
288
|
self.assertEqual(type(result), str)
|
|
298
289
|
self.assertEqual(result, "/login?query_string")
|
|
299
290
|
|
|
300
|
-
result = self.app.url_for("app.login", params
|
|
291
|
+
result = self.app.url_for("app.login", params=dict(query="query_string"))
|
|
301
292
|
self.assertEqual(type(result), str)
|
|
302
293
|
self.assertEqual(result, "/login?query=query_string")
|
|
303
294
|
|
|
304
|
-
result = self.app.url_for("static", filename
|
|
295
|
+
result = self.app.url_for("static", filename="hello.txt")
|
|
305
296
|
self.assertEqual(type(result), str)
|
|
306
297
|
self.assertEqual(result, "/static/hello.txt")
|
|
307
298
|
|
|
308
|
-
result = self.app.url_for("static", filename
|
|
299
|
+
result = self.app.url_for("static", filename="hello.txt", compress="gzip")
|
|
309
300
|
self.assertEqual(type(result), str)
|
|
310
301
|
self.assertEqual(result, "/static/hello.txt?compress=gzip")
|
|
311
302
|
|
|
312
303
|
def test_filters(self):
|
|
313
304
|
if not self.app.jinja:
|
|
314
|
-
if not hasattr(self, "skipTest"):
|
|
305
|
+
if not hasattr(self, "skipTest"):
|
|
306
|
+
return
|
|
315
307
|
self.skipTest("No Jinja2 template engine present")
|
|
316
308
|
|
|
317
309
|
template = appier.Template("{{ message|locale }}")
|
|
318
|
-
result = self.app.template(template, message
|
|
310
|
+
result = self.app.template(template, message="hello")
|
|
319
311
|
self.assertEqual(result, "hello")
|
|
320
312
|
|
|
321
313
|
template = appier.Template("{{ message|nl_to_br }}")
|
|
322
|
-
result = self.app.template(template, message
|
|
314
|
+
result = self.app.template(template, message="hello\n")
|
|
323
315
|
self.assertEqual(result, "hello<br/>\n")
|
|
324
316
|
|
|
325
317
|
template = appier.Template("{{ message|sp_to_nbsp }}")
|
|
326
|
-
result = self.app.template(template, message
|
|
318
|
+
result = self.app.template(template, message="hello world")
|
|
327
319
|
self.assertEqual(result, "hello world")
|
|
328
320
|
|
|
329
321
|
def test_unset_filter(self):
|
|
330
322
|
if not self.app.jinja:
|
|
331
|
-
if not hasattr(self, "skipTest"):
|
|
323
|
+
if not hasattr(self, "skipTest"):
|
|
324
|
+
return
|
|
332
325
|
self.skipTest("No Jinja2 template engine present")
|
|
333
326
|
|
|
334
327
|
template = appier.Template("{{ message|unset('world') }}")
|
|
335
328
|
result = self.app.template(template)
|
|
336
329
|
self.assertEqual(result, appier.legacy.u("world"))
|
|
337
|
-
result = self.app.template(template, message
|
|
330
|
+
result = self.app.template(template, message="hello")
|
|
338
331
|
self.assertEqual(result, appier.legacy.u("hello"))
|
|
339
332
|
|
|
340
333
|
template = appier.Template("{{ message|unset(default = 'world') }}")
|
|
341
334
|
result = self.app.template(template)
|
|
342
335
|
self.assertEqual(result, appier.legacy.u("world"))
|
|
343
|
-
result = self.app.template(template, message
|
|
336
|
+
result = self.app.template(template, message="hello")
|
|
344
337
|
self.assertEqual(result, appier.legacy.u("hello"))
|
|
345
338
|
|
|
346
|
-
template = appier.Template(
|
|
347
|
-
|
|
339
|
+
template = appier.Template(
|
|
340
|
+
"{{ message|unset(default = 'world', empty = True) }}"
|
|
341
|
+
)
|
|
342
|
+
result = self.app.template(template, message="")
|
|
348
343
|
self.assertEqual(result, appier.legacy.u("world"))
|
|
349
|
-
result = self.app.template(template, message
|
|
344
|
+
result = self.app.template(template, message="hello")
|
|
350
345
|
self.assertEqual(result, appier.legacy.u("hello"))
|
|
351
346
|
|
|
352
|
-
template = appier.Template(
|
|
353
|
-
|
|
347
|
+
template = appier.Template(
|
|
348
|
+
"{{ message|unset(default = 'world', extra = ('',)) }}"
|
|
349
|
+
)
|
|
350
|
+
result = self.app.template(template, message="")
|
|
354
351
|
self.assertEqual(result, appier.legacy.u("world"))
|
|
355
|
-
result = self.app.template(template, message
|
|
352
|
+
result = self.app.template(template, message="hello")
|
|
356
353
|
self.assertEqual(result, appier.legacy.u("hello"))
|
|
357
354
|
|
|
358
|
-
template = appier.Template(
|
|
359
|
-
|
|
355
|
+
template = appier.Template(
|
|
356
|
+
"{{ message|unset(default = 'world', extra = ('', 't')) }}"
|
|
357
|
+
)
|
|
358
|
+
result = self.app.template(template, message="t")
|
|
360
359
|
self.assertEqual(result, appier.legacy.u("world"))
|
|
361
|
-
result = self.app.template(template, message
|
|
360
|
+
result = self.app.template(template, message="hello")
|
|
362
361
|
self.assertEqual(result, appier.legacy.u("hello"))
|
|
363
362
|
|
|
364
363
|
def test_locale_filter(self):
|
|
365
364
|
if not self.app.jinja:
|
|
366
|
-
if not hasattr(self, "skipTest"):
|
|
365
|
+
if not hasattr(self, "skipTest"):
|
|
366
|
+
return
|
|
367
367
|
self.skipTest("No Jinja2 template engine present")
|
|
368
368
|
|
|
369
|
-
self.app._register_bundle(
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
369
|
+
self.app._register_bundle(
|
|
370
|
+
{
|
|
371
|
+
"hello": appier.legacy.u("olá"),
|
|
372
|
+
"world": appier.legacy.u("mundo"),
|
|
373
|
+
},
|
|
374
|
+
"pt_pt",
|
|
375
|
+
)
|
|
373
376
|
|
|
374
377
|
template = appier.Template("{{ message|locale }}")
|
|
375
|
-
result = self.app.template(template, locale
|
|
378
|
+
result = self.app.template(template, locale="pt_pt", message="hello")
|
|
376
379
|
self.assertEqual(result, appier.legacy.u("olá"))
|
|
377
|
-
result = self.app.template(template, locale
|
|
380
|
+
result = self.app.template(template, locale="en_us", message="hello")
|
|
378
381
|
self.assertEqual(result, appier.legacy.u("hello"))
|
|
379
382
|
|
|
380
383
|
template = appier.Template("{{ 'hello'|locale }}")
|
|
381
|
-
result = self.app.template(template, locale
|
|
384
|
+
result = self.app.template(template, locale="pt_pt")
|
|
382
385
|
self.assertEqual(result, appier.legacy.u("olá"))
|
|
383
|
-
result = self.app.template(template, locale
|
|
386
|
+
result = self.app.template(template, locale="en_us")
|
|
384
387
|
self.assertEqual(result, appier.legacy.u("hello"))
|
appier/test/cache.py
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
# -*- coding: utf-8 -*-
|
|
3
3
|
|
|
4
4
|
# Hive Appier Framework
|
|
5
|
-
# Copyright (c) 2008-
|
|
5
|
+
# Copyright (c) 2008-2024 Hive Solutions Lda.
|
|
6
6
|
#
|
|
7
7
|
# This file is part of Hive Appier Framework.
|
|
8
8
|
#
|
|
@@ -22,16 +22,7 @@
|
|
|
22
22
|
__author__ = "João Magalhães <joamag@hive.pt>"
|
|
23
23
|
""" The author(s) of the module """
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
""" The version of the module """
|
|
27
|
-
|
|
28
|
-
__revision__ = "$LastChangedRevision$"
|
|
29
|
-
""" The revision number of the module """
|
|
30
|
-
|
|
31
|
-
__date__ = "$LastChangedDate$"
|
|
32
|
-
""" The last change date of the module """
|
|
33
|
-
|
|
34
|
-
__copyright__ = "Copyright (c) 2008-2022 Hive Solutions Lda."
|
|
25
|
+
__copyright__ = "Copyright (c) 2008-2024 Hive Solutions Lda."
|
|
35
26
|
""" The copyright for the module """
|
|
36
27
|
|
|
37
28
|
__license__ = "Apache License, Version 2.0"
|
|
@@ -42,8 +33,8 @@ import unittest
|
|
|
42
33
|
|
|
43
34
|
import appier
|
|
44
35
|
|
|
45
|
-
class CacheTest(unittest.TestCase):
|
|
46
36
|
|
|
37
|
+
class CacheTest(unittest.TestCase):
|
|
47
38
|
def setUp(self):
|
|
48
39
|
self.app = appier.App()
|
|
49
40
|
|
|
@@ -59,21 +50,21 @@ class CacheTest(unittest.TestCase):
|
|
|
59
50
|
self.assertEqual(cache["first"], 1)
|
|
60
51
|
self.assertEqual(cache["second"], 2)
|
|
61
52
|
|
|
62
|
-
cache.set_item("first", 1, timeout
|
|
53
|
+
cache.set_item("first", 1, timeout=-1)
|
|
63
54
|
|
|
64
55
|
self.assertEqual("first" in cache, False)
|
|
65
56
|
self.assertRaises(KeyError, lambda: cache["first"])
|
|
66
57
|
|
|
67
|
-
cache.set_item("first", 1, timeout
|
|
58
|
+
cache.set_item("first", 1, timeout=3600)
|
|
68
59
|
|
|
69
60
|
self.assertEqual(cache["first"], 1)
|
|
70
61
|
|
|
71
|
-
cache.set_item("first", 1, expires
|
|
62
|
+
cache.set_item("first", 1, expires=time.time() - 1)
|
|
72
63
|
|
|
73
64
|
self.assertEqual("first" in cache, False)
|
|
74
65
|
self.assertRaises(KeyError, lambda: cache["first"])
|
|
75
66
|
|
|
76
|
-
cache.set_item("first", 1, expires
|
|
67
|
+
cache.set_item("first", 1, expires=time.time() + 3600)
|
|
77
68
|
|
|
78
69
|
self.assertEqual(cache["first"], 1)
|
|
79
70
|
|
|
@@ -96,21 +87,21 @@ class CacheTest(unittest.TestCase):
|
|
|
96
87
|
self.assertEqual(cache["first"], b"1")
|
|
97
88
|
self.assertEqual(cache["second"], b"2")
|
|
98
89
|
|
|
99
|
-
cache.set_item("first", b"1", timeout
|
|
90
|
+
cache.set_item("first", b"1", timeout=-1)
|
|
100
91
|
|
|
101
92
|
self.assertEqual("first" in cache, False)
|
|
102
93
|
self.assertRaises(KeyError, lambda: cache["first"])
|
|
103
94
|
|
|
104
|
-
cache.set_item("first", b"1", timeout
|
|
95
|
+
cache.set_item("first", b"1", timeout=3600)
|
|
105
96
|
|
|
106
97
|
self.assertEqual(cache["first"], b"1")
|
|
107
98
|
|
|
108
|
-
cache.set_item("first", b"1", expires
|
|
99
|
+
cache.set_item("first", b"1", expires=time.time() - 1)
|
|
109
100
|
|
|
110
101
|
self.assertEqual("first" in cache, False)
|
|
111
102
|
self.assertRaises(KeyError, lambda: cache["first"])
|
|
112
103
|
|
|
113
|
-
cache.set_item("first", b"1", expires
|
|
104
|
+
cache.set_item("first", b"1", expires=time.time() + 3600)
|
|
114
105
|
|
|
115
106
|
self.assertEqual(cache["first"], b"1")
|
|
116
107
|
|
|
@@ -128,7 +119,8 @@ class CacheTest(unittest.TestCase):
|
|
|
128
119
|
try:
|
|
129
120
|
cache = appier.RedisCache.new()
|
|
130
121
|
except Exception:
|
|
131
|
-
if not hasattr(self, "skipTest"):
|
|
122
|
+
if not hasattr(self, "skipTest"):
|
|
123
|
+
return
|
|
132
124
|
self.skipTest("No Redis server present")
|
|
133
125
|
|
|
134
126
|
cache["first"] = b"1"
|
|
@@ -137,21 +129,21 @@ class CacheTest(unittest.TestCase):
|
|
|
137
129
|
self.assertEqual(cache["first"], b"1")
|
|
138
130
|
self.assertEqual(cache["second"], b"2")
|
|
139
131
|
|
|
140
|
-
cache.set_item("first", b"1", timeout
|
|
132
|
+
cache.set_item("first", b"1", timeout=-1)
|
|
141
133
|
|
|
142
134
|
self.assertEqual("first" in cache, False)
|
|
143
135
|
self.assertRaises(KeyError, lambda: cache["first"])
|
|
144
136
|
|
|
145
|
-
cache.set_item("first", b"1", timeout
|
|
137
|
+
cache.set_item("first", b"1", timeout=3600)
|
|
146
138
|
|
|
147
139
|
self.assertEqual(cache["first"], b"1")
|
|
148
140
|
|
|
149
|
-
cache.set_item("first", b"1", expires
|
|
141
|
+
cache.set_item("first", b"1", expires=time.time() - 1)
|
|
150
142
|
|
|
151
143
|
self.assertEqual("first" in cache, False)
|
|
152
144
|
self.assertRaises(KeyError, lambda: cache["first"])
|
|
153
145
|
|
|
154
|
-
cache.set_item("first", b"1", expires
|
|
146
|
+
cache.set_item("first", b"1", expires=time.time() + 3600)
|
|
155
147
|
|
|
156
148
|
self.assertEqual(cache["first"], b"1")
|
|
157
149
|
|
|
@@ -167,9 +159,10 @@ class CacheTest(unittest.TestCase):
|
|
|
167
159
|
|
|
168
160
|
def test_redis_hash(self):
|
|
169
161
|
try:
|
|
170
|
-
cache = appier.RedisCache.new(hash
|
|
162
|
+
cache = appier.RedisCache.new(hash=True)
|
|
171
163
|
except Exception:
|
|
172
|
-
if not hasattr(self, "skipTest"):
|
|
164
|
+
if not hasattr(self, "skipTest"):
|
|
165
|
+
return
|
|
173
166
|
self.skipTest("No Redis server present")
|
|
174
167
|
|
|
175
168
|
cache["first"] = b"1"
|
|
@@ -178,21 +171,21 @@ class CacheTest(unittest.TestCase):
|
|
|
178
171
|
self.assertEqual(cache["first"], b"1")
|
|
179
172
|
self.assertEqual(cache["second"], b"2")
|
|
180
173
|
|
|
181
|
-
cache.set_item("first", b"1", timeout
|
|
174
|
+
cache.set_item("first", b"1", timeout=-1)
|
|
182
175
|
|
|
183
176
|
self.assertEqual("first" in cache, False)
|
|
184
177
|
self.assertRaises(KeyError, lambda: cache["first"])
|
|
185
178
|
|
|
186
|
-
cache.set_item("first", b"1", timeout
|
|
179
|
+
cache.set_item("first", b"1", timeout=3600)
|
|
187
180
|
|
|
188
181
|
self.assertEqual(cache["first"], b"1")
|
|
189
182
|
|
|
190
|
-
cache.set_item("first", b"1", expires
|
|
183
|
+
cache.set_item("first", b"1", expires=time.time() - 1)
|
|
191
184
|
|
|
192
185
|
self.assertEqual("first" in cache, False)
|
|
193
186
|
self.assertRaises(KeyError, lambda: cache["first"])
|
|
194
187
|
|
|
195
|
-
cache.set_item("first", b"1", expires
|
|
188
|
+
cache.set_item("first", b"1", expires=time.time() + 3600)
|
|
196
189
|
|
|
197
190
|
self.assertEqual(cache["first"], b"1")
|
|
198
191
|
|
|
@@ -216,21 +209,21 @@ class CacheTest(unittest.TestCase):
|
|
|
216
209
|
self.assertEqual(cache["first"], 1)
|
|
217
210
|
self.assertEqual(cache["second"], 2)
|
|
218
211
|
|
|
219
|
-
cache.set_item("first", 1, timeout
|
|
212
|
+
cache.set_item("first", 1, timeout=-1)
|
|
220
213
|
|
|
221
214
|
self.assertEqual("first" in cache, False)
|
|
222
215
|
self.assertRaises(KeyError, lambda: cache["first"])
|
|
223
216
|
|
|
224
|
-
cache.set_item("first", 1, timeout
|
|
217
|
+
cache.set_item("first", 1, timeout=3600)
|
|
225
218
|
|
|
226
219
|
self.assertEqual(cache["first"], 1)
|
|
227
220
|
|
|
228
|
-
cache.set_item("first", 1, expires
|
|
221
|
+
cache.set_item("first", 1, expires=time.time() - 1)
|
|
229
222
|
|
|
230
223
|
self.assertEqual("first" in cache, False)
|
|
231
224
|
self.assertRaises(KeyError, lambda: cache["first"])
|
|
232
225
|
|
|
233
|
-
cache.set_item("first", 1, expires
|
|
226
|
+
cache.set_item("first", 1, expires=time.time() + 3600)
|
|
234
227
|
|
|
235
228
|
self.assertEqual(cache["first"], 1)
|
|
236
229
|
|