appier 1.34.6__tar.gz → 1.34.7__tar.gz
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-1.34.6/src/appier.egg-info → appier-1.34.7}/PKG-INFO +1 -1
- {appier-1.34.6 → appier-1.34.7}/setup.py +1 -1
- {appier-1.34.6 → appier-1.34.7}/src/appier/__init__.py +1 -1
- {appier-1.34.6 → appier-1.34.7}/src/appier/async_neo.py +2 -2
- {appier-1.34.6 → appier-1.34.7}/src/appier/async_old.py +1 -1
- {appier-1.34.6 → appier-1.34.7}/src/appier/base.py +5 -2
- {appier-1.34.6 → appier-1.34.7}/src/appier/data.py +2 -0
- {appier-1.34.6 → appier-1.34.7}/src/appier/model.py +7 -2
- {appier-1.34.6 → appier-1.34.7}/src/appier/test/data.py +10 -0
- appier-1.34.7/src/appier/test/error_handler.py +136 -0
- appier-1.34.7/src/appier/test/exception_handler.py +143 -0
- {appier-1.34.6 → appier-1.34.7}/src/appier/test/http.py +24 -0
- {appier-1.34.6 → appier-1.34.7}/src/appier/util.py +9 -4
- {appier-1.34.6 → appier-1.34.7/src/appier.egg-info}/PKG-INFO +1 -1
- {appier-1.34.6 → appier-1.34.7}/src/appier.egg-info/SOURCES.txt +2 -0
- {appier-1.34.6 → appier-1.34.7}/MANIFEST.in +0 -0
- {appier-1.34.6 → appier-1.34.7}/README.rst +0 -0
- {appier-1.34.6 → appier-1.34.7}/pyproject.toml +0 -0
- {appier-1.34.6 → appier-1.34.7}/setup.cfg +0 -0
- {appier-1.34.6 → appier-1.34.7}/src/appier/amqp.py +0 -0
- {appier-1.34.6 → appier-1.34.7}/src/appier/api.py +0 -0
- {appier-1.34.6 → appier-1.34.7}/src/appier/asgi.py +0 -0
- {appier-1.34.6 → appier-1.34.7}/src/appier/asynchronous.py +0 -0
- {appier-1.34.6 → appier-1.34.7}/src/appier/asynchronous.pyi +0 -0
- {appier-1.34.6 → appier-1.34.7}/src/appier/base.pyi +0 -0
- {appier-1.34.6 → appier-1.34.7}/src/appier/bus.py +0 -0
- {appier-1.34.6 → appier-1.34.7}/src/appier/bus.pyi +0 -0
- {appier-1.34.6 → appier-1.34.7}/src/appier/cache.py +0 -0
- {appier-1.34.6 → appier-1.34.7}/src/appier/cache.pyi +0 -0
- {appier-1.34.6 → appier-1.34.7}/src/appier/common.py +0 -0
- {appier-1.34.6 → appier-1.34.7}/src/appier/component.py +0 -0
- {appier-1.34.6 → appier-1.34.7}/src/appier/component.pyi +0 -0
- {appier-1.34.6 → appier-1.34.7}/src/appier/compress.py +0 -0
- {appier-1.34.6 → appier-1.34.7}/src/appier/config.py +0 -0
- {appier-1.34.6 → appier-1.34.7}/src/appier/controller.py +0 -0
- {appier-1.34.6 → appier-1.34.7}/src/appier/crypt.py +0 -0
- {appier-1.34.6 → appier-1.34.7}/src/appier/data.pyi +0 -0
- {appier-1.34.6 → appier-1.34.7}/src/appier/defines.py +0 -0
- {appier-1.34.6 → appier-1.34.7}/src/appier/exceptions.py +0 -0
- {appier-1.34.6 → appier-1.34.7}/src/appier/execution.py +0 -0
- {appier-1.34.6 → appier-1.34.7}/src/appier/export.py +0 -0
- {appier-1.34.6 → appier-1.34.7}/src/appier/extra.py +0 -0
- {appier-1.34.6 → appier-1.34.7}/src/appier/extra_neo.py +0 -0
- {appier-1.34.6 → appier-1.34.7}/src/appier/extra_old.py +0 -0
- {appier-1.34.6 → appier-1.34.7}/src/appier/geo.py +0 -0
- {appier-1.34.6 → appier-1.34.7}/src/appier/git.py +0 -0
- {appier-1.34.6 → appier-1.34.7}/src/appier/graph.py +0 -0
- {appier-1.34.6 → appier-1.34.7}/src/appier/http.py +0 -0
- {appier-1.34.6 → appier-1.34.7}/src/appier/legacy.py +0 -0
- {appier-1.34.6 → appier-1.34.7}/src/appier/log.py +0 -0
- {appier-1.34.6 → appier-1.34.7}/src/appier/meta.py +0 -0
- {appier-1.34.6 → appier-1.34.7}/src/appier/mock.py +0 -0
- {appier-1.34.6 → appier-1.34.7}/src/appier/model.pyi +0 -0
- {appier-1.34.6 → appier-1.34.7}/src/appier/model_a.py +0 -0
- {appier-1.34.6 → appier-1.34.7}/src/appier/mongo.py +0 -0
- {appier-1.34.6 → appier-1.34.7}/src/appier/observer.py +0 -0
- {appier-1.34.6 → appier-1.34.7}/src/appier/part.py +0 -0
- {appier-1.34.6 → appier-1.34.7}/src/appier/part.pyi +0 -0
- {appier-1.34.6 → appier-1.34.7}/src/appier/preferences.py +0 -0
- {appier-1.34.6 → appier-1.34.7}/src/appier/preferences.pyi +0 -0
- {appier-1.34.6 → appier-1.34.7}/src/appier/queuing.py +0 -0
- {appier-1.34.6 → appier-1.34.7}/src/appier/redisdb.py +0 -0
- {appier-1.34.6 → appier-1.34.7}/src/appier/request.py +0 -0
- {appier-1.34.6 → appier-1.34.7}/src/appier/res/static/css/base.css +0 -0
- {appier-1.34.6 → appier-1.34.7}/src/appier/res/static/images/favicon.ico +0 -0
- {appier-1.34.6 → appier-1.34.7}/src/appier/res/static/js/base.js +0 -0
- {appier-1.34.6 → appier-1.34.7}/src/appier/res/templates/error.html.tpl +0 -0
- {appier-1.34.6 → appier-1.34.7}/src/appier/res/templates/holder.html.tpl +0 -0
- {appier-1.34.6 → appier-1.34.7}/src/appier/res/templates/layout.html.tpl +0 -0
- {appier-1.34.6 → appier-1.34.7}/src/appier/scheduler.py +0 -0
- {appier-1.34.6 → appier-1.34.7}/src/appier/scheduler.pyi +0 -0
- {appier-1.34.6 → appier-1.34.7}/src/appier/serialize.py +0 -0
- {appier-1.34.6 → appier-1.34.7}/src/appier/session.py +0 -0
- {appier-1.34.6 → appier-1.34.7}/src/appier/session.pyi +0 -0
- {appier-1.34.6 → appier-1.34.7}/src/appier/settings.py +0 -0
- {appier-1.34.6 → appier-1.34.7}/src/appier/smtp.py +0 -0
- {appier-1.34.6 → appier-1.34.7}/src/appier/storage.py +0 -0
- {appier-1.34.6 → appier-1.34.7}/src/appier/structures.py +0 -0
- {appier-1.34.6 → appier-1.34.7}/src/appier/test/__init__.py +0 -0
- {appier-1.34.6 → appier-1.34.7}/src/appier/test/base.py +0 -0
- {appier-1.34.6 → appier-1.34.7}/src/appier/test/cache.py +0 -0
- {appier-1.34.6 → appier-1.34.7}/src/appier/test/config.py +0 -0
- {appier-1.34.6 → appier-1.34.7}/src/appier/test/crypt.py +0 -0
- {appier-1.34.6 → appier-1.34.7}/src/appier/test/exceptions.py +0 -0
- {appier-1.34.6 → appier-1.34.7}/src/appier/test/export.py +0 -0
- {appier-1.34.6 → appier-1.34.7}/src/appier/test/graph.py +0 -0
- {appier-1.34.6 → appier-1.34.7}/src/appier/test/legacy.py +0 -0
- {appier-1.34.6 → appier-1.34.7}/src/appier/test/log.py +0 -0
- {appier-1.34.6 → appier-1.34.7}/src/appier/test/mock.py +0 -0
- {appier-1.34.6 → appier-1.34.7}/src/appier/test/model.py +0 -0
- {appier-1.34.6 → appier-1.34.7}/src/appier/test/part.py +0 -0
- {appier-1.34.6 → appier-1.34.7}/src/appier/test/preferences.py +0 -0
- {appier-1.34.6 → appier-1.34.7}/src/appier/test/queuing.py +0 -0
- {appier-1.34.6 → appier-1.34.7}/src/appier/test/request.py +0 -0
- {appier-1.34.6 → appier-1.34.7}/src/appier/test/scheduler.py +0 -0
- {appier-1.34.6 → appier-1.34.7}/src/appier/test/serialize.py +0 -0
- {appier-1.34.6 → appier-1.34.7}/src/appier/test/session.py +0 -0
- {appier-1.34.6 → appier-1.34.7}/src/appier/test/smtp.py +0 -0
- {appier-1.34.6 → appier-1.34.7}/src/appier/test/structures.py +0 -0
- {appier-1.34.6 → appier-1.34.7}/src/appier/test/typesf.py +0 -0
- {appier-1.34.6 → appier-1.34.7}/src/appier/test/util.py +0 -0
- {appier-1.34.6 → appier-1.34.7}/src/appier/test/validation.py +0 -0
- {appier-1.34.6 → appier-1.34.7}/src/appier/typesf.py +0 -0
- {appier-1.34.6 → appier-1.34.7}/src/appier/validation.py +0 -0
- {appier-1.34.6 → appier-1.34.7}/src/appier.egg-info/dependency_links.txt +0 -0
- {appier-1.34.6 → appier-1.34.7}/src/appier.egg-info/not-zip-safe +0 -0
- {appier-1.34.6 → appier-1.34.7}/src/appier.egg-info/top_level.txt +0 -0
|
@@ -92,7 +92,7 @@ class CoroutineWrapper(object):
|
|
|
92
92
|
self._buffer.append(value)
|
|
93
93
|
|
|
94
94
|
|
|
95
|
-
class
|
|
95
|
+
class AsyncgenWrapper(object):
|
|
96
96
|
def __init__(self, async_iter):
|
|
97
97
|
self.async_iter = async_iter
|
|
98
98
|
self.current = None
|
|
@@ -149,7 +149,7 @@ def ensure_generator(value):
|
|
|
149
149
|
if hasattr(inspect, "isasyncgen") and inspect.isasyncgen(
|
|
150
150
|
value
|
|
151
151
|
): # @UndefinedVariable
|
|
152
|
-
return True,
|
|
152
|
+
return True, AsyncgenWrapper(value)
|
|
153
153
|
|
|
154
154
|
return False, value
|
|
155
155
|
|
|
@@ -94,7 +94,7 @@ NAME = "appier"
|
|
|
94
94
|
""" The name to be used to describe the framework while working
|
|
95
95
|
on its own environment, this is just a descriptive value """
|
|
96
96
|
|
|
97
|
-
VERSION = "1.34.
|
|
97
|
+
VERSION = "1.34.7"
|
|
98
98
|
""" The version of the framework that is currently installed
|
|
99
99
|
this value may be used for debugging/diagnostic purposes """
|
|
100
100
|
|
|
@@ -6138,7 +6138,10 @@ class App(
|
|
|
6138
6138
|
continue
|
|
6139
6139
|
if _handler[1] and not scope == _handler[1]:
|
|
6140
6140
|
continue
|
|
6141
|
-
if
|
|
6141
|
+
# if the handler has explicitly defined to handle JSON
|
|
6142
|
+
# contexts then it should only be used if the JSON flag
|
|
6143
|
+
# is also set to the same value as in the handler
|
|
6144
|
+
if not _handler[2] == None and not json == _handler[2]:
|
|
6142
6145
|
continue
|
|
6143
6146
|
handler = _handler
|
|
6144
6147
|
break
|
|
@@ -354,6 +354,7 @@ class Model(legacy.with_meta(meta.Ordered, observer.Observable, *EXTRA_CLS)):
|
|
|
354
354
|
safe=True,
|
|
355
355
|
build=False,
|
|
356
356
|
fill=True,
|
|
357
|
+
fill_safe=False,
|
|
357
358
|
new=True,
|
|
358
359
|
**kwargs
|
|
359
360
|
):
|
|
@@ -395,7 +396,11 @@ class Model(legacy.with_meta(meta.Ordered, observer.Observable, *EXTRA_CLS)):
|
|
|
395
396
|
injected into the resulting instance.
|
|
396
397
|
:type fill: bool
|
|
397
398
|
:param fill: If the various attributes of the model should be "filled"
|
|
398
|
-
with default values (avoiding empty values)
|
|
399
|
+
with default values (avoiding empty values), not going to be applied to
|
|
400
|
+
safe attributes.
|
|
401
|
+
:type fill_safe: bool
|
|
402
|
+
:param fill_safe: If the safe values should also be "filled" meaning that
|
|
403
|
+
they are initialized in a forced "way".
|
|
399
404
|
:type new: bool
|
|
400
405
|
:param new: In case this value is valid the resulting instance is expected
|
|
401
406
|
to be considered as new meaning that no identifier attributes are set.
|
|
@@ -408,7 +413,7 @@ class Model(legacy.with_meta(meta.Ordered, observer.Observable, *EXTRA_CLS)):
|
|
|
408
413
|
model = util.get_object() if form else dict(kwargs)
|
|
409
414
|
if fill:
|
|
410
415
|
model = cls.fill(model, safe=not new)
|
|
411
|
-
instance = cls(fill=
|
|
416
|
+
instance = cls(fill=fill_safe)
|
|
412
417
|
instance.apply(model, form=form, safe_a=safe)
|
|
413
418
|
if build:
|
|
414
419
|
cls.build(instance.model, map=False)
|
|
@@ -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,136 @@
|
|
|
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
|
+
expected_message = "resource not found"
|
|
57
|
+
|
|
58
|
+
@appier.error_handler(404, json=True)
|
|
59
|
+
def not_found(_):
|
|
60
|
+
return expected_message
|
|
61
|
+
|
|
62
|
+
exc = appier.exceptions.NotFoundError("dummy")
|
|
63
|
+
result = self.app.call_error(exc, code=exc.code, scope=None, json=True)
|
|
64
|
+
|
|
65
|
+
self.assertEqual(result, expected_message)
|
|
66
|
+
|
|
67
|
+
handlers = appier.common.base().App._ERROR_HANDLERS.get(404)
|
|
68
|
+
self.assertNotEqual(handlers, None)
|
|
69
|
+
self.assertEqual(len(handlers), 1)
|
|
70
|
+
|
|
71
|
+
method, scope, json, opts, ctx, priority = handlers[0]
|
|
72
|
+
self.assertEqual(method, not_found)
|
|
73
|
+
self.assertEqual(scope, None)
|
|
74
|
+
self.assertEqual(json, True)
|
|
75
|
+
self.assertEqual(opts, None)
|
|
76
|
+
self.assertEqual(ctx, None)
|
|
77
|
+
self.assertEqual(priority, 1)
|
|
78
|
+
|
|
79
|
+
def test_web_handler(self):
|
|
80
|
+
"""
|
|
81
|
+
Test that in which the error handler is a web handler by default, to be
|
|
82
|
+
able to properly handle errors in an WebApp, because this is a App no
|
|
83
|
+
handler is called.
|
|
84
|
+
"""
|
|
85
|
+
|
|
86
|
+
expected_message = "resource not found"
|
|
87
|
+
|
|
88
|
+
@appier.error_handler(404, json=False)
|
|
89
|
+
def not_found(_):
|
|
90
|
+
return expected_message
|
|
91
|
+
|
|
92
|
+
exc = appier.exceptions.NotFoundError("dummy")
|
|
93
|
+
result = self.app.call_error(exc, code=exc.code, scope=None, json=True)
|
|
94
|
+
|
|
95
|
+
self.assertEqual(result, None)
|
|
96
|
+
|
|
97
|
+
handlers = appier.common.base().App._ERROR_HANDLERS.get(404)
|
|
98
|
+
self.assertNotEqual(handlers, None)
|
|
99
|
+
self.assertEqual(len(handlers), 1)
|
|
100
|
+
|
|
101
|
+
method, scope, json, opts, ctx, priority = handlers[0]
|
|
102
|
+
self.assertEqual(method, not_found)
|
|
103
|
+
self.assertEqual(scope, None)
|
|
104
|
+
self.assertEqual(json, False)
|
|
105
|
+
self.assertEqual(opts, None)
|
|
106
|
+
self.assertEqual(ctx, None)
|
|
107
|
+
self.assertEqual(priority, 1)
|
|
108
|
+
|
|
109
|
+
def test_scope_registration(self):
|
|
110
|
+
"""
|
|
111
|
+
When a *scope* argument is provided, it should be stored in the handler
|
|
112
|
+
metadata so that the framework can later match it appropriately.
|
|
113
|
+
|
|
114
|
+
The error handler is a JSON handler by default, to be able to properly
|
|
115
|
+
handle errors in an App.
|
|
116
|
+
"""
|
|
117
|
+
|
|
118
|
+
class DummyScope:
|
|
119
|
+
pass
|
|
120
|
+
|
|
121
|
+
@appier.error_handler(400, scope=DummyScope, json=True)
|
|
122
|
+
def bad_request(_):
|
|
123
|
+
return "bad request"
|
|
124
|
+
|
|
125
|
+
handlers = appier.common.base().App._ERROR_HANDLERS.get(400)
|
|
126
|
+
self.assertNotEqual(handlers, None)
|
|
127
|
+
self.assertEqual(len(handlers), 1)
|
|
128
|
+
|
|
129
|
+
method, scope, json, opts, ctx, priority = handlers[0]
|
|
130
|
+
|
|
131
|
+
self.assertEqual(method, bad_request)
|
|
132
|
+
self.assertEqual(scope, DummyScope)
|
|
133
|
+
self.assertEqual(json, True)
|
|
134
|
+
self.assertEqual(opts, None)
|
|
135
|
+
self.assertEqual(ctx, None)
|
|
136
|
+
self.assertEqual(priority, 1)
|
|
@@ -0,0 +1,143 @@
|
|
|
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
|
+
expected_message = "resource not found"
|
|
57
|
+
|
|
58
|
+
@appier.exception_handler(appier.exceptions.NotFoundError, json=True)
|
|
59
|
+
def not_found(_):
|
|
60
|
+
return expected_message
|
|
61
|
+
|
|
62
|
+
exc = appier.exceptions.NotFoundError("dummy")
|
|
63
|
+
result = self.app.call_error(exc, code=exc.code, scope=None, json=True)
|
|
64
|
+
|
|
65
|
+
self.assertEqual(result, expected_message)
|
|
66
|
+
|
|
67
|
+
handlers = appier.common.base().App._ERROR_HANDLERS.get(
|
|
68
|
+
appier.exceptions.NotFoundError
|
|
69
|
+
)
|
|
70
|
+
self.assertNotEqual(handlers, None)
|
|
71
|
+
self.assertEqual(len(handlers), 1)
|
|
72
|
+
|
|
73
|
+
method, scope, json, opts, ctx, priority = handlers[0]
|
|
74
|
+
self.assertEqual(method, not_found)
|
|
75
|
+
self.assertEqual(scope, None)
|
|
76
|
+
self.assertEqual(json, True)
|
|
77
|
+
self.assertEqual(opts, None)
|
|
78
|
+
self.assertEqual(ctx, None)
|
|
79
|
+
self.assertEqual(priority, 1)
|
|
80
|
+
|
|
81
|
+
def test_scope_registration(self):
|
|
82
|
+
"""
|
|
83
|
+
When a *scope* argument is provided, it should be stored in the handler
|
|
84
|
+
metadata so that the framework can later match it appropriately.
|
|
85
|
+
|
|
86
|
+
The exception handler is a JSON handler by default, to be able to properly
|
|
87
|
+
handle errors in an App.
|
|
88
|
+
"""
|
|
89
|
+
|
|
90
|
+
class DummyScope:
|
|
91
|
+
pass
|
|
92
|
+
|
|
93
|
+
class DummyException(Exception):
|
|
94
|
+
code = 400
|
|
95
|
+
|
|
96
|
+
@appier.exception_handler(DummyException, scope=DummyScope, json=True)
|
|
97
|
+
def dummy_handler(_):
|
|
98
|
+
return "dummy"
|
|
99
|
+
|
|
100
|
+
handlers = appier.common.base().App._ERROR_HANDLERS.get(DummyException)
|
|
101
|
+
self.assertNotEqual(handlers, None)
|
|
102
|
+
self.assertEqual(len(handlers), 1)
|
|
103
|
+
|
|
104
|
+
method, scope, json, opts, ctx, priority = handlers[0]
|
|
105
|
+
|
|
106
|
+
self.assertEqual(method, dummy_handler)
|
|
107
|
+
self.assertEqual(scope, DummyScope)
|
|
108
|
+
self.assertEqual(json, True)
|
|
109
|
+
self.assertEqual(opts, None)
|
|
110
|
+
self.assertEqual(ctx, None)
|
|
111
|
+
self.assertEqual(priority, 1)
|
|
112
|
+
|
|
113
|
+
def test_web_handler(self):
|
|
114
|
+
"""
|
|
115
|
+
Test that in which the exception handler is a web handler by default, to be
|
|
116
|
+
able to properly handle errors in an WebApp, because this is an App no
|
|
117
|
+
handler is called.
|
|
118
|
+
"""
|
|
119
|
+
|
|
120
|
+
expected_message = "resource not found"
|
|
121
|
+
|
|
122
|
+
@appier.exception_handler(appier.exceptions.NotFoundError, json=False)
|
|
123
|
+
def not_found(_):
|
|
124
|
+
return expected_message
|
|
125
|
+
|
|
126
|
+
exc = appier.exceptions.NotFoundError("dummy")
|
|
127
|
+
result = self.app.call_error(exc, code=exc.code, scope=None, json=True)
|
|
128
|
+
|
|
129
|
+
self.assertEqual(result, None)
|
|
130
|
+
|
|
131
|
+
handlers = appier.common.base().App._ERROR_HANDLERS.get(
|
|
132
|
+
appier.exceptions.NotFoundError
|
|
133
|
+
)
|
|
134
|
+
self.assertNotEqual(handlers, None)
|
|
135
|
+
self.assertEqual(len(handlers), 1)
|
|
136
|
+
|
|
137
|
+
method, scope, json, opts, ctx, priority = handlers[0]
|
|
138
|
+
self.assertEqual(method, not_found)
|
|
139
|
+
self.assertEqual(scope, None)
|
|
140
|
+
self.assertEqual(json, False)
|
|
141
|
+
self.assertEqual(opts, None)
|
|
142
|
+
self.assertEqual(ctx, None)
|
|
143
|
+
self.assertEqual(priority, 1)
|
|
@@ -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
|
)
|
|
@@ -2145,13 +2145,13 @@ def route(url, method="GET", asynchronous=False, json=False, opts=None, priority
|
|
|
2145
2145
|
return decorator
|
|
2146
2146
|
|
|
2147
2147
|
|
|
2148
|
-
def error_handler(code, scope=None, json=
|
|
2148
|
+
def error_handler(code, scope=None, json=None, opts=None, priority=1):
|
|
2149
2149
|
def decorator(function, *args, **kwargs):
|
|
2150
2150
|
if is_detached(function):
|
|
2151
2151
|
delay(function, *args, **kwargs)
|
|
2152
2152
|
else:
|
|
2153
2153
|
common.base().App.add_error(
|
|
2154
|
-
code, function, json=json, opts=opts, priority=priority
|
|
2154
|
+
code, function, scope=scope, json=json, opts=opts, priority=priority
|
|
2155
2155
|
)
|
|
2156
2156
|
return function
|
|
2157
2157
|
|
|
@@ -2168,13 +2168,18 @@ def error_handler(code, scope=None, json=False, opts=None, priority=1):
|
|
|
2168
2168
|
return decorator
|
|
2169
2169
|
|
|
2170
2170
|
|
|
2171
|
-
def exception_handler(exception, scope=None, json=
|
|
2171
|
+
def exception_handler(exception, scope=None, json=None, opts=None, priority=1):
|
|
2172
2172
|
def decorator(function, *args, **kwargs):
|
|
2173
2173
|
if is_detached(function):
|
|
2174
2174
|
delay(function, *args, **kwargs)
|
|
2175
2175
|
else:
|
|
2176
2176
|
common.base().App.add_exception(
|
|
2177
|
-
exception,
|
|
2177
|
+
exception,
|
|
2178
|
+
function,
|
|
2179
|
+
scope=scope,
|
|
2180
|
+
json=json,
|
|
2181
|
+
opts=opts,
|
|
2182
|
+
priority=priority,
|
|
2178
2183
|
)
|
|
2179
2184
|
return function
|
|
2180
2185
|
|
|
@@ -82,6 +82,8 @@ src/appier/test/cache.py
|
|
|
82
82
|
src/appier/test/config.py
|
|
83
83
|
src/appier/test/crypt.py
|
|
84
84
|
src/appier/test/data.py
|
|
85
|
+
src/appier/test/error_handler.py
|
|
86
|
+
src/appier/test/exception_handler.py
|
|
85
87
|
src/appier/test/exceptions.py
|
|
86
88
|
src/appier/test/export.py
|
|
87
89
|
src/appier/test/graph.py
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|