Completed
Pull Request — master (#132)
by Jace
01:42
created

TestTemplates.test_get_all()   A

Complexity

Conditions 4

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %
Metric Value
cc 4
dl 0
loc 7
rs 9.2
1
# pylint: disable=unused-variable
2
# pylint: disable=misplaced-comparison-constant
0 ignored issues
show
introduced by
Bad option value 'misplaced-comparison-constant'
Loading history...
3
4
from .conftest import load
5
6
7
def describe_get():
8
9
    def when_default_text(client):
10
        response = client.get("/templates/iw")
11
12
        assert 200 == response.status_code
13
        assert dict(
14
            name="Insanity Wolf",
15
            description="http://knowyourmeme.com/memes/insanity-wolf",
16
            aliases=['insanity', 'insanity-wolf', 'iw'],
17
            styles=[],
18
            example="http://localhost/iw/does-testing/in-production",
19
        ) == load(response)
20
21
    def when_no_default_text(client):
22
        response = client.get("/templates/keanu")
23
24
        assert 200 == response.status_code
25
        assert "http://localhost/keanu/your-text/goes-here" == \
26
            load(response)['example']
27
28
    def when_alternate_sytles_available(client):
29
        response = client.get("/templates/sad-biden")
30
31
        assert 200 == response.status_code
32
        assert ['down', 'scowl', 'window'] == load(response)['styles']
33
34
    def when_dashes_in_key(client):
35
        response = client.get("/templates/awkward-awesome")
36
37
        assert 200 == response.status_code
38
39
    def it_returns_list_when_no_key(client):
40
        response = client.get("/templates/")
41
42
        assert 200 == response.status_code
43
        data = load(response)
44
        assert "http://localhost/templates/iw" == data['Insanity Wolf']
45
        assert len(data) >= 20  # there should be many memes
46
47
    def it_redirects_when_text_is_provided(client):
48
        response = client.get("/templates/iw/top/bottom")
49
50
        assert 302 == response.status_code
51
        assert '<a href="/iw/top/bottom">' in load(response, as_json=False)
52
53
    def it_redirects_when_key_is_an_alias(client):
54
        response = client.get("/templates/insanity-wolf")
55
56
        assert 302 == response.status_code
57
        assert '<a href="/templates/iw">' in load(response, as_json=False)
58
59
60
def describe_post():
61
62
    def it_returns_an_error(client):
63
        response = client.post("/templates/")
64
65
        assert 403 == response.status_code
66
        assert dict(
67
            message="http://github.com/jacebrowning/memegen/blob/master/CONTRIBUTING.md"
68
        ) == load(response)
69