Completed
Push — master ( d36755...584f50 )
by Jace
14s
created

when_valid()   A

Complexity

Conditions 3

Size

Total Lines 5

Duplication

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