Completed
Pull Request — master (#208)
by Jace
03:30
created

with_only_1_line()   A

Complexity

Conditions 3

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
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
import os
4
5
import pytest
6
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...
7
8
from .conftest import load
9
10
TESTS = os.path.dirname(__file__)
11
ROOT = os.path.dirname(TESTS)
12
IMAGES = os.path.join(ROOT, "data", "images")
13
LATEST = os.path.join(IMAGES, "latest.jpg")
14
15
16
def describe_get():
17
18
    def describe_visible():
19
20
        def with_nominal_text(client):
21
            path = os.path.join(IMAGES, 'iw', 'hello', 'world.jpg')
22
            if os.path.exists(path):
23
                os.remove(path)
24
25
            response = client.get("/iw/hello/world.jpg")
26
27
            assert 200 == response.status_code
28
            assert 'image/jpeg' == response.mimetype
29
            assert os.path.isfile(path)
30
31
        def with_only_1_line(client):
32
            response = client.get("/iw/hello.jpg")
33
34
            assert 200 == response.status_code
35
            assert 'image/jpeg' == response.mimetype
36
37
        @pytest.mark.xfail(os.name == 'nt', reason="Windows has a path limit")
38
        def with_lots_of_text(client):
39
            top = "-".join(["hello"] * 20)
40
            bottom = "-".join(["world"] * 20)
41
            response = client.get("/iw/" + top + "/" + bottom + ".jpg")
42
43
            assert 200 == response.status_code
44
            assert 'image/jpeg' == response.mimetype
45
46
    def describe_hidden():
47
48
        def when_jpg(client):
49
            response = client.get("/_aXcJaGVsbG8vd29ybGQJ.jpg")
50
51
            assert 200 == response.status_code
52
            assert 'image/jpeg' == response.mimetype
53
54
    def describe_alt():
55
56
        def when_style(client):
57
            response = client.get("/sad-biden/hello.jpg?alt=scowl")
58
59
            assert 200 == response.status_code
60
            assert 'image/jpeg' == response.mimetype
61
62
        def it_redirects_to_lose_alt_when_default_style(client):
63
            response = client.get("/sad-biden/hello.jpg?alt=default")
64
65
            assert 302 == response.status_code
66
            assert '<a href="/sad-biden/hello.jpg">' in \
67
                load(response, as_json=False)
68
69
        def it_redirects_to_lose_alt_when_unknown_style(client):
70
            response = client.get("/sad-biden/hello.jpg?alt=__unknown__")
71
72
            assert 302 == response.status_code
73
            assert '<a href="/sad-biden/hello.jpg">' in \
74
                load(response, as_json=False)
75
76
        def it_keeps_alt_after_template_redirect(client):
77
            response = client.get("/sad-joe/hello.jpg?alt=scowl")
78
79
            assert 302 == response.status_code
80
            assert '<a href="/sad-biden/hello.jpg?alt=scowl">' in \
81
                load(response, as_json=False)
82
83
        def it_keeps_alt_after_text_redirect(client):
84
            response = client.get("/sad-biden.jpg?alt=scowl")
85
86
            assert 302 == response.status_code
87
            assert '-vote.jpg?alt=scowl">' in \
88
                load(response, as_json=False)
89
90
        def when_url(client):
91
            url = "http://www.gstatic.com/webp/gallery/1.jpg"
92
            response = client.get("/sad-biden/hello.jpg?alt=" + url)
93
94
            expect(response.status_code) == 200
95
            expect(response.mimetype) == 'image/jpeg'
96
97
        def it_returns_an_error_with_non_image_urls(client):
98
            url = "http://example.com"
99
            response = client.get("/sad-biden/hello.jpg?alt=" + url)
100
101
            expect(response.status_code) == 415
102
103
        def it_redirects_to_lose_alt_when_unknown_url(client):
104
            url = "http://example.com/not/a/real/image.jpg"
105
            response = client.get("/sad-biden/hello.jpg?alt=" + url)
106
107
            expect(response.status_code) == 302
108
            expect(load(response, as_json=False)).contains(
109
                '<a href="/sad-biden/hello.jpg">')
110
111
        def it_redirects_to_lose_alt_when_bad_url(client):
112
            url = "http:invalid"
113
            response = client.get("/sad-biden/hello.jpg?alt=" + url)
114
115
            expect(response.status_code) == 302
116
            expect(load(response, as_json=False)).contains(
117
                '<a href="/sad-biden/hello.jpg">')
118
119
    def describe_latest():
120
121
        def when_existing(client):
122
            open(LATEST, 'w').close()  # force the file to exist
123
            response = client.get("/latest.jpg")
124
125
            assert 200 == response.status_code
126
            assert 'image/jpeg' == response.mimetype
127
128
        def when_missing(client):
129
            try:
130
                os.remove(LATEST)
131
            except FileNotFoundError:
132
                pass
133
134
            response = client.get("/latest.jpg")
135
136
            assert 200 == response.status_code
137
            assert 'image/png' == response.mimetype
138
139
    def describe_redirects():
140
141
        def when_missing_dashes(client):
142
            response = client.get("/iw/HelloThere_World/How-areYOU.jpg")
143
144
            assert 302 == response.status_code
145
            assert '<a href="/iw/hello-there-world/how-are-you.jpg">' in \
146
                load(response, as_json=False)
147
148
        def when_no_text(client):
149
            response = client.get("/live.jpg")
150
151
            assert 302 == response.status_code
152
            assert '<a href="/live/_/do-it-live!.jpg">' in \
153
                load(response, as_json=False)
154
155
        def when_aliased_template(client):
156
            response = client.get("/insanity-wolf/hello/world.jpg")
157
158
            assert 302 == response.status_code
159
            assert '<a href="/iw/hello/world.jpg">' in \
160
                load(response, as_json=False)
161
162
        def when_jpeg_extension_without_text(client):
163
            response = client.get("/iw.jpeg")
164
165
            assert 302 == response.status_code
166
            assert '<a href="/iw.jpg">' in \
167
                load(response, as_json=False)
168
169
        def when_jpeg_extension_with_text(client):
170
            response = client.get("/iw/hello/world.jpeg")
171
172
            assert 302 == response.status_code
173
            assert '<a href="/iw/hello/world.jpg">' in \
174
                load(response, as_json=False)
175
176
    def describe_errors():
177
178
        def when_unknown_template(client):
179
            response = client.get("/make/sudo/give.me.jpg")
180
181
            assert 200 == response.status_code
182
            assert 'image/jpeg' == response.mimetype
183
            # unit tests ensure this is a placeholder image
184
185
        @pytest.mark.xfail(os.name == 'nt', reason="Windows has a path limit")
186
        def when_too_much_text_for_a_filename(client):
187
            top = "hello"
188
            bottom = "-".join(["world"] * 50)
189
            response = client.get("/iw/" + top + "/" + bottom + ".jpg")
190
191
            assert 414 == response.status_code
192
            assert {
193
                'message': "Filename too long."
194
            } == load(response)
195