| Conditions | 1 |
| Total Lines | 62 |
| Code Lines | 42 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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:
| 1 | # pylint: disable=unused-variable,misplaced-comparison-constant,expression-not-assigned |
||
| 59 | def describe_post(): |
||
| 60 | |||
| 61 | def it_requies_an_existing_template(client): |
||
| 62 | status, data = load(client.post("/api/templates/")) |
||
| 63 | |||
| 64 | expect(status) == 403 |
||
| 65 | expect(data) == { |
||
| 66 | 'message': "https://raw.githubusercontent.com/jacebrowning/memegen/master/CONTRIBUTING.md" |
||
| 67 | } |
||
| 68 | |||
| 69 | def it_can_create_a_new_meme(client): |
||
| 70 | params = {'top': "foo", 'bottom': "bar"} |
||
| 71 | status, data = load(client.post("/api/templates/fry", data=params)) |
||
| 72 | |||
| 73 | expect(status) == 303 |
||
| 74 | expect(data).contains( |
||
| 75 | '<a href="http://localhost/fry/foo/bar.jpg">' |
||
| 76 | ) |
||
| 77 | |||
| 78 | def it_escapes_special_characters(client): |
||
| 79 | params = {'top': "#special characters?", 'bottom': "underscore_ dash-"} |
||
| 80 | status, data = load(client.post("/api/templates/fry", data=params)) |
||
| 81 | |||
| 82 | expect(status) == 303 |
||
| 83 | expect(data).contains( |
||
| 84 | '<a href="http://localhost/fry/~hspecial_characters~q/underscore___dash--.jpg">' |
||
| 85 | ) |
||
| 86 | |||
| 87 | def it_supports_top_only(client): |
||
| 88 | params = {'top': "foo"} |
||
| 89 | status, data = load(client.post("/api/templates/fry", data=params)) |
||
| 90 | |||
| 91 | expect(status) == 303 |
||
| 92 | expect(data).contains( |
||
| 93 | '<a href="http://localhost/fry/foo.jpg">' |
||
| 94 | ) |
||
| 95 | |||
| 96 | def it_supports_bottom_only(client): |
||
| 97 | params = {'bottom': "bar"} |
||
| 98 | status, data = load(client.post("/api/templates/fry", data=params)) |
||
| 99 | |||
| 100 | expect(status) == 303 |
||
| 101 | expect(data).contains( |
||
| 102 | '<a href="http://localhost/fry/_/bar.jpg">' |
||
| 103 | ) |
||
| 104 | |||
| 105 | def it_supports_no_text(client): |
||
| 106 | params = {} |
||
| 107 | status, data = load(client.post("/api/templates/fry", data=params)) |
||
| 108 | |||
| 109 | expect(status) == 303 |
||
| 110 | expect(data).contains( |
||
| 111 | '<a href="http://localhost/fry/_.jpg">' |
||
| 112 | ) |
||
| 113 | |||
| 114 | def it_can_return_json_instead_of_redirecting(client): |
||
| 115 | params = {'top': "foo", 'bottom': "bar", 'redirect': False} |
||
| 116 | status, data = load(client.post("/api/templates/fry", data=params)) |
||
| 117 | |||
| 118 | expect(status) == 200 |
||
| 119 | expect(data) == { |
||
| 120 | 'href': "http://localhost/fry/foo/bar.jpg" |
||
| 121 | } |
||
| 122 |