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/http.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 threading
|
|
|
42
33
|
|
|
43
34
|
import appier
|
|
44
35
|
|
|
45
|
-
class HTTPTest(unittest.TestCase):
|
|
46
36
|
|
|
37
|
+
class HTTPTest(unittest.TestCase):
|
|
47
38
|
def setUp(self):
|
|
48
39
|
unittest.TestCase.setUp(self)
|
|
49
40
|
self.httpbin = appier.conf("HTTPBIN", "httpbin.org")
|
|
@@ -62,7 +53,9 @@ class HTTPTest(unittest.TestCase):
|
|
|
62
53
|
self.assertEqual(result_single, result_multiple)
|
|
63
54
|
|
|
64
55
|
def test__parse_url(self):
|
|
65
|
-
url, scheme, host, authorization, params = appier.http._parse_url(
|
|
56
|
+
url, scheme, host, authorization, params = appier.http._parse_url(
|
|
57
|
+
"http://hive.pt/"
|
|
58
|
+
)
|
|
66
59
|
|
|
67
60
|
self.assertEqual(url, "http://hive.pt:80/")
|
|
68
61
|
self.assertEqual(scheme, "http")
|
|
@@ -70,7 +63,9 @@ class HTTPTest(unittest.TestCase):
|
|
|
70
63
|
self.assertEqual(authorization, None)
|
|
71
64
|
self.assertEqual(params, {})
|
|
72
65
|
|
|
73
|
-
url, scheme, host, authorization, params = appier.http._parse_url(
|
|
66
|
+
url, scheme, host, authorization, params = appier.http._parse_url(
|
|
67
|
+
"http://username@hive.pt/"
|
|
68
|
+
)
|
|
74
69
|
|
|
75
70
|
self.assertEqual(url, "http://hive.pt:80/")
|
|
76
71
|
self.assertEqual(scheme, "http")
|
|
@@ -78,7 +73,9 @@ class HTTPTest(unittest.TestCase):
|
|
|
78
73
|
self.assertEqual(authorization, None)
|
|
79
74
|
self.assertEqual(params, {})
|
|
80
75
|
|
|
81
|
-
url, scheme, host, authorization, params = appier.http._parse_url(
|
|
76
|
+
url, scheme, host, authorization, params = appier.http._parse_url(
|
|
77
|
+
"http://username:password@hive.pt/"
|
|
78
|
+
)
|
|
82
79
|
|
|
83
80
|
self.assertEqual(url, "http://hive.pt:80/")
|
|
84
81
|
self.assertEqual(scheme, "http")
|
|
@@ -86,7 +83,9 @@ class HTTPTest(unittest.TestCase):
|
|
|
86
83
|
self.assertEqual(authorization, "dXNlcm5hbWU6cGFzc3dvcmQ=")
|
|
87
84
|
self.assertEqual(params, {})
|
|
88
85
|
|
|
89
|
-
url, scheme, host, authorization, params = appier.http._parse_url(
|
|
86
|
+
url, scheme, host, authorization, params = appier.http._parse_url(
|
|
87
|
+
"http://username:password@hive.pt/hello/world"
|
|
88
|
+
)
|
|
90
89
|
|
|
91
90
|
self.assertEqual(url, "http://hive.pt:80/hello/world")
|
|
92
91
|
self.assertEqual(scheme, "http")
|
|
@@ -94,20 +93,22 @@ class HTTPTest(unittest.TestCase):
|
|
|
94
93
|
self.assertEqual(authorization, "dXNlcm5hbWU6cGFzc3dvcmQ=")
|
|
95
94
|
self.assertEqual(params, {})
|
|
96
95
|
|
|
97
|
-
url, scheme, host, authorization, params = appier.http._parse_url(
|
|
96
|
+
url, scheme, host, authorization, params = appier.http._parse_url(
|
|
97
|
+
"http://username:password@hive.pt/hello/world?hello=world"
|
|
98
|
+
)
|
|
98
99
|
|
|
99
100
|
self.assertEqual(url, "http://hive.pt:80/hello/world")
|
|
100
101
|
self.assertEqual(scheme, "http")
|
|
101
102
|
self.assertEqual(host, "hive.pt")
|
|
102
103
|
self.assertEqual(authorization, "dXNlcm5hbWU6cGFzc3dvcmQ=")
|
|
103
|
-
self.assertEqual(params, dict(hello
|
|
104
|
+
self.assertEqual(params, dict(hello=["world"]))
|
|
104
105
|
|
|
105
106
|
def test_redirect(self):
|
|
106
107
|
_data, response = appier.get(
|
|
107
|
-
"https://%s/redirect-to" % self.httpbin
|
|
108
|
-
params
|
|
109
|
-
handle
|
|
110
|
-
redirect
|
|
108
|
+
"https://%s/redirect-to" % self.httpbin,
|
|
109
|
+
params=dict(url="https://%s/" % self.httpbin),
|
|
110
|
+
handle=True,
|
|
111
|
+
redirect=True,
|
|
111
112
|
)
|
|
112
113
|
|
|
113
114
|
code = response.getcode()
|
|
@@ -117,8 +118,8 @@ class HTTPTest(unittest.TestCase):
|
|
|
117
118
|
quoted = appier.legacy.quote("https://%s/" % self.httpbin)
|
|
118
119
|
_data, response = appier.get(
|
|
119
120
|
"https://%s/redirect-to?url=%s" % (self.httpbin, quoted),
|
|
120
|
-
handle
|
|
121
|
-
redirect
|
|
121
|
+
handle=True,
|
|
122
|
+
redirect=True,
|
|
122
123
|
)
|
|
123
124
|
|
|
124
125
|
code = response.getcode()
|
|
@@ -126,9 +127,7 @@ class HTTPTest(unittest.TestCase):
|
|
|
126
127
|
self.assertEqual(code, 200)
|
|
127
128
|
|
|
128
129
|
_data, response = appier.get(
|
|
129
|
-
"https://%s/relative-redirect/2" % self.httpbin ,
|
|
130
|
-
handle = True,
|
|
131
|
-
redirect = True
|
|
130
|
+
"https://%s/relative-redirect/2" % self.httpbin, handle=True, redirect=True
|
|
132
131
|
)
|
|
133
132
|
|
|
134
133
|
code = response.getcode()
|
|
@@ -140,17 +139,14 @@ class HTTPTest(unittest.TestCase):
|
|
|
140
139
|
BaseException,
|
|
141
140
|
lambda: appier.get(
|
|
142
141
|
"https://%s/delay/3" % self.httpbin,
|
|
143
|
-
handle
|
|
144
|
-
redirect
|
|
145
|
-
timeout
|
|
146
|
-
)
|
|
142
|
+
handle=True,
|
|
143
|
+
redirect=True,
|
|
144
|
+
timeout=1,
|
|
145
|
+
),
|
|
147
146
|
)
|
|
148
147
|
|
|
149
148
|
data, response = appier.get(
|
|
150
|
-
"https://%s/delay/1" % self.httpbin,
|
|
151
|
-
handle = True,
|
|
152
|
-
redirect = True,
|
|
153
|
-
timeout = 30
|
|
149
|
+
"https://%s/delay/1" % self.httpbin, handle=True, redirect=True, timeout=30
|
|
154
150
|
)
|
|
155
151
|
|
|
156
152
|
code = response.getcode()
|
|
@@ -166,10 +162,7 @@ class HTTPTest(unittest.TestCase):
|
|
|
166
162
|
self.assertEqual(len(file.data) > 100, True)
|
|
167
163
|
self.assertEqual(len(file.data_b64) > 100, True)
|
|
168
164
|
|
|
169
|
-
file = appier.get_f(
|
|
170
|
-
"https://%s/image/png" % self.httpbin,
|
|
171
|
-
name = "dummy"
|
|
172
|
-
)
|
|
165
|
+
file = appier.get_f("https://%s/image/png" % self.httpbin, name="dummy")
|
|
173
166
|
|
|
174
167
|
self.assertEqual(file.file_name, "dummy")
|
|
175
168
|
self.assertEqual(file.mime, "image/png")
|
|
@@ -177,16 +170,13 @@ class HTTPTest(unittest.TestCase):
|
|
|
177
170
|
self.assertEqual(len(file.data_b64) > 100, True)
|
|
178
171
|
|
|
179
172
|
def test_generator(self):
|
|
180
|
-
def text_g(message
|
|
173
|
+
def text_g(message=[b"hello", b" ", b"world"]):
|
|
181
174
|
yield sum(len(value) for value in message)
|
|
182
175
|
for value in message:
|
|
183
176
|
yield value
|
|
184
177
|
|
|
185
178
|
data, response = appier.post(
|
|
186
|
-
"https://%s/post" % self.httpbin,
|
|
187
|
-
data = text_g(),
|
|
188
|
-
handle = True,
|
|
189
|
-
reuse = False
|
|
179
|
+
"https://%s/post" % self.httpbin, data=text_g(), handle=True, reuse=False
|
|
190
180
|
)
|
|
191
181
|
|
|
192
182
|
code = response.getcode()
|
|
@@ -197,9 +187,9 @@ class HTTPTest(unittest.TestCase):
|
|
|
197
187
|
def test_file(self):
|
|
198
188
|
data, response = appier.post(
|
|
199
189
|
"https://%s/post" % self.httpbin,
|
|
200
|
-
data
|
|
201
|
-
handle
|
|
202
|
-
reuse
|
|
190
|
+
data=appier.legacy.BytesIO(b"hello world"),
|
|
191
|
+
handle=True,
|
|
192
|
+
reuse=False,
|
|
203
193
|
)
|
|
204
194
|
|
|
205
195
|
code = response.getcode()
|
|
@@ -218,16 +208,16 @@ class HTTPTest(unittest.TestCase):
|
|
|
218
208
|
def generate(index):
|
|
219
209
|
def caller():
|
|
220
210
|
data, response = appier.get(
|
|
221
|
-
"https://%s/ip" % self.httpbin,
|
|
222
|
-
handle = True
|
|
211
|
+
"https://%s/ip" % self.httpbin, handle=True
|
|
223
212
|
)
|
|
224
213
|
result = results[index]
|
|
225
214
|
result["data"] = data
|
|
226
215
|
result["response"] = response
|
|
216
|
+
|
|
227
217
|
return caller
|
|
228
218
|
|
|
229
219
|
callable = generate(index)
|
|
230
|
-
thread = threading.Thread(target
|
|
220
|
+
thread = threading.Thread(target=callable, name="TestMultithread")
|
|
231
221
|
thread.start()
|
|
232
222
|
threads.append(thread)
|
|
233
223
|
|
|
@@ -241,12 +231,10 @@ class HTTPTest(unittest.TestCase):
|
|
|
241
231
|
|
|
242
232
|
def test_error(self):
|
|
243
233
|
self.assertRaises(
|
|
244
|
-
appier.HTTPError,
|
|
245
|
-
lambda: appier.get("https://%s/status/404" % self.httpbin)
|
|
234
|
+
appier.HTTPError, lambda: appier.get("https://%s/status/404" % self.httpbin)
|
|
246
235
|
)
|
|
247
236
|
|
|
248
237
|
def test_invalid(self):
|
|
249
238
|
self.assertRaises(
|
|
250
|
-
BaseException,
|
|
251
|
-
lambda: appier.get("https://invalidlargedomain.org/")
|
|
239
|
+
BaseException, lambda: appier.get("https://invalidlargedomain.org/")
|
|
252
240
|
)
|
appier/test/legacy.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,24 +33,25 @@ import unittest
|
|
|
42
33
|
|
|
43
34
|
import appier
|
|
44
35
|
|
|
45
|
-
class LegacyTest(unittest.TestCase):
|
|
46
36
|
|
|
37
|
+
class LegacyTest(unittest.TestCase):
|
|
47
38
|
def test_bytes(self):
|
|
48
39
|
value = appier.legacy.u("hello")
|
|
49
40
|
value = appier.legacy.bytes(value)
|
|
50
|
-
if appier.legacy.PYTHON_3:
|
|
51
|
-
|
|
41
|
+
if appier.legacy.PYTHON_3:
|
|
42
|
+
self.assertEqual(type(value), bytes)
|
|
43
|
+
else:
|
|
44
|
+
self.assertEqual(type(value), appier.legacy.UNICODE)
|
|
52
45
|
|
|
53
46
|
value = appier.legacy.u("hello")
|
|
54
|
-
value = appier.legacy.bytes(value, force
|
|
47
|
+
value = appier.legacy.bytes(value, force=True)
|
|
55
48
|
self.assertEqual(type(value), bytes)
|
|
56
49
|
|
|
57
50
|
value = appier.legacy.u("你好")
|
|
58
51
|
self.assertRaises(
|
|
59
|
-
UnicodeEncodeError,
|
|
60
|
-
lambda: appier.legacy.bytes(value, force = True)
|
|
52
|
+
UnicodeEncodeError, lambda: appier.legacy.bytes(value, force=True)
|
|
61
53
|
)
|
|
62
|
-
value = appier.legacy.bytes(value, encoding
|
|
54
|
+
value = appier.legacy.bytes(value, encoding="utf-8", force=True)
|
|
63
55
|
self.assertEqual(type(value), bytes)
|
|
64
56
|
self.assertEqual(value, b"\xe4\xbd\xa0\xe5\xa5\xbd")
|
|
65
57
|
|
|
@@ -67,21 +59,21 @@ class LegacyTest(unittest.TestCase):
|
|
|
67
59
|
value = appier.legacy.str(b"value")
|
|
68
60
|
self.assertEqual(type(value), str)
|
|
69
61
|
|
|
70
|
-
value = appier.legacy.str(b"value", force
|
|
62
|
+
value = appier.legacy.str(b"value", force=True)
|
|
71
63
|
self.assertEqual(type(value), str)
|
|
72
64
|
|
|
73
65
|
def test_u(self):
|
|
74
66
|
value = appier.legacy.u(b"hello")
|
|
75
|
-
if appier.legacy.PYTHON_3:
|
|
76
|
-
|
|
67
|
+
if appier.legacy.PYTHON_3:
|
|
68
|
+
self.assertEqual(type(value), bytes)
|
|
69
|
+
else:
|
|
70
|
+
self.assertEqual(type(value), appier.legacy.UNICODE)
|
|
77
71
|
|
|
78
|
-
value = appier.legacy.u(b"hello", force
|
|
72
|
+
value = appier.legacy.u(b"hello", force=True)
|
|
79
73
|
self.assertEqual(type(value), appier.legacy.UNICODE)
|
|
80
74
|
|
|
81
75
|
value = appier.legacy.u(
|
|
82
|
-
b"\xe4\xbd\xa0\xe5\xa5\xbd",
|
|
83
|
-
encoding = "utf-8",
|
|
84
|
-
force = True
|
|
76
|
+
b"\xe4\xbd\xa0\xe5\xa5\xbd", encoding="utf-8", force=True
|
|
85
77
|
)
|
|
86
78
|
self.assertEqual(type(value), appier.legacy.UNICODE)
|
|
87
79
|
self.assertEqual(value, appier.legacy.u("你好"))
|
|
@@ -108,7 +100,7 @@ class LegacyTest(unittest.TestCase):
|
|
|
108
100
|
self.assertEqual(value, "1")
|
|
109
101
|
|
|
110
102
|
def test_argspec(self):
|
|
111
|
-
hello_world = lambda message, extra
|
|
103
|
+
hello_world = lambda message, extra="": "hello world %s" % message
|
|
112
104
|
|
|
113
105
|
spec = appier.legacy.getargspec(hello_world)
|
|
114
106
|
self.assertEqual(spec[0], ["message", "extra"])
|
|
@@ -127,9 +119,7 @@ class LegacyTest(unittest.TestCase):
|
|
|
127
119
|
value = appier.legacy.quote("你好世界")
|
|
128
120
|
self.assertEqual(value, "%E4%BD%A0%E5%A5%BD%E4%B8%96%E7%95%8C")
|
|
129
121
|
|
|
130
|
-
value = appier.legacy.quote(
|
|
131
|
-
appier.legacy.bytes("你好世界", encoding = "utf-8")
|
|
132
|
-
)
|
|
122
|
+
value = appier.legacy.quote(appier.legacy.bytes("你好世界", encoding="utf-8"))
|
|
133
123
|
self.assertEqual(value, "%E4%BD%A0%E5%A5%BD%E4%B8%96%E7%95%8C")
|
|
134
124
|
|
|
135
125
|
def test_unquote(self):
|
|
@@ -144,7 +134,7 @@ class LegacyTest(unittest.TestCase):
|
|
|
144
134
|
|
|
145
135
|
method = lambda: appier.legacy.unquote(
|
|
146
136
|
appier.legacy.bytes("%E4%BD%A0%E5%A5%BD%E4%B8%96%E7%95%8C"),
|
|
147
|
-
encoding
|
|
137
|
+
encoding="utf-8",
|
|
148
138
|
)
|
|
149
139
|
if not appier.legacy.PYTHON_3 or not appier.legacy.PYTHON_39:
|
|
150
140
|
self.assertRaises(TypeError, method)
|
appier/test/log.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 LogTest(unittest.TestCase):
|
|
46
36
|
|
|
37
|
+
class LogTest(unittest.TestCase):
|
|
47
38
|
def test_memory_handler(self):
|
|
48
39
|
memory_handler = appier.MemoryHandler()
|
|
49
40
|
formatter = logging.Formatter("%(message)s")
|
|
@@ -54,10 +45,7 @@ class LogTest(unittest.TestCase):
|
|
|
54
45
|
self.assertEqual(latest, [])
|
|
55
46
|
|
|
56
47
|
record = logging.makeLogRecord(
|
|
57
|
-
dict(
|
|
58
|
-
msg = "hello world",
|
|
59
|
-
levelname = logging.getLevelName(logging.INFO)
|
|
60
|
-
)
|
|
48
|
+
dict(msg="hello world", levelname=logging.getLevelName(logging.INFO))
|
|
61
49
|
)
|
|
62
50
|
memory_handler.emit(record)
|
|
63
51
|
latest = memory_handler.get_latest()
|
|
@@ -66,10 +54,7 @@ class LogTest(unittest.TestCase):
|
|
|
66
54
|
self.assertEqual(latest, ["hello world"])
|
|
67
55
|
|
|
68
56
|
record = logging.makeLogRecord(
|
|
69
|
-
dict(
|
|
70
|
-
msg = "hello world 2",
|
|
71
|
-
levelname = logging.getLevelName(logging.ERROR)
|
|
72
|
-
)
|
|
57
|
+
dict(msg="hello world 2", levelname=logging.getLevelName(logging.ERROR))
|
|
73
58
|
)
|
|
74
59
|
memory_handler.emit(record)
|
|
75
60
|
latest = memory_handler.get_latest()
|
|
@@ -77,22 +62,22 @@ class LogTest(unittest.TestCase):
|
|
|
77
62
|
self.assertEqual(len(latest), 2)
|
|
78
63
|
self.assertEqual(latest, ["hello world 2", "hello world"])
|
|
79
64
|
|
|
80
|
-
latest = memory_handler.get_latest(level
|
|
65
|
+
latest = memory_handler.get_latest(level=logging.ERROR)
|
|
81
66
|
|
|
82
67
|
self.assertEqual(len(latest), 1)
|
|
83
68
|
self.assertEqual(latest, ["hello world 2"])
|
|
84
69
|
|
|
85
|
-
latest = memory_handler.get_latest(level
|
|
70
|
+
latest = memory_handler.get_latest(level=logging.CRITICAL)
|
|
86
71
|
|
|
87
72
|
self.assertEqual(len(latest), 0)
|
|
88
73
|
self.assertEqual(latest, [])
|
|
89
74
|
|
|
90
|
-
latest = memory_handler.get_latest(level
|
|
75
|
+
latest = memory_handler.get_latest(level=logging.INFO)
|
|
91
76
|
|
|
92
77
|
self.assertEqual(len(latest), 2)
|
|
93
78
|
self.assertEqual(latest, ["hello world 2", "hello world"])
|
|
94
79
|
|
|
95
|
-
latest = memory_handler.get_latest(count
|
|
80
|
+
latest = memory_handler.get_latest(count=1, level=logging.INFO)
|
|
96
81
|
|
|
97
82
|
self.assertEqual(len(latest), 1)
|
|
98
83
|
self.assertEqual(latest, ["hello world 2"])
|
|
@@ -107,23 +92,17 @@ class LogTest(unittest.TestCase):
|
|
|
107
92
|
self.assertEqual(latest, [])
|
|
108
93
|
|
|
109
94
|
record = logging.makeLogRecord(
|
|
110
|
-
dict(
|
|
111
|
-
msg = "hello world",
|
|
112
|
-
levelname = logging.getLevelName(logging.INFO)
|
|
113
|
-
)
|
|
95
|
+
dict(msg="hello world", levelname=logging.getLevelName(logging.INFO))
|
|
114
96
|
)
|
|
115
97
|
memory_handler.emit(record)
|
|
116
98
|
record = logging.makeLogRecord(
|
|
117
|
-
dict(
|
|
118
|
-
msg = "hello world 2",
|
|
119
|
-
levelname = logging.getLevelName(logging.INFO)
|
|
120
|
-
)
|
|
99
|
+
dict(msg="hello world 2", levelname=logging.getLevelName(logging.INFO))
|
|
121
100
|
)
|
|
122
101
|
memory_handler.emit(record)
|
|
123
102
|
|
|
124
103
|
file = appier.legacy.BytesIO()
|
|
125
104
|
|
|
126
|
-
memory_handler.flush_to_file(file, clear
|
|
105
|
+
memory_handler.flush_to_file(file, clear=False)
|
|
127
106
|
|
|
128
107
|
file.seek(0)
|
|
129
108
|
contents = file.read()
|
|
@@ -132,12 +111,12 @@ class LogTest(unittest.TestCase):
|
|
|
132
111
|
|
|
133
112
|
file = appier.legacy.BytesIO()
|
|
134
113
|
|
|
135
|
-
memory_handler.flush_to_file(file, reverse
|
|
114
|
+
memory_handler.flush_to_file(file, reverse=False)
|
|
136
115
|
|
|
137
116
|
file.seek(0)
|
|
138
117
|
contents = file.read()
|
|
139
118
|
|
|
140
119
|
self.assertEqual(contents, b"hello world 2\nhello world\n")
|
|
141
120
|
|
|
142
|
-
latest = memory_handler.get_latest(count
|
|
121
|
+
latest = memory_handler.get_latest(count=1)
|
|
143
122
|
self.assertEqual(len(latest), 0)
|
appier/test/mock.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"
|
|
@@ -39,110 +30,51 @@ __license__ = "Apache License, Version 2.0"
|
|
|
39
30
|
|
|
40
31
|
import appier
|
|
41
32
|
|
|
42
|
-
class Person(appier.Model):
|
|
43
33
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
index = True,
|
|
47
|
-
increment = True,
|
|
48
|
-
default = True
|
|
49
|
-
)
|
|
34
|
+
class Person(appier.Model):
|
|
35
|
+
identifier = appier.field(type=int, index=True, increment=True, default=True)
|
|
50
36
|
|
|
51
|
-
identifier_safe = appier.field(
|
|
52
|
-
type = int,
|
|
53
|
-
index = True,
|
|
54
|
-
increment = True,
|
|
55
|
-
safe = True
|
|
56
|
-
)
|
|
37
|
+
identifier_safe = appier.field(type=int, index=True, increment=True, safe=True)
|
|
57
38
|
|
|
58
39
|
name = appier.field()
|
|
59
40
|
|
|
60
|
-
age = appier.field(
|
|
61
|
-
type = int
|
|
62
|
-
)
|
|
41
|
+
age = appier.field(type=int)
|
|
63
42
|
|
|
64
|
-
info = appier.field(
|
|
65
|
-
type = dict
|
|
66
|
-
)
|
|
43
|
+
info = appier.field(type=dict)
|
|
67
44
|
|
|
68
45
|
father = appier.field(
|
|
69
|
-
type
|
|
70
|
-
"Person",
|
|
71
|
-
name = "identifier",
|
|
72
|
-
dumpall = True
|
|
73
|
-
)
|
|
46
|
+
type=appier.reference("Person", name="identifier", dumpall=True)
|
|
74
47
|
)
|
|
75
48
|
|
|
76
|
-
brother = appier.field(
|
|
77
|
-
type = appier.reference(
|
|
78
|
-
"Person",
|
|
79
|
-
name = "identifier"
|
|
80
|
-
)
|
|
81
|
-
)
|
|
49
|
+
brother = appier.field(type=appier.reference("Person", name="identifier"))
|
|
82
50
|
|
|
83
|
-
car = appier.field(
|
|
84
|
-
type = appier.reference(
|
|
85
|
-
"Car",
|
|
86
|
-
name = "identifier"
|
|
87
|
-
),
|
|
88
|
-
eager = True
|
|
89
|
-
)
|
|
51
|
+
car = appier.field(type=appier.reference("Car", name="identifier"), eager=True)
|
|
90
52
|
|
|
91
|
-
cats = appier.field(
|
|
92
|
-
type = appier.references(
|
|
93
|
-
"Cat",
|
|
94
|
-
name = "identifier"
|
|
95
|
-
)
|
|
96
|
-
)
|
|
53
|
+
cats = appier.field(type=appier.references("Cat", name="identifier"))
|
|
97
54
|
|
|
98
55
|
@classmethod
|
|
99
56
|
def validate(cls):
|
|
100
57
|
return super(Person, cls).validate() + [
|
|
101
58
|
appier.not_null("name"),
|
|
102
59
|
appier.not_empty("name"),
|
|
103
|
-
appier.not_duplicate("name", cls._name())
|
|
60
|
+
appier.not_duplicate("name", cls._name()),
|
|
104
61
|
]
|
|
105
62
|
|
|
63
|
+
|
|
106
64
|
class Cat(appier.Model):
|
|
65
|
+
identifier = appier.field(type=int, index=True, increment=True, default=True)
|
|
107
66
|
|
|
108
|
-
|
|
109
|
-
type = int,
|
|
110
|
-
index = True,
|
|
111
|
-
increment = True,
|
|
112
|
-
default = True
|
|
113
|
-
)
|
|
114
|
-
|
|
115
|
-
identifier_safe = appier.field(
|
|
116
|
-
type = int,
|
|
117
|
-
index = True,
|
|
118
|
-
increment = True,
|
|
119
|
-
safe = True
|
|
120
|
-
)
|
|
67
|
+
identifier_safe = appier.field(type=int, index=True, increment=True, safe=True)
|
|
121
68
|
|
|
122
69
|
name = appier.field()
|
|
123
70
|
|
|
124
|
-
friend = appier.field(
|
|
125
|
-
type = appier.reference(
|
|
126
|
-
"Cat",
|
|
127
|
-
name = "identifier"
|
|
128
|
-
)
|
|
129
|
-
)
|
|
71
|
+
friend = appier.field(type=appier.reference("Cat", name="identifier"))
|
|
130
72
|
|
|
131
|
-
class Car(appier.Model):
|
|
132
73
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
index = True,
|
|
136
|
-
increment = True,
|
|
137
|
-
default = True
|
|
138
|
-
)
|
|
74
|
+
class Car(appier.Model):
|
|
75
|
+
identifier = appier.field(type=int, index=True, increment=True, default=True)
|
|
139
76
|
|
|
140
|
-
identifier_safe = appier.field(
|
|
141
|
-
type = int,
|
|
142
|
-
index = True,
|
|
143
|
-
increment = True,
|
|
144
|
-
safe = True
|
|
145
|
-
)
|
|
77
|
+
identifier_safe = appier.field(type=int, index=True, increment=True, safe=True)
|
|
146
78
|
|
|
147
79
|
name = appier.field()
|
|
148
80
|
|
|
@@ -151,53 +83,25 @@ class Car(appier.Model):
|
|
|
151
83
|
variant = appier.field()
|
|
152
84
|
|
|
153
85
|
garage = appier.field(
|
|
154
|
-
type
|
|
155
|
-
"Garage",
|
|
156
|
-
name = "identifier"
|
|
157
|
-
),
|
|
158
|
-
eager = True
|
|
86
|
+
type=appier.reference("Garage", name="identifier"), eager=True
|
|
159
87
|
)
|
|
160
88
|
|
|
161
|
-
class Garage(appier.Model):
|
|
162
89
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
index = True,
|
|
166
|
-
increment = True,
|
|
167
|
-
default = True
|
|
168
|
-
)
|
|
90
|
+
class Garage(appier.Model):
|
|
91
|
+
identifier = appier.field(type=int, index=True, increment=True, default=True)
|
|
169
92
|
|
|
170
|
-
identifier_safe = appier.field(
|
|
171
|
-
type = int,
|
|
172
|
-
index = True,
|
|
173
|
-
increment = True,
|
|
174
|
-
safe = True
|
|
175
|
-
)
|
|
93
|
+
identifier_safe = appier.field(type=int, index=True, increment=True, safe=True)
|
|
176
94
|
|
|
177
95
|
name = appier.field()
|
|
178
96
|
|
|
179
97
|
address = appier.field(
|
|
180
|
-
type
|
|
181
|
-
"Address",
|
|
182
|
-
name = "identifier"
|
|
183
|
-
),
|
|
184
|
-
eager = True
|
|
98
|
+
type=appier.reference("Address", name="identifier"), eager=True
|
|
185
99
|
)
|
|
186
100
|
|
|
187
|
-
class Address(appier.Model):
|
|
188
101
|
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
index = True,
|
|
192
|
-
increment = True,
|
|
193
|
-
default = True
|
|
194
|
-
)
|
|
102
|
+
class Address(appier.Model):
|
|
103
|
+
identifier = appier.field(type=int, index=True, increment=True, default=True)
|
|
195
104
|
|
|
196
|
-
identifier_safe = appier.field(
|
|
197
|
-
type = int,
|
|
198
|
-
index = True,
|
|
199
|
-
increment = True,
|
|
200
|
-
safe = True
|
|
201
|
-
)
|
|
105
|
+
identifier_safe = appier.field(type=int, index=True, increment=True, safe=True)
|
|
202
106
|
|
|
203
107
|
street = appier.field()
|