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.
Files changed (81) hide show
  1. appier/__init__.py +333 -52
  2. appier/amqp.py +29 -30
  3. appier/api.py +214 -212
  4. appier/asgi.py +54 -55
  5. appier/async_neo.py +46 -35
  6. appier/async_old.py +55 -42
  7. appier/asynchronous.py +7 -13
  8. appier/base.py +1762 -1429
  9. appier/bus.py +51 -52
  10. appier/cache.py +99 -84
  11. appier/common.py +9 -11
  12. appier/component.py +17 -19
  13. appier/compress.py +25 -28
  14. appier/config.py +96 -73
  15. appier/controller.py +9 -15
  16. appier/crypt.py +25 -21
  17. appier/data.py +73 -57
  18. appier/defines.py +191 -226
  19. appier/exceptions.py +103 -63
  20. appier/execution.py +94 -88
  21. appier/export.py +90 -88
  22. appier/extra.py +6 -13
  23. appier/extra_neo.py +8 -11
  24. appier/extra_old.py +18 -16
  25. appier/geo.py +57 -47
  26. appier/git.py +101 -90
  27. appier/graph.py +23 -24
  28. appier/http.py +520 -398
  29. appier/legacy.py +373 -180
  30. appier/log.py +90 -97
  31. appier/meta.py +42 -42
  32. appier/mock.py +32 -34
  33. appier/model.py +793 -681
  34. appier/model_a.py +208 -183
  35. appier/mongo.py +183 -107
  36. appier/observer.py +39 -31
  37. appier/part.py +23 -24
  38. appier/preferences.py +44 -47
  39. appier/queuing.py +78 -96
  40. appier/redisdb.py +40 -35
  41. appier/request.py +227 -175
  42. appier/scheduler.py +13 -18
  43. appier/serialize.py +37 -31
  44. appier/session.py +161 -147
  45. appier/settings.py +2 -11
  46. appier/smtp.py +53 -49
  47. appier/storage.py +39 -33
  48. appier/structures.py +50 -45
  49. appier/test/__init__.py +2 -11
  50. appier/test/base.py +111 -108
  51. appier/test/cache.py +28 -35
  52. appier/test/config.py +10 -19
  53. appier/test/crypt.py +3 -12
  54. appier/test/data.py +3 -12
  55. appier/test/exceptions.py +8 -17
  56. appier/test/export.py +16 -33
  57. appier/test/graph.py +27 -60
  58. appier/test/http.py +42 -54
  59. appier/test/legacy.py +20 -30
  60. appier/test/log.py +14 -35
  61. appier/test/mock.py +27 -123
  62. appier/test/model.py +79 -91
  63. appier/test/part.py +5 -14
  64. appier/test/preferences.py +5 -13
  65. appier/test/queuing.py +29 -37
  66. appier/test/request.py +61 -73
  67. appier/test/serialize.py +12 -23
  68. appier/test/session.py +10 -19
  69. appier/test/smtp.py +8 -14
  70. appier/test/structures.py +20 -24
  71. appier/test/typesf.py +14 -28
  72. appier/test/util.py +480 -438
  73. appier/typesf.py +251 -171
  74. appier/util.py +578 -407
  75. appier/validation.py +280 -143
  76. {appier-1.31.4.dist-info → appier-1.32.0.dist-info}/METADATA +6 -1
  77. appier-1.32.0.dist-info/RECORD +86 -0
  78. appier-1.31.4.dist-info/RECORD +0 -86
  79. {appier-1.31.4.dist-info → appier-1.32.0.dist-info}/LICENSE +0 -0
  80. {appier-1.31.4.dist-info → appier-1.32.0.dist-info}/WHEEL +0 -0
  81. {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-2022 Hive Solutions Lda.
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
- __version__ = "1.0.0"
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 = "Hello"), "en_us")
55
- self.app._register_bundle(dict(hello = "Olá"), "pt_pt")
56
- self.app._register_bundle(dict(hello = "Bonjour"), "fr")
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 = "en_us")
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 = "en-us")
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 = "pt_pt")
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 = "pt-pt")
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 = "fr_fr")
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 = "fr")
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 = "es_es")
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 = "pt_pt")
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 = "pt_pt")
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 = "fr_fr")
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 = "fr")
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 = "fr")
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 = "es_es")
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 = "es_es")
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 = "Hola"), "es_es")
96
+ self.app._register_bundle(dict(hello="Hola"), "es_es")
106
97
 
107
- result = self.app.to_locale("hello", locale = "es_es")
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 = "en")
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 = "pt")
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 = "es")
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 = "cn")
113
+ result = self.app.to_locale("bye", locale="cn")
123
114
  self.assertEqual(result, "bye")
124
115
 
125
- self.app._register_bundle(dict(bye = "Bye"), "en_us")
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 = "en_us")
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 = "pt_pt")
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 = "pt_pt", fallback = False)
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 = "en_us")
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 = "en_us")
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 = "pt_pt")
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 = "pt_pt")
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 = "Hello"), "en_us", context = "extra")
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 = "extra")
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 = "other")
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 = "extra")
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 = "other")
158
+ result = self.app.has_locale("hello", context="other")
168
159
  self.assertEqual(result, False)
169
160
 
170
- self.app._unregister_bundle(dict(hello = "Hello"), "en_us", context = "extra")
161
+ self.app._unregister_bundle(dict(hello="Hello"), "en_us", context="extra")
171
162
 
172
- result = self.app.has_locale("hello", context = "extra")
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 = ["john doe"],
180
- message = [""],
181
- valid_email = ["john@doe.com"],
182
- invalid_email = ["john"],
183
- valid_length = ["1234"],
184
- invalid_length = ["12345"]
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 = True)
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 = True,
206
- not_empty = True,
207
- validation = ((appier.string_lt, 5),)
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 = True, not_empty = True)
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 = True,
226
- not_empty = True,
227
- validation = (appier.is_email,)
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 = True,
236
- not_empty = True,
237
- validation = ((appier.string_lt, 5),)
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"): return
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(appier.legacy.bytes("你好世界", encoding = "utf-8"))
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"): return
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 = "utf-8"))
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 = "query_string")
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 = dict(query = "query_string"))
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 = "hello.txt")
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 = "hello.txt", compress = "gzip")
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"): return
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 = "hello")
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 = "hello\n")
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 = "hello world")
318
+ result = self.app.template(template, message="hello world")
327
319
  self.assertEqual(result, "hello&nbsp;world")
328
320
 
329
321
  def test_unset_filter(self):
330
322
  if not self.app.jinja:
331
- if not hasattr(self, "skipTest"): return
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 = "hello")
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 = "hello")
336
+ result = self.app.template(template, message="hello")
344
337
  self.assertEqual(result, appier.legacy.u("hello"))
345
338
 
346
- template = appier.Template("{{ message|unset(default = 'world', empty = True) }}")
347
- result = self.app.template(template, message = "")
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 = "hello")
344
+ result = self.app.template(template, message="hello")
350
345
  self.assertEqual(result, appier.legacy.u("hello"))
351
346
 
352
- template = appier.Template("{{ message|unset(default = 'world', extra = ('',)) }}")
353
- result = self.app.template(template, message = "")
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 = "hello")
352
+ result = self.app.template(template, message="hello")
356
353
  self.assertEqual(result, appier.legacy.u("hello"))
357
354
 
358
- template = appier.Template("{{ message|unset(default = 'world', extra = ('', 't')) }}")
359
- result = self.app.template(template, message = "t")
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 = "hello")
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"): return
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
- "hello" : appier.legacy.u("olá"),
371
- "world" : appier.legacy.u("mundo"),
372
- }, "pt_pt")
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 = "pt_pt", message = "hello")
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 = "en_us", message = "hello")
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 = "pt_pt")
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 = "en_us")
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-2022 Hive Solutions Lda.
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
- __version__ = "1.0.0"
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 = -1)
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 = 3600)
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 = time.time() - 1)
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 = time.time() + 3600)
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 = -1)
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 = 3600)
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 = time.time() - 1)
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 = time.time() + 3600)
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"): return
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 = -1)
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 = 3600)
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 = time.time() - 1)
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 = time.time() + 3600)
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 = True)
162
+ cache = appier.RedisCache.new(hash=True)
171
163
  except Exception:
172
- if not hasattr(self, "skipTest"): return
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 = -1)
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 = 3600)
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 = time.time() - 1)
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 = time.time() + 3600)
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 = -1)
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 = 3600)
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 = time.time() - 1)
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 = time.time() + 3600)
226
+ cache.set_item("first", 1, expires=time.time() + 3600)
234
227
 
235
228
  self.assertEqual(cache["first"], 1)
236
229