| Total Complexity | 41 |
| Total Lines | 100 |
| Duplicated Lines | 0 % |
Complex classes like TestImage 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=misplaced-comparison-constant |
||
| 12 | |||
| 13 | |||
| 14 | def describe_get(): |
||
| 15 | |||
| 16 | def describe_visible(): |
||
| 17 | |||
| 18 | def basic(client): |
||
| 19 | path = os.path.join(IMAGES, 'iw', 'hello', 'world.jpg') |
||
| 20 | if os.path.exists(path): |
||
| 21 | os.remove(path) |
||
| 22 | |||
| 23 | response = client.get("/iw/hello/world.jpg") |
||
| 24 | |||
| 25 | assert 200 == response.status_code |
||
| 26 | assert 'image/jpeg' == response.mimetype |
||
| 27 | assert os.path.isfile(path) |
||
| 28 | |||
| 29 | def with_only_1_line(client): |
||
| 30 | response = client.get("/iw/hello.jpg") |
||
| 31 | |||
| 32 | assert 200 == response.status_code |
||
| 33 | assert 'image/jpeg' == response.mimetype |
||
| 34 | |||
| 35 | def with_lots_of_text(client): |
||
| 36 | top = "-".join(["hello"] * 20) |
||
| 37 | bottom = "-".join(["world"] * 20) |
||
| 38 | response = client.get("/iw/" + top + "/" + bottom + ".jpg") |
||
| 39 | |||
| 40 | assert 200 == response.status_code |
||
| 41 | assert 'image/jpeg' == response.mimetype |
||
| 42 | |||
| 43 | def describe_hidden(): |
||
| 44 | |||
| 45 | def when_jpg(client): |
||
| 46 | response = client.get("/_aXcJaGVsbG8vd29ybGQJ.jpg") |
||
| 47 | |||
| 48 | assert 200 == response.status_code |
||
| 49 | assert 'image/jpeg' == response.mimetype |
||
| 50 | |||
| 51 | def describe_alt(): |
||
| 52 | |||
| 53 | def when_valid(client): |
||
| 54 | response = client.get("/sad-biden/hello.jpg?alt=scowl") |
||
| 55 | |||
| 56 | assert 200 == response.status_code |
||
| 57 | assert 'image/jpeg' == response.mimetype |
||
| 58 | |||
| 59 | def it_redirects_to_lose_alt_when_default(client): |
||
| 60 | response = client.get("/sad-biden/hello.jpg?alt=default") |
||
| 61 | |||
| 62 | assert 302 == response.status_code |
||
| 63 | assert '<a href="/sad-biden/hello.jpg">' in \ |
||
| 64 | load(response, as_json=False) |
||
| 65 | |||
| 66 | def it_redirects_to_lose_alt_when_unknown(client): |
||
| 67 | response = client.get("/sad-biden/hello.jpg?alt=__unknown__") |
||
| 68 | |||
| 69 | assert 302 == response.status_code |
||
| 70 | assert '<a href="/sad-biden/hello.jpg">' in \ |
||
| 71 | load(response, as_json=False) |
||
| 72 | |||
| 73 | def it_keeps_alt_after_template_redirect(client): |
||
| 74 | response = client.get("/sad-joe/hello.jpg?alt=scowl") |
||
| 75 | |||
| 76 | assert 302 == response.status_code |
||
| 77 | assert '<a href="/sad-biden/hello.jpg?alt=scowl">' in \ |
||
| 78 | load(response, as_json=False) |
||
| 79 | |||
| 80 | def it_keeps_alt_after_text_redirect(client): |
||
| 81 | response = client.get("/sad-biden.jpg?alt=scowl") |
||
| 82 | |||
| 83 | assert 302 == response.status_code |
||
| 84 | assert '-vote.jpg?style=scowl">' in \ |
||
| 85 | load(response, as_json=False) |
||
| 86 | |||
| 87 | def describe_latest(): |
||
| 88 | |||
| 89 | def when_existing(client): |
||
| 90 | open(LATEST, 'w').close() # force the file to exist |
||
| 91 | response = client.get("/latest.jpg") |
||
| 92 | |||
| 93 | assert 200 == response.status_code |
||
| 94 | assert 'image/jpeg' == response.mimetype |
||
| 95 | |||
| 96 | def when_missing(client): |
||
| 97 | try: |
||
| 98 | os.remove(LATEST) |
||
| 99 | except FileNotFoundError: |
||
| 100 | pass |
||
| 101 | |||
| 102 | response = client.get("/latest.jpg") |
||
| 103 | |||
| 104 | assert 200 == response.status_code |
||
| 105 | assert 'image/png' == response.mimetype |
||
| 106 | |||
| 107 | def describe_redirects(): |
||
| 108 | |||
| 109 | def when_missing_dashes(client): |
||
| 110 | response = client.get("/iw/HelloThere_World/How-areYOU.jpg") |
||
| 111 | |||
| 112 | assert 302 == response.status_code |
||
| 160 |