appier 1.34.7__py2.py3-none-any.whl → 1.34.9__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/api.py +10 -0
- appier/asgi.py +10 -0
- appier/base.py +11 -1
- appier/bus.py +10 -0
- appier/config.py +409 -401
- appier/exceptions.py +450 -442
- appier/http.py +1292 -1283
- appier/model.py +31 -12
- appier/mongo.py +24 -0
- appier/scheduler.py +342 -334
- appier/test/error_handler.py +17 -11
- appier/test/exception_handler.py +44 -41
- appier/test/tags.py +109 -0
- appier/util.py +2517 -2508
- {appier-1.34.7.dist-info → appier-1.34.9.dist-info}/METADATA +1 -1
- {appier-1.34.7.dist-info → appier-1.34.9.dist-info}/RECORD +19 -18
- {appier-1.34.7.dist-info → appier-1.34.9.dist-info}/LICENSE +0 -0
- {appier-1.34.7.dist-info → appier-1.34.9.dist-info}/WHEEL +0 -0
- {appier-1.34.7.dist-info → appier-1.34.9.dist-info}/top_level.txt +0 -0
appier/test/error_handler.py
CHANGED
|
@@ -53,16 +53,13 @@ class ErrorHandlerTest(unittest.TestCase):
|
|
|
53
53
|
handle errors in an App.
|
|
54
54
|
"""
|
|
55
55
|
|
|
56
|
-
expected_message = "resource not found"
|
|
57
|
-
|
|
58
56
|
@appier.error_handler(404, json=True)
|
|
59
57
|
def not_found(_):
|
|
60
|
-
return
|
|
58
|
+
return "resource not found"
|
|
61
59
|
|
|
62
60
|
exc = appier.exceptions.NotFoundError("dummy")
|
|
63
61
|
result = self.app.call_error(exc, code=exc.code, scope=None, json=True)
|
|
64
|
-
|
|
65
|
-
self.assertEqual(result, expected_message)
|
|
62
|
+
self.assertEqual(result, "resource not found")
|
|
66
63
|
|
|
67
64
|
handlers = appier.common.base().App._ERROR_HANDLERS.get(404)
|
|
68
65
|
self.assertNotEqual(handlers, None)
|
|
@@ -83,15 +80,12 @@ class ErrorHandlerTest(unittest.TestCase):
|
|
|
83
80
|
handler is called.
|
|
84
81
|
"""
|
|
85
82
|
|
|
86
|
-
expected_message = "resource not found"
|
|
87
|
-
|
|
88
83
|
@appier.error_handler(404, json=False)
|
|
89
84
|
def not_found(_):
|
|
90
|
-
return
|
|
85
|
+
return "resource not found"
|
|
91
86
|
|
|
92
87
|
exc = appier.exceptions.NotFoundError("dummy")
|
|
93
88
|
result = self.app.call_error(exc, code=exc.code, scope=None, json=True)
|
|
94
|
-
|
|
95
89
|
self.assertEqual(result, None)
|
|
96
90
|
|
|
97
91
|
handlers = appier.common.base().App._ERROR_HANDLERS.get(404)
|
|
@@ -118,10 +112,22 @@ class ErrorHandlerTest(unittest.TestCase):
|
|
|
118
112
|
class DummyScope:
|
|
119
113
|
pass
|
|
120
114
|
|
|
121
|
-
|
|
115
|
+
class DummyException(Exception):
|
|
116
|
+
code = 400
|
|
117
|
+
|
|
118
|
+
@appier.error_handler(400, scope=DummyScope)
|
|
122
119
|
def bad_request(_):
|
|
123
120
|
return "bad request"
|
|
124
121
|
|
|
122
|
+
exc = DummyException("dummy")
|
|
123
|
+
result = self.app.call_error(exc, code=exc.code, scope=DummyScope, json=True)
|
|
124
|
+
self.assertEqual(result, "bad request")
|
|
125
|
+
|
|
126
|
+
result = None
|
|
127
|
+
exc = DummyException("dummy")
|
|
128
|
+
result = self.app.call_error(exc, code=exc.code, json=True)
|
|
129
|
+
self.assertEqual(result, None)
|
|
130
|
+
|
|
125
131
|
handlers = appier.common.base().App._ERROR_HANDLERS.get(400)
|
|
126
132
|
self.assertNotEqual(handlers, None)
|
|
127
133
|
self.assertEqual(len(handlers), 1)
|
|
@@ -130,7 +136,7 @@ class ErrorHandlerTest(unittest.TestCase):
|
|
|
130
136
|
|
|
131
137
|
self.assertEqual(method, bad_request)
|
|
132
138
|
self.assertEqual(scope, DummyScope)
|
|
133
|
-
self.assertEqual(json,
|
|
139
|
+
self.assertEqual(json, None)
|
|
134
140
|
self.assertEqual(opts, None)
|
|
135
141
|
self.assertEqual(ctx, None)
|
|
136
142
|
self.assertEqual(priority, 1)
|
appier/test/exception_handler.py
CHANGED
|
@@ -53,16 +53,13 @@ class ExceptionHandlerTest(unittest.TestCase):
|
|
|
53
53
|
handle errors in an App.
|
|
54
54
|
"""
|
|
55
55
|
|
|
56
|
-
expected_message = "resource not found"
|
|
57
|
-
|
|
58
56
|
@appier.exception_handler(appier.exceptions.NotFoundError, json=True)
|
|
59
57
|
def not_found(_):
|
|
60
|
-
return
|
|
58
|
+
return "resource not found"
|
|
61
59
|
|
|
62
60
|
exc = appier.exceptions.NotFoundError("dummy")
|
|
63
|
-
result = self.app.call_error(exc,
|
|
64
|
-
|
|
65
|
-
self.assertEqual(result, expected_message)
|
|
61
|
+
result = self.app.call_error(exc, scope=None, json=True)
|
|
62
|
+
self.assertEqual(result, "resource not found")
|
|
66
63
|
|
|
67
64
|
handlers = appier.common.base().App._ERROR_HANDLERS.get(
|
|
68
65
|
appier.exceptions.NotFoundError
|
|
@@ -78,66 +75,72 @@ class ExceptionHandlerTest(unittest.TestCase):
|
|
|
78
75
|
self.assertEqual(ctx, None)
|
|
79
76
|
self.assertEqual(priority, 1)
|
|
80
77
|
|
|
81
|
-
def
|
|
78
|
+
def test_web_handler(self):
|
|
82
79
|
"""
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
The exception handler is a JSON handler by default, to be able to properly
|
|
87
|
-
handle errors in an App.
|
|
80
|
+
Test that in which the exception handler is a web handler by default, to be
|
|
81
|
+
able to properly handle errors in an WebApp, because this is an App no
|
|
82
|
+
handler is called.
|
|
88
83
|
"""
|
|
89
84
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
class DummyException(Exception):
|
|
94
|
-
code = 400
|
|
85
|
+
@appier.exception_handler(appier.exceptions.NotFoundError, json=False)
|
|
86
|
+
def not_found(_):
|
|
87
|
+
return "resource not found"
|
|
95
88
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
89
|
+
exc = appier.exceptions.NotFoundError("dummy")
|
|
90
|
+
result = self.app.call_error(exc, scope=None, json=True)
|
|
91
|
+
self.assertEqual(result, None)
|
|
99
92
|
|
|
100
|
-
handlers = appier.common.base().App._ERROR_HANDLERS.get(
|
|
93
|
+
handlers = appier.common.base().App._ERROR_HANDLERS.get(
|
|
94
|
+
appier.exceptions.NotFoundError
|
|
95
|
+
)
|
|
101
96
|
self.assertNotEqual(handlers, None)
|
|
102
97
|
self.assertEqual(len(handlers), 1)
|
|
103
98
|
|
|
104
99
|
method, scope, json, opts, ctx, priority = handlers[0]
|
|
105
|
-
|
|
106
|
-
self.assertEqual(
|
|
107
|
-
self.assertEqual(
|
|
108
|
-
self.assertEqual(json, True)
|
|
100
|
+
self.assertEqual(method, not_found)
|
|
101
|
+
self.assertEqual(scope, None)
|
|
102
|
+
self.assertEqual(json, False)
|
|
109
103
|
self.assertEqual(opts, None)
|
|
110
104
|
self.assertEqual(ctx, None)
|
|
111
105
|
self.assertEqual(priority, 1)
|
|
112
106
|
|
|
113
|
-
def
|
|
107
|
+
def test_scope_registration(self):
|
|
114
108
|
"""
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
109
|
+
When a *scope* argument is provided, it should be stored in the handler
|
|
110
|
+
metadata so that the framework can later match it appropriately.
|
|
111
|
+
|
|
112
|
+
The exception handler is a JSON handler by default, to be able to properly
|
|
113
|
+
handle errors in an App.
|
|
118
114
|
"""
|
|
119
115
|
|
|
120
|
-
|
|
116
|
+
class DummyScope:
|
|
117
|
+
pass
|
|
121
118
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
return expected_message
|
|
119
|
+
class DummyException(Exception):
|
|
120
|
+
code = 400
|
|
125
121
|
|
|
126
|
-
|
|
127
|
-
|
|
122
|
+
@appier.exception_handler(DummyException, scope=DummyScope)
|
|
123
|
+
def bad_request(_):
|
|
124
|
+
return "bad request"
|
|
128
125
|
|
|
126
|
+
exc = DummyException("dummy")
|
|
127
|
+
result = self.app.call_error(exc, scope=DummyScope, json=True)
|
|
128
|
+
self.assertEqual(result, "bad request")
|
|
129
|
+
|
|
130
|
+
result = None
|
|
131
|
+
exc = DummyException("dummy")
|
|
132
|
+
result = self.app.call_error(exc, json=True)
|
|
129
133
|
self.assertEqual(result, None)
|
|
130
134
|
|
|
131
|
-
handlers = appier.common.base().App._ERROR_HANDLERS.get(
|
|
132
|
-
appier.exceptions.NotFoundError
|
|
133
|
-
)
|
|
135
|
+
handlers = appier.common.base().App._ERROR_HANDLERS.get(DummyException)
|
|
134
136
|
self.assertNotEqual(handlers, None)
|
|
135
137
|
self.assertEqual(len(handlers), 1)
|
|
136
138
|
|
|
137
139
|
method, scope, json, opts, ctx, priority = handlers[0]
|
|
138
|
-
|
|
139
|
-
self.assertEqual(
|
|
140
|
-
self.assertEqual(
|
|
140
|
+
|
|
141
|
+
self.assertEqual(method, bad_request)
|
|
142
|
+
self.assertEqual(scope, DummyScope)
|
|
143
|
+
self.assertEqual(json, None)
|
|
141
144
|
self.assertEqual(opts, None)
|
|
142
145
|
self.assertEqual(ctx, None)
|
|
143
146
|
self.assertEqual(priority, 1)
|
appier/test/tags.py
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
#!/usr/bin/python
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
|
|
4
|
+
# Hive Appier Framework
|
|
5
|
+
# Copyright (c) 2008-2024 Hive Solutions Lda.
|
|
6
|
+
#
|
|
7
|
+
# This file is part of Hive Appier Framework.
|
|
8
|
+
#
|
|
9
|
+
# Hive Appier Framework is free software: you can redistribute it and/or modify
|
|
10
|
+
# it under the terms of the Apache License as published by the Apache
|
|
11
|
+
# Foundation, either version 2.0 of the License, or (at your option) any
|
|
12
|
+
# later version.
|
|
13
|
+
#
|
|
14
|
+
# Hive Appier Framework is distributed in the hope that it will be useful,
|
|
15
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
16
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
17
|
+
# Apache License for more details.
|
|
18
|
+
#
|
|
19
|
+
# You should have received a copy of the Apache License along with
|
|
20
|
+
# Hive Appier Framework. If not, see <http://www.apache.org/licenses/>.
|
|
21
|
+
|
|
22
|
+
__author__ = "João Magalhães <joamag@hive.pt>"
|
|
23
|
+
""" The author(s) of the module """
|
|
24
|
+
|
|
25
|
+
__copyright__ = "Copyright (c) 2008-2024 Hive Solutions Lda."
|
|
26
|
+
""" The copyright for the module """
|
|
27
|
+
|
|
28
|
+
__license__ = "Apache License, Version 2.0"
|
|
29
|
+
""" The license for the module """
|
|
30
|
+
|
|
31
|
+
import unittest
|
|
32
|
+
|
|
33
|
+
import appier
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
class TagsTest(unittest.TestCase):
|
|
37
|
+
def setUp(self):
|
|
38
|
+
self.app = appier.App()
|
|
39
|
+
|
|
40
|
+
def tearDown(self):
|
|
41
|
+
self.app.unload()
|
|
42
|
+
|
|
43
|
+
def test_script_tag(self):
|
|
44
|
+
if not self.app.jinja:
|
|
45
|
+
if not hasattr(self, "skipTest"):
|
|
46
|
+
return
|
|
47
|
+
self.skipTest("No Jinja2 template engine present")
|
|
48
|
+
|
|
49
|
+
template = appier.Template("{{ value|script_tag }}")
|
|
50
|
+
result = self.app.template(template, value="/static/app.js")
|
|
51
|
+
self.assertEqual(
|
|
52
|
+
result, '<script type="text/javascript" src="/static/app.js"></script>'
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
template = appier.Template("{{ '/static/app.js'|script_tag }}")
|
|
56
|
+
result = self.app.template(template)
|
|
57
|
+
self.assertEqual(
|
|
58
|
+
result, '<script type="text/javascript" src="/static/app.js"></script>'
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
def test_css_tag(self):
|
|
62
|
+
if not self.app.jinja:
|
|
63
|
+
if not hasattr(self, "skipTest"):
|
|
64
|
+
return
|
|
65
|
+
self.skipTest("No Jinja2 template engine present")
|
|
66
|
+
|
|
67
|
+
template = appier.Template("{{ value|css_tag }}")
|
|
68
|
+
result = self.app.template(template, value="/static/style.css")
|
|
69
|
+
self.assertEqual(
|
|
70
|
+
result, '<link rel="stylesheet" type="text/css" href="/static/style.css" />'
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
template = appier.Template("{{ '/static/style.css'|css_tag }}")
|
|
74
|
+
result = self.app.template(template)
|
|
75
|
+
self.assertEqual(
|
|
76
|
+
result, '<link rel="stylesheet" type="text/css" href="/static/style.css" />'
|
|
77
|
+
)
|
|
78
|
+
|
|
79
|
+
def test_stylesheet_tag(self):
|
|
80
|
+
if not self.app.jinja:
|
|
81
|
+
if not hasattr(self, "skipTest"):
|
|
82
|
+
return
|
|
83
|
+
self.skipTest("No Jinja2 template engine present")
|
|
84
|
+
|
|
85
|
+
template = appier.Template("{{ value|stylesheet_tag }}")
|
|
86
|
+
result = self.app.template(template, value="/static/main.css")
|
|
87
|
+
self.assertEqual(
|
|
88
|
+
result, '<link rel="stylesheet" type="text/css" href="/static/main.css" />'
|
|
89
|
+
)
|
|
90
|
+
|
|
91
|
+
template = appier.Template("{{ '/static/main.css'|stylesheet_tag }}")
|
|
92
|
+
result = self.app.template(template)
|
|
93
|
+
self.assertEqual(
|
|
94
|
+
result, '<link rel="stylesheet" type="text/css" href="/static/main.css" />'
|
|
95
|
+
)
|
|
96
|
+
|
|
97
|
+
def test_asset_url(self):
|
|
98
|
+
if not self.app.jinja:
|
|
99
|
+
if not hasattr(self, "skipTest"):
|
|
100
|
+
return
|
|
101
|
+
self.skipTest("No Jinja2 template engine present")
|
|
102
|
+
|
|
103
|
+
template = appier.Template("{{ filename|asset_url }}")
|
|
104
|
+
result = self.app.template(template, filename="logo.png")
|
|
105
|
+
self.assertEqual(result, "/static/assets/logo.png")
|
|
106
|
+
|
|
107
|
+
template = appier.Template("{{ 'logo.png'|asset_url }}")
|
|
108
|
+
result = self.app.template(template)
|
|
109
|
+
self.assertEqual(result, "/static/assets/logo.png")
|