/
test_routes_templates.py
62 lines (45 loc) · 2.1 KB
/
test_routes_templates.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# pylint: disable=no-self-use
from .conftest import load
class TestTemplates:
def test_get(self, client):
response = client.get("/templates/iw")
assert 200 == response.status_code
assert dict(
name="Insanity Wolf",
description="http://knowyourmeme.com/memes/insanity-wolf",
aliases=['insanity', 'insanity-wolf', 'iw'],
example="http://localhost/iw/your-text/goes-here",
) == load(response)
def test_get_with_default(self, client):
response = client.get("/templates/live")
assert 200 == response.status_code
assert dict(
name="Do It Live!",
description="http://knowyourmeme.com/memes/bill-oreilly-rant",
aliases=["bill-o'reilly-rant", 'do-it-live', 'live', "o'reilly",
"o'reilly-rant"],
example="http://localhost/live/_/do-it-live!",
) == load(response)
def test_get_with_dash_in_key(self, client):
response = client.get("/templates/awkward-awesome")
assert 200 == response.status_code
def test_get_all(self, client):
response = client.get("/templates/")
assert 200 == response.status_code
data = load(response)
assert "http://localhost/templates/iw" == data['Insanity Wolf']
assert len(data) >= 20 # there should be many memes
def test_get_redirects_when_text_is_provided(self, client):
response = client.get("/templates/iw/top/bottom")
assert 302 == response.status_code
assert '<a href="/iw/top/bottom">' in load(response, as_json=False)
def test_get_redirects_when_key_is_an_alias(self, client):
response = client.get("/templates/insanity-wolf")
assert 302 == response.status_code
assert '<a href="/templates/iw">' in load(response, as_json=False)
def test_post_returns_an_error(self, client):
response = client.post("/templates/")
assert 403 == response.status_code
assert dict(
message="http://github.com/jacebrowning/memegen/blob/master/CONTRIBUTING.md"
) == load(response)