-
-
Notifications
You must be signed in to change notification settings - Fork 182
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #140 from jacebrowning/aliases-route
Add aliases route
- Loading branch information
Showing
10 changed files
with
102 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,4 @@ | |
from . import overview | ||
from . import generator | ||
from . import latest | ||
from . import aliases |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
from collections import OrderedDict | ||
|
||
from flask import Blueprint, current_app as app | ||
from webargs import fields, flaskparser | ||
|
||
from ._common import url_for | ||
|
||
|
||
blueprint = Blueprint('aliases', __name__, url_prefix="/aliases/") | ||
|
||
FILTER = { | ||
'name': fields.Str(missing="") # pylint: disable=no-member | ||
} | ||
|
||
|
||
@blueprint.route("") | ||
@flaskparser.use_kwargs(FILTER) | ||
def get(name): | ||
"""Get a list of all matching aliases.""" | ||
items = OrderedDict() | ||
|
||
for alias in sorted(app.template_service.aliases(name)): | ||
template = app.template_service.find(alias) | ||
|
||
data = OrderedDict() | ||
data['styles'] = sorted(template.styles) | ||
data['template'] = \ | ||
url_for('templates.create', key=template.key, _external=True) | ||
|
||
items[alias] = data | ||
|
||
return items |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# pylint: disable=unused-variable,misplaced-comparison-constant,expression-not-assigned | ||
|
||
from .conftest import load | ||
|
||
|
||
def describe_get(): | ||
|
||
def it_returns_all_aliases(client): | ||
response = client.get("/aliases/") | ||
|
||
assert 200 == response.status_code | ||
assert len(load(response)) > 200 | ||
|
||
def describe_filter(): | ||
|
||
def with_single_match(client): | ||
response = client.get("/aliases/?name=sad-biden") | ||
|
||
assert 200 == response.status_code | ||
assert { | ||
'sad-biden': { | ||
'styles': [ | ||
'down', | ||
'scowl', | ||
'window', | ||
], | ||
'template': "http://localhost/templates/sad-biden" | ||
} | ||
} == load(response) | ||
|
||
def with_many_matches(client): | ||
response = client.get("/aliases/?name=votestakes") | ||
|
||
assert 200 == response.status_code | ||
assert len(load(response)) == 3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters