| Conditions | 20 |
| Total Lines | 71 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 17 | ||
| 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_get() 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,misplaced-comparison-constant,expression-not-assigned |
||
| 8 | def describe_get(): |
||
| 9 | |||
| 10 | def it_returns_link_options(client): |
||
| 11 | response = client.get("/api/templates/iw/hello/world") |
||
| 12 | |||
| 13 | expect(response.status_code) == 200 |
||
| 14 | assert dict( |
||
| 15 | direct=dict( |
||
| 16 | visible="http://localhost/iw/hello/world.jpg", |
||
| 17 | masked="http://localhost/_aXcJaGVsbG8vd29ybGQJ.jpg", |
||
| 18 | ), |
||
| 19 | markdown=dict( |
||
| 20 | visible="", |
||
| 21 | masked="", |
||
| 22 | ), |
||
| 23 | ) == load(response) |
||
| 24 | |||
| 25 | def with_top_only(client): |
||
| 26 | response = client.get("/api/templates/iw/hello") |
||
| 27 | |||
| 28 | expect(response.status_code) == 200 |
||
| 29 | assert dict( |
||
| 30 | visible="http://localhost/iw/hello.jpg", |
||
| 31 | masked="http://localhost/_aXcJaGVsbG8J.jpg", |
||
| 32 | ) == load(response, key='direct') |
||
| 33 | |||
| 34 | def with_bottom_only(client): |
||
| 35 | response = client.get("/api/templates/iw/_/hello") |
||
| 36 | |||
| 37 | expect(response.status_code) == 200 |
||
| 38 | assert dict( |
||
| 39 | visible="http://localhost/iw/_/hello.jpg", |
||
| 40 | masked="http://localhost/_aXcJXy9oZWxsbwkJ.jpg", |
||
| 41 | ) == load(response, key='direct') |
||
| 42 | |||
| 43 | def with_dashes(client): |
||
| 44 | response = client.get("/api/templates/iw/HelloThere_World/How-areYOU") |
||
| 45 | |||
| 46 | expect(response.status_code) == 302 |
||
| 47 | assert '<a href="/api/templates/iw/hello-there-world/how-are-you">' in \ |
||
| 48 | load(response, as_json=False) |
||
| 49 | |||
| 50 | def when_masked(client): |
||
| 51 | response = client.get("/_aXcJaGVsbG8vd29ybGQJ") |
||
| 52 | |||
| 53 | expect(response.status_code) == 302 |
||
| 54 | assert '<a href="/api/templates/iw/hello/world">' in load(response, as_json=False) |
||
| 55 | |||
| 56 | def when_masked_with_1_line(client): |
||
| 57 | response = client.get("/_aXcJaGVsbG8J") |
||
| 58 | |||
| 59 | expect(response.status_code) == 302 |
||
| 60 | assert '<a href="/api/templates/iw/hello">' in load(response, as_json=False) |
||
| 61 | |||
| 62 | def when_alias(client): |
||
| 63 | response = client.get("/api/templates/insanity-wolf") |
||
| 64 | |||
| 65 | expect(response.status_code) == 302 |
||
| 66 | assert '<a href="/api/templates/iw">' in load(response, as_json=False) |
||
| 67 | |||
| 68 | def when_alias_with_text(client): |
||
| 69 | response = client.get("/api/templates/insanity-wolf/hello/world") |
||
| 70 | |||
| 71 | expect(response.status_code) == 302 |
||
| 72 | assert '<a href="/api/templates/iw/hello/world">' in load(response, as_json=False) |
||
| 73 | |||
| 74 | def old_api_is_still_supported_via_redirect(client): |
||
| 75 | response = client.get("/iw/top/bottom") |
||
| 76 | |||
| 77 | assert 302 == response.status_code |
||
| 78 | assert '<a href="/api/templates/iw/top/bottom">' in load(response, as_json=False) |
||
| 79 |