Issues (59)

tests/test_api_templates.py (1 issue)

Severity
1
# pylint: disable=unused-variable,misplaced-comparison-constant,expression-not-assigned
2
3
from expecter import expect
0 ignored issues
show
Unable to import 'expecter'
Loading history...
4
5
from .utils import load
6
7
8
def describe_get():
9
10
    def it_returns_template_info(client):
11
        status, data = load(client.get("/api/templates/iw"))
12
13
        expect(status) == 200
14
        expect(data) == {
15
            'name': "Insanity Wolf",
16
            'description': "http://knowyourmeme.com/memes/insanity-wolf",
17
            'aliases': ['insanity', 'insanity-wolf', 'iw'],
18
            'styles': [],
19
            'example': "http://localhost/api/templates/iw/does_testing/in_production",
20
        }
21
22
    def when_no_default_text(client):
23
        status, data = load(client.get("/api/templates/keanu"))
24
25
        expect(status) == 200
26
        expect(data['example']) == "http://localhost/api/templates/keanu/your_text/goes_here"
27
28
    def when_alternate_sytles_available(client):
29
        status, data = load(client.get("/api/templates/sad-biden"))
30
31
        expect(status) == 200
32
        expect(data['styles']) == ['down', 'scowl', 'window']
33
34
    def when_dashes_in_key(client):
35
        status, data = load(client.get("/api/templates/awkward-awesome"))
36
37
        expect(status) == 200
38
39
    def it_returns_list_when_no_key(client):
40
        status, data = load(client.get("/api/templates/"))
41
42
        expect(status) == 200
43
        expect(data['Insanity Wolf']) == "http://localhost/api/templates/iw"
44
        expect(len(data)) >= 20  # there should be many memes
45
46
    def it_redirects_when_key_is_an_alias(client):
47
        status, data = load(client.get("/api/templates/insanity-wolf"))
48
49
        expect(status) == 302
50
        expect(data).contains('<a href="/api/templates/iw">')
51
52
    def old_api_is_still_supported_via_redirect(client):
53
        status, data = load(client.get("/templates/"))
54
55
        expect(status) == 302
56
        expect(data).contains('<a href="/api/templates/">')
57
58
59
def describe_post():
60
61
    def it_requies_an_existing_template(client):
62
        status, data = load(client.post("/api/templates/"))
63
64
        expect(status) == 403
65
        expect(data) == {
66
            'message': "https://raw.githubusercontent.com/jacebrowning/memegen/master/CONTRIBUTING.md"
67
        }
68
69
    def it_can_create_a_new_meme(client):
70
        params = {'top': "foo", 'bottom': "bar"}
71
        status, data = load(client.post("/api/templates/fry", data=params))
72
73
        expect(status) == 303
74
        expect(data).contains(
75
            '<a href="http://localhost/fry/foo/bar.jpg">'
76
        )
77
78
    def it_escapes_special_characters(client):
79
        params = {'top': "#special characters?", 'bottom': "underscore_ dash-"}
80
        status, data = load(client.post("/api/templates/fry", data=params))
81
82
        expect(status) == 303
83
        expect(data).contains(
84
            '<a href="http://localhost/fry/~hspecial_characters~q/underscore___dash--.jpg">'
85
        )
86
87
    def it_supports_top_only(client):
88
        params = {'top': "foo"}
89
        status, data = load(client.post("/api/templates/fry", data=params))
90
91
        expect(status) == 303
92
        expect(data).contains(
93
            '<a href="http://localhost/fry/foo.jpg">'
94
        )
95
96
    def it_supports_bottom_only(client):
97
        params = {'bottom': "bar"}
98
        status, data = load(client.post("/api/templates/fry", data=params))
99
100
        expect(status) == 303
101
        expect(data).contains(
102
            '<a href="http://localhost/fry/_/bar.jpg">'
103
        )
104
105
    def it_supports_no_text(client):
106
        params = {}
107
        status, data = load(client.post("/api/templates/fry", data=params))
108
109
        expect(status) == 303
110
        expect(data).contains(
111
            '<a href="http://localhost/fry/_.jpg">'
112
        )
113
114
    def it_can_return_json_instead_of_redirecting(client):
115
        params = {'top': "foo", 'bottom': "bar", 'redirect': False}
116
        status, data = load(client.post("/api/templates/fry", data=params))
117
118
        expect(status) == 200
119
        expect(data) == {
120
            'href': "http://localhost/fry/foo/bar.jpg"
121
        }
122