Merge ~cjwatson/lazr.restful:simplify-error-status-tests into lazr.restful:main

Proposed by Colin Watson
Status: Merged
Merged at revision: e99f1d0efa67f15ad8dff3b6b66951476be3dee7
Proposed branch: ~cjwatson/lazr.restful:simplify-error-status-tests
Merge into: lazr.restful:main
Diff against target: 47 lines (+5/-17)
2 files modified
src/lazr/restful/declarations.py (+1/-1)
src/lazr/restful/docs/webservice-declarations.rst (+4/-16)
Reviewer Review Type Date Requested Status
Jürgen Gmach Approve
Review via email: mp+413871@code.launchpad.net

Commit message

Simplify error_status tests

To post a comment you must log in.
Revision history for this message
Jürgen Gmach (jugmac00) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/src/lazr/restful/declarations.py b/src/lazr/restful/declarations.py
index 1ea9e21..0fca6c1 100644
--- a/src/lazr/restful/declarations.py
+++ b/src/lazr/restful/declarations.py
@@ -547,7 +547,7 @@ def webservice_error(status):
547547
548548
549def error_status(status):549def error_status(status):
550 """Make a Python 2.6 class decorator for the given status.550 """Make a class decorator for the given status.
551551
552 Usage 1:552 Usage 1:
553 @error_status(400)553 @error_status(400)
diff --git a/src/lazr/restful/docs/webservice-declarations.rst b/src/lazr/restful/docs/webservice-declarations.rst
index 2a8eb46..8c66e30 100644
--- a/src/lazr/restful/docs/webservice-declarations.rst
+++ b/src/lazr/restful/docs/webservice-declarations.rst
@@ -675,25 +675,13 @@ Exporting exceptions
675675
676When a method raises an exception, the default is to report the error as676When a method raises an exception, the default is to report the error as
677'500 Internal Server Error'. In many cases, that's not the case and one677'500 Internal Server Error'. In many cases, that's not the case and one
678of the 4XX error would be better.678of the 4XX error would be better. You can use error_status to annotate an
679679exception with a suitable HTTP status.
680For Python 2.6 or higher, or for annotating an already existing exception,
681you can use error_status.
682
683In Python 2.6, you would spell this as follows::
684
685 from lazr.restful.declarations import error_status
686 @error_status(400)
687 class InvalidDemo(Exception):
688 """An example exception"""
689
690In earlier Pythons it is still usable.
691680
692 >>> from lazr.restful.declarations import error_status681 >>> from lazr.restful.declarations import error_status
693 >>> class InvalidDemo(Exception):682 >>> @error_status(400)
683 ... class InvalidDemo(Exception):
694 ... """An example exception"""684 ... """An example exception"""
695 ...
696 >>> ignore = error_status(400)(InvalidDemo)
697685
698The function sets the __lazr_webservice_error__ attribute on the686The function sets the __lazr_webservice_error__ attribute on the
699exception, which will be used by the view handling the exception.687exception, which will be used by the view handling the exception.

Subscribers

People subscribed via source and target branches