Skip to content
This repository has been archived by the owner on Jan 5, 2019. It is now read-only.

Commit

Permalink
Added exception docs
Browse files Browse the repository at this point in the history
  • Loading branch information
rbw committed Mar 11, 2018
1 parent c86f7de commit 4b86e36
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
17 changes: 15 additions & 2 deletions flask_journey/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ class Journey(object):
Registers bundles and exposes properties for listing routes.
:param app: App to pass directly to Journey
:raises:
- InvalidBundlesType if passed bundles is not of type list
"""

def __init__(self, app=None, bundles=None):
Expand All @@ -44,6 +46,9 @@ def init_app(self, app):
"""Initializes Journey extension
:param app: App passed from constructor or directly to init_app
:raises:
- NoBundlesAttached if no bundles has been attached attached
"""

if len(self._attached_bundles) == 0:
Expand Down Expand Up @@ -99,7 +104,13 @@ def routes_simple(self):

return routes

def bundle_exists(self, path):
def _bundle_exists(self, path):
"""Checks if a bundle exists at the provided path
:param path: Bundle path
:return: bool
"""

for attached_bundle in self._attached_bundles:
if path == attached_bundle.path:
return True
Expand All @@ -112,14 +123,16 @@ def attach_bundle(self, bundle):
:param bundle: :class:`flask_journey.BlueprintBundle` object
:raises:
- IncompatibleBundle if the bundle is not of type `BlueprintBundle`
- DuplicateBundlePath if a bundle has already been attached at the same path
- MissingBlueprints if the bundle doesn't contain any blueprints
"""

if not isinstance(bundle, BlueprintBundle):
raise IncompatibleBundle('BlueprintBundle object passed to attach_bundle must be of type {0}'
.format(BlueprintBundle))
elif len(bundle.blueprints) == 0:
raise MissingBlueprints("Bundles must contain at least one flask.Blueprint")
elif self.bundle_exists(bundle.path):
elif self._bundle_exists(bundle.path):
raise DuplicateBundlePath("Duplicate bundle path {0}".format(bundle.path))

self._attached_bundles.append(bundle)
Expand Down
6 changes: 5 additions & 1 deletion flask_journey/blueprint_bundle.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ def sanitize_path(path):
"""Performs sanitation of the route path after validating
:param path: path to sanitize
:return: sanitized path
:return: path string
:raises:
- InvalidBundlePath if the path doesn't start with a slash
"""

if path[:1] != '/':
Expand All @@ -35,6 +37,8 @@ def attach_bp(self, bp, description=''):
:param bp: :class:`flask.Blueprint` object
:param description: Optional description string
:raises:
- InvalidBlueprint if the Blueprint is not of type `flask.Blueprint`
"""

if not isinstance(bp, Blueprint):
Expand Down
2 changes: 2 additions & 0 deletions flask_journey/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ def route(bp, *args, **kwargs):
- :body_schema: Deserialize JSON body with this schema
- :query_schema: Deserialize Query string with this schema
- :marshal_with: Serialize the output with this schema
:raises:
- ValidationError if the query parameters or JSON body fails validation
"""

kwargs['strict_slashes'] = kwargs.pop('strict_slashes', False)
Expand Down

0 comments on commit 4b86e36

Please sign in to comment.