Passed
Push — master ( 00d837...bc5250 )
by Jace
49s
created

describe_get()   D

Complexity

Conditions 10

Size

Total Lines 73

Duplication

Lines 0
Ratio 0 %

Importance

Changes 9
Bugs 0 Features 0
Metric Value
cc 10
c 9
b 0
f 0
dl 0
loc 73
rs 4.0909

9 Methods

Rating   Name   Duplication   Size   Complexity  
A old_api_is_still_supported_via_redirect() 0 5 1
A when_alias() 0 5 1
A when_masked() 0 5 1
A it_returns_link_options() 0 5 1
A when_alias_with_text() 0 6 1
A when_masked_with_1_line() 0 5 1
A with_dashes() 0 7 1
A with_top_only() 0 5 1
A with_bottom_only() 0 5 1

How to fix   Long Method    Complexity   

Long Method

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:

Complexity

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
2
3
from expecter import expect
4
5
from .utils import load
6
7
8
def describe_get():
9
10
    def it_returns_link_options(client):
11
        status, data = load(client.get("/api/templates/iw/hello/world"))
12
13
        expect(status) == 200
14
        expect(data) == dict(
15
            direct=dict(
16
                visible="http://localhost/iw/hello/world.jpg",
17
                masked="http://localhost/_aXcJaGVsbG8vd29ybGQJ.jpg",
18
            ),
19
            markdown=dict(
20
                visible="![iw](http://localhost/iw/hello/world.jpg)",
21
                masked="![iw](http://localhost/_aXcJaGVsbG8vd29ybGQJ.jpg)",
22
            ),
23
        )
24
25
    def with_top_only(client):
26
        status, data = load(client.get("/api/templates/iw/hello"))
27
28
        expect(status) == 200
29
        expect(data['direct']) == dict(
30
            visible="http://localhost/iw/hello.jpg",
31
            masked="http://localhost/_aXcJaGVsbG8J.jpg",
32
        )
33
34
    def with_bottom_only(client):
35
        status, data = load(client.get("/api/templates/iw/_/hello"))
36
37
        expect(status) == 200
38
        expect(data['direct']) == dict(
39
            visible="http://localhost/iw/_/hello.jpg",
40
            masked="http://localhost/_aXcJXy9oZWxsbwkJ.jpg",
41
        )
42
43
    def with_dashes(client):
44
        status, data = load(client.get(
45
            "/api/templates/iw/HelloThere_World/How-areYOU"))
46
47
        expect(status) == 302
48
        expect(data).contains(
49
            '<a href="/api/templates/iw/hello_there_world/how_are_you">')
50
51
    def when_masked(client):
52
        status, data = load(client.get("/_aXcJaGVsbG8vd29ybGQJ"))
53
54
        expect(status) == 302
55
        expect(data).contains('<a href="/api/templates/iw/hello/world">')
56
57
    def when_masked_with_1_line(client):
58
        status, data = load(client.get("/_aXcJaGVsbG8J"))
59
60
        expect(status) == 302
61
        expect(data).contains('<a href="/api/templates/iw/hello">')
62
63
    def when_alias(client):
64
        status, data = load(client.get("/api/templates/insanity-wolf"))
65
66
        expect(status) == 302
67
        expect(data).contains('<a href="/api/templates/iw">')
68
69
    def when_alias_with_text(client):
70
        status, data = load(client.get(
71
            "/api/templates/insanity-wolf/hello/world"))
72
73
        expect(status) == 302
74
        expect(data).contains('<a href="/api/templates/iw/hello/world">')
75
76
    def old_api_is_still_supported_via_redirect(client):
77
        status, data = load(client.get("/iw/top/bottom"))
78
79
        expect(status) == 302
80
        expect(data).contains('<a href="/api/templates/iw/top/bottom">')
81