Skip to content

Commit

Permalink
Redirect bare aliases (no ext) to the template overview
Browse files Browse the repository at this point in the history
  • Loading branch information
jacebrowning committed Aug 8, 2015
1 parent 29c8a6d commit 92d14dd
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
6 changes: 1 addition & 5 deletions memegen/routes/links.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,7 @@
@blueprint.route("<key>")
def get_without_text(key):
template = app.template_service.find(key)
if template.key != key:
return redirect(url_for(".get_without_text", key=template.key))

text = Text(template.default or '_')
return redirect(url_for(".get", key=key, path=text.path))
return redirect(url_for("templates.create", key=template.key))


@blueprint.route("<key>/<path:path>", endpoint='get')
Expand Down
6 changes: 3 additions & 3 deletions tests/test_routes_links.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,16 @@ def test_get_redirects_when_masked_with_1_line(self, client):
assert response.status_code == 302
assert '<a href="/iw/hello">' in load(response, as_json=False)

def test_get_redirects_to_default(self, client):
def test_get_without_extension_redirects_to_template(self, client):
response = client.get("/live")
assert response.status_code == 302
assert '<a href="/live/_/do-it-live!">' in \
assert '<a href="/templates/live">' in \
load(response, as_json=False)

def test_get_redirects_when_alias(self, client):
response = client.get("/insanity-wolf")
assert response.status_code == 302
assert '<a href="/iw">' in load(response, as_json=False)
assert '<a href="/templates/iw">' in load(response, as_json=False)

def test_get_redirects_when_alias_with_text(self, client):
response = client.get("/insanity-wolf/hello/world")
Expand Down

0 comments on commit 92d14dd

Please sign in to comment.