Skip to content

Commit c8e61fd

Browse files
committed
test(spyne): Add tests for error handling and custom headers
Signed-off-by: Varsha GS <[email protected]>
1 parent ce6f6a0 commit c8e61fd

File tree

2 files changed

+365
-21
lines changed

2 files changed

+365
-21
lines changed

tests/apps/spyne_app/app.py

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
from wsgiref.simple_server import make_server
99
from spyne import Application, rpc, ServiceBase, Iterable, UnsignedInteger, \
10-
String, Unicode, M, UnsignedInteger32
10+
String, Unicode
1111

1212
from spyne.protocol.json import JsonDocument
1313
from spyne.protocol.http import HttpRpc
@@ -24,22 +24,9 @@
2424
testenv["spyne_server"] = ("http://127.0.0.1:" + str(testenv["spyne_port"]))
2525

2626
class HelloWorldService(ServiceBase):
27-
# @rpc(Unicode, _returns=Unicode)
28-
# def get_resource(self, resource_id):
29-
# # Simulate checking for a resource
30-
# if resource_id != "existing_resource":
31-
# raise ResourceNotFoundError(
32-
# "Resource not found",
33-
# "The requested resource does not exist."
34-
# )
35-
# return f"Resource {resource_id} found."
36-
3727
@rpc(String, UnsignedInteger, _returns=Iterable(String))
3828
def say_hello(ctx, name, times):
3929
"""
40-
Docstrings for service methods do appear as documentation in the
41-
interface documents. <b>What fun!</b>
42-
4330
:param name: The name to say hello to
4431
:param times: The number of times to say hello
4532
@@ -50,12 +37,22 @@ def say_hello(ctx, name, times):
5037
yield 'Hello, %s' % name
5138

5239
@rpc(_returns=Unicode)
53-
def hello(self):
40+
def hello(ctx):
5441
return "<center><h1>🐍 Hello Stan! 🦄</h1></center>"
5542

56-
@rpc(M(UnsignedInteger32))
57-
def del_user(ctx, user_id):
43+
@rpc(_returns=Unicode)
44+
def response_headers(ctx):
45+
ctx.transport.add_header("X-Capture-This", "this")
46+
ctx.transport.add_header("X-Capture-That", "that")
47+
return "Stan wuz here with headers!"
48+
49+
@rpc(UnsignedInteger)
50+
def custom_404(ctx, user_id):
5851
raise ResourceNotFoundError(user_id)
52+
53+
@rpc()
54+
def exception(ctx):
55+
raise Exception('fake error')
5956

6057

6158
application = Application([HelloWorldService], 'spyne.examples.hello.http',
@@ -66,7 +63,5 @@ def del_user(ctx, user_id):
6663
spyne_server = make_server('127.0.0.1', testenv["spyne_port"], wsgi_app)
6764

6865
if __name__ == '__main__':
69-
# logging.info("listening to http://127.0.0.1:8000")
70-
# logging.info("wsdl is at: http://localhost:8000/?wsdl")
7166
spyne_server.request_queue_size = 20
7267
spyne_server.serve_forever()

0 commit comments

Comments
 (0)