| Conditions | 13 |
| Total Lines | 81 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 5 | ||
| Bugs | 0 | Features | 1 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
Complex classes like describe_custom_style() often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
| 1 | # pylint: disable=unused-variable,unused-argument,misplaced-comparison-constant,expression-not-assigned,singleton-comparison |
||
| 55 | def describe_custom_style(): |
||
| 56 | |||
| 57 | def when_provided(client): |
||
| 58 | response = client.get("/sad-biden/hello.jpg?alt=scowl") |
||
| 59 | |||
| 60 | expect(response.status_code) == 200 |
||
| 61 | expect(response.mimetype) == 'image/jpeg' |
||
| 62 | |||
| 63 | def it_redirects_to_lose_alt_when_default_style(client): |
||
| 64 | status, data = load(client.get("/sad-biden/hello.jpg?alt=default")) |
||
| 65 | |||
| 66 | expect(status) == 302 |
||
| 67 | expect(data).contains('<a href="/sad-biden/hello.jpg">') |
||
| 68 | |||
| 69 | def it_redirects_to_lose_alt_when_unknown_style(client): |
||
| 70 | status, data = load(client.get( |
||
| 71 | "/sad-biden/hello.jpg?alt=__unknown__")) |
||
| 72 | |||
| 73 | expect(status) == 302 |
||
| 74 | expect(data).contains('<a href="/sad-biden/hello.jpg">') |
||
| 75 | |||
| 76 | def it_keeps_alt_after_template_redirect(client): |
||
| 77 | status, data = load(client.get("/sad-joe/hello.jpg?alt=scowl")) |
||
| 78 | |||
| 79 | expect(status) == 302 |
||
| 80 | expect(data).contains('<a href="/sad-biden/hello.jpg?alt=scowl">') |
||
| 81 | |||
| 82 | def it_keeps_alt_after_text_redirect(client): |
||
| 83 | status, data = load(client.get("/sad-biden.jpg?alt=scowl")) |
||
| 84 | |||
| 85 | expect(status) == 302 |
||
| 86 | expect(data).contains("_vote.jpg") |
||
| 87 | expect(data).contains("alt=scowl") |
||
| 88 | |||
| 89 | def it_redirects_to_custom_when_alt_is_url(client): |
||
| 90 | url = "http://www.gstatic.com/webp/gallery/1.jpg" |
||
| 91 | status, data = load(client.get(f"/sad-biden/hello.jpg?alt={url}")) |
||
|
|
|||
| 92 | |||
| 93 | expect(status) == 302 |
||
| 94 | expect(data).contains(f'<a href="/custom/hello.jpg?alt={url}">') |
||
| 95 | |||
| 96 | def it_returns_an_error_with_non_image_urls(client): |
||
| 97 | url = "http://example.com" |
||
| 98 | response = client.get(f"/custom/hello.jpg?alt={url}") |
||
| 99 | |||
| 100 | expect(response.status_code) == 415 |
||
| 101 | |||
| 102 | def it_returns_an_error_with_non_urls(client): |
||
| 103 | url = "undefined" |
||
| 104 | response = client.get(f"/custom/hello.jpg?alt={url}") |
||
| 105 | |||
| 106 | print(response.data) |
||
| 107 | expect(response.status_code) == 415 |
||
| 108 | |||
| 109 | def it_handles_png_int32_pixels(client): |
||
| 110 | url = "https://raw.githubusercontent.com/jacebrowning/memegen/master/tests/files/201692816359570.jpeg" |
||
| 111 | response = client.get(f"/custom/hello.jpg?alt={url}") |
||
| 112 | |||
| 113 | expect(response.status_code) == 200 |
||
| 114 | expect(response.mimetype) == 'image/jpeg' |
||
| 115 | |||
| 116 | def it_handles_jpg_cmyk_pixels(client): |
||
| 117 | url = "https://raw.githubusercontent.com/jacebrowning/memegen/master/tests/files/Channel_digital_image_CMYK_color.jpg" |
||
| 118 | response = client.get(f"/custom/hello.jpg?alt={url}") |
||
| 119 | |||
| 120 | expect(response.status_code) == 200 |
||
| 121 | expect(response.mimetype) == 'image/jpeg' |
||
| 122 | |||
| 123 | def it_redirects_to_lose_alt_when_invalid_url(client): |
||
| 124 | url = "http:invalid" |
||
| 125 | status, data = load(client.get(f"/sad-biden/hello.jpg?alt={url}")) |
||
| 126 | |||
| 127 | expect(status) == 302 |
||
| 128 | expect(data).contains('<a href="/sad-biden/hello.jpg">') |
||
| 129 | |||
| 130 | def it_redirects_to_lose_alt_when_missing_schema(client): |
||
| 131 | url = "http:/www.gstatic.com/webp/gallery/1.jpg" |
||
| 132 | status, data = load(client.get(f"/sad-biden/hello.jpg?alt={url}")) |
||
| 133 | |||
| 134 | expect(status) == 302 |
||
| 135 | expect(data).contains('<a href="/sad-biden/hello.jpg">') |
||
| 136 | |||
| 317 |