Completed
Pull Request — master (#308)
by Jace
02:14
created

it_supports_no_text()   A

Complexity

Conditions 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
dl 0
loc 7
rs 9.4285
1
# pylint: disable=unused-variable,misplaced-comparison-constant,expression-not-assigned
0 ignored issues
show
introduced by
Bad option value 'misplaced-comparison-constant'
Loading history...
2
3
from expecter import expect
0 ignored issues
show
Configuration introduced by
The import expecter could not be resolved.

This can be caused by one of the following:

1. Missing Dependencies

This error could indicate a configuration issue of Pylint. Make sure that your libraries are available by adding the necessary commands.

# .scrutinizer.yml
before_commands:
    - sudo pip install abc # Python2
    - sudo pip3 install abc # Python3
Tip: We are currently not using virtualenv to run pylint, when installing your modules make sure to use the command for the correct version.

2. Missing __init__.py files

This error could also result from missing __init__.py files in your module folders. Make sure that you place one file in each sub-folder.

Loading history...
4
5
from .conftest import load
6
7
8
def describe_get():
9
10
    def it_returns_template_info(client):
11
        response = client.get("/api/templates/iw")
12
13
        assert 200 == response.status_code
14
        assert dict(
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
        ) == load(response)
21
22
    def when_no_default_text(client):
23
        response = client.get("/api/templates/keanu")
24
25
        assert 200 == response.status_code
26
        assert "http://localhost/api/templates/keanu/your-text/goes-here" == \
27
            load(response)['example']
28
29
    def when_alternate_sytles_available(client):
30
        response = client.get("/api/templates/sad-biden")
31
32
        assert 200 == response.status_code
33
        assert ['down', 'scowl', 'window'] == load(response)['styles']
34
35
    def when_dashes_in_key(client):
36
        response = client.get("/api/templates/awkward-awesome")
37
38
        assert 200 == response.status_code
39
40
    def it_returns_list_when_no_key(client):
41
        response = client.get("/api/templates/")
42
43
        assert 200 == response.status_code
44
        data = load(response)
45
        assert "http://localhost/api/templates/iw" == data['Insanity Wolf']
46
        assert len(data) >= 20  # there should be many memes
47
48
    def it_redirects_when_key_is_an_alias(client):
49
        response = client.get("/api/templates/insanity-wolf")
50
51
        assert 302 == response.status_code
52
        assert '<a href="/api/templates/iw">' in load(response, as_json=False)
53
54
    def old_api_is_still_supported_via_redirect(client):
55
        response = client.get("/templates/")
56
57
        assert 302 == response.status_code
58
        assert '<a href="/api/templates/">' in load(response, as_json=False)
59
60
61
def describe_post():
62
63
    def it_requies_an_existing_template(client):
64
        response = client.post("/api/templates/")
65
66
        assert 403 == response.status_code
67
        assert dict(
68
            message="https://raw.githubusercontent.com/jacebrowning/memegen/master/CONTRIBUTING.md"
69
        ) == load(response)
70
71
    def it_can_create_a_new_meme(client):
72
        params = {'top': "foo", 'bottom': "bar"}
73
        response = client.post("/api/templates/fry", data=params)
74
75
        expect(response.status_code) == 303
76
        expect(load(response, as_json=False)).contains(
77
            '<a href="/fry/foo/bar.jpg">'
78
        )
79
80
    def it_escapes_special_characters(client):
81
        params = {'top': "#special characters?", 'bottom': "underscore_ dash-"}
82
        response = client.post("/api/templates/fry", data=params)
83
84
        expect(response.status_code) == 303
85
        expect(load(response, as_json=False)).contains(
86
            '<a href="/fry/~hspecial-characters~q/underscore__-dash--.jpg">'
87
        )
88
89
    def it_supports_top_only(client):
90
        params = {'top': "foo"}
91
        response = client.post("/api/templates/fry", data=params)
92
93
        expect(response.status_code) == 303
94
        expect(load(response, as_json=False)).contains(
95
            '<a href="/fry/foo.jpg">'
96
        )
97
98
    def it_supports_bottom_only(client):
99
        params = {'bottom': "bar"}
100
        response = client.post("/api/templates/fry", data=params)
101
102
        expect(response.status_code) == 303
103
        expect(load(response, as_json=False)).contains(
104
            '<a href="/fry/_/bar.jpg">'
105
        )
106
107
    def it_supports_no_text(client):
108
        params = {}
109
        response = client.post("/api/templates/fry", data=params)
110
111
        expect(response.status_code) == 303
112
        expect(load(response, as_json=False)).contains(
113
            '<a href="/fry/_.jpg">'
114
        )
115
116
    def it_can_return_json_instead_of_redirecting(client):
117
        params = {'top': "foo", 'bottom': "bar", 'redirect': False}
118
        response = client.post("/api/templates/fry", data=params)
119
120
        expect(response.status_code) == 200
121
        expect(load(response)) == {
122
            'href': "/fry/foo/bar.jpg"
123
        }
124