| Conditions | 21 |
| Total Lines | 71 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 4 | ||
| Bugs | 0 | Features | 0 |
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 |
||
| 53 | def describe_custom_style(): |
||
| 54 | |||
| 55 | def when_provided(client): |
||
| 56 | response = client.get("/sad-biden/hello.jpg?alt=scowl") |
||
| 57 | |||
| 58 | assert 200 == response.status_code |
||
| 59 | assert 'image/jpeg' == response.mimetype |
||
| 60 | |||
| 61 | def it_redirects_to_lose_alt_when_default_style(client): |
||
| 62 | response = client.get("/sad-biden/hello.jpg?alt=default") |
||
| 63 | |||
| 64 | assert 302 == response.status_code |
||
| 65 | assert '<a href="/sad-biden/hello.jpg">' in \ |
||
| 66 | load(response, as_json=False) |
||
| 67 | |||
| 68 | def it_redirects_to_lose_alt_when_unknown_style(client): |
||
| 69 | response = client.get("/sad-biden/hello.jpg?alt=__unknown__") |
||
| 70 | |||
| 71 | assert 302 == response.status_code |
||
| 72 | assert '<a href="/sad-biden/hello.jpg">' in \ |
||
| 73 | load(response, as_json=False) |
||
| 74 | |||
| 75 | def it_keeps_alt_after_template_redirect(client): |
||
| 76 | response = client.get("/sad-joe/hello.jpg?alt=scowl") |
||
| 77 | |||
| 78 | assert 302 == response.status_code |
||
| 79 | assert '<a href="/sad-biden/hello.jpg?alt=scowl">' in \ |
||
| 80 | load(response, as_json=False) |
||
| 81 | |||
| 82 | def it_keeps_alt_after_text_redirect(client): |
||
| 83 | response = client.get("/sad-biden.jpg?alt=scowl") |
||
| 84 | |||
| 85 | assert 302 == response.status_code |
||
| 86 | assert '-vote.jpg?alt=scowl">' in \ |
||
| 87 | load(response, as_json=False) |
||
| 88 | |||
| 89 | def when_url(client): |
||
| 90 | url = "http://www.gstatic.com/webp/gallery/1.jpg" |
||
| 91 | response = client.get("/sad-biden/hello.jpg?alt=" + url) |
||
| 92 | |||
| 93 | expect(response.status_code) == 200 |
||
| 94 | expect(response.mimetype) == 'image/jpeg' |
||
| 95 | |||
| 96 | def it_returns_an_error_with_non_image_urls(client): |
||
| 97 | url = "http://example.com" |
||
| 98 | response = client.get("/sad-biden/hello.jpg?alt=" + url) |
||
| 99 | |||
| 100 | expect(response.status_code) == 415 |
||
| 101 | |||
| 102 | def it_handles_int32_pixels(client): |
||
| 103 | url = "https://raw.githubusercontent.com/jacebrowning/memegen/master/tests/files/201692816359570.jpeg" |
||
| 104 | response = client.get("/sad-biden/hello.jpg?alt=" + url) |
||
| 105 | |||
| 106 | expect(response.status_code) == 200 |
||
| 107 | expect(response.mimetype) == 'image/jpeg' |
||
| 108 | |||
| 109 | def it_redirects_to_lose_alt_when_unknown_url(client): |
||
| 110 | url = "http://example.com/not/a/real/image.jpg" |
||
| 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 it_redirects_to_lose_alt_when_bad_url(client): |
||
| 118 | url = "http:invalid" |
||
| 119 | response = client.get("/sad-biden/hello.jpg?alt=" + url) |
||
| 120 | |||
| 121 | expect(response.status_code) == 302 |
||
| 122 | expect(load(response, as_json=False)).contains( |
||
| 123 | '<a href="/sad-biden/hello.jpg">') |
||
| 124 | |||
| 228 |