Conditions | 1 |
Total Lines | 139 |
Code Lines | 9 |
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 | # -*- coding: utf-8 -*- |
||
44 | def create_gmp_mock(self): |
||
45 | mock_gmp = MagicMock() |
||
46 | credentials = etree.XML( |
||
47 | """ |
||
48 | <get_credentials_response status="200" status_text="OK"> |
||
49 | <credential id="6da5b7de-92ad-4dd2-8610-d5711b9c5937"> |
||
50 | <owner> |
||
51 | <name>jloechte</name> |
||
52 | </owner> |
||
53 | <name>test_</name> |
||
54 | <comment>comm</comment> |
||
55 | <creation_time>2020-09-17T07:34:32Z</creation_time> |
||
56 | <modification_time>2020-09-30T00:46:44Z</modification_time> |
||
57 | <writable>1</writable> |
||
58 | <in_use>1</in_use> |
||
59 | <permissions> |
||
60 | <permission> |
||
61 | <name>Everything</name> |
||
62 | </permission> |
||
63 | </permissions> |
||
64 | <allow_insecure>0</allow_insecure> |
||
65 | <login>sdfsdf</login> |
||
66 | <type>up</type> |
||
67 | <full_type>username + password</full_type> |
||
68 | <formats> |
||
69 | <format>exe</format> |
||
70 | </formats> |
||
71 | </credential> |
||
72 | <credential id="7802648d-1a31-4f69-bb30-00766a1ae1e6"> |
||
73 | <owner> |
||
74 | <name>jloechte</name> |
||
75 | </owner> |
||
76 | <name>Unnamed</name> |
||
77 | <comment></comment> |
||
78 | <creation_time>2020-09-29T20:44:49Z</creation_time> |
||
79 | <modification_time>2020-09-29T20:45:00Z</modification_time> |
||
80 | <writable>1</writable> |
||
81 | <in_use>1</in_use> |
||
82 | <permissions> |
||
83 | <permission> |
||
84 | <name>Everything</name> |
||
85 | </permission> |
||
86 | </permissions> |
||
87 | <allow_insecure>0</allow_insecure> |
||
88 | <login>rterte</login> |
||
89 | <type>usk</type> |
||
90 | <full_type>username + SSH key</full_type> |
||
91 | <formats> |
||
92 | <format>key</format> |
||
93 | <format>rpm</format> |
||
94 | <format>deb</format> |
||
95 | </formats> |
||
96 | </credential> |
||
97 | <credential id="70a63257-4923-4bf4-a9bb-dd8b710b2d80"> |
||
98 | <owner> |
||
99 | <name>jloechte</name> |
||
100 | </owner> |
||
101 | <name>Unnamedas</name> |
||
102 | <comment></comment> |
||
103 | <creation_time>2020-09-29T21:31:50Z</creation_time> |
||
104 | <modification_time>2020-09-29T21:32:57Z</modification_time> |
||
105 | <writable>1</writable> |
||
106 | <in_use>0</in_use> |
||
107 | <permissions> |
||
108 | <permission> |
||
109 | <name>Everything</name> |
||
110 | </permission> |
||
111 | </permissions> |
||
112 | <allow_insecure>0</allow_insecure> |
||
113 | <login>abc</login> |
||
114 | <type>snmp</type> |
||
115 | <full_type>SNMP</full_type> |
||
116 | <formats></formats> |
||
117 | <auth_algorithm>sha1</auth_algorithm> |
||
118 | <privacy> |
||
119 | <algorithm>des</algorithm> |
||
120 | </privacy> |
||
121 | </credential> |
||
122 | <credential id="2bac0c76-795e-4742-b17a-808a0ec8e409"> |
||
123 | <owner> |
||
124 | <name>jloechte</name> |
||
125 | </owner> |
||
126 | <name>work</name> |
||
127 | <comment>test</comment> |
||
128 | <creation_time>2020-08-18T18:35:04Z</creation_time> |
||
129 | <modification_time>2020-09-29T20:43:16Z</modification_time> |
||
130 | <writable>1</writable> |
||
131 | <in_use>1</in_use> |
||
132 | <permissions> |
||
133 | <permission> |
||
134 | <name>Everything</name> |
||
135 | </permission> |
||
136 | </permissions> |
||
137 | <allow_insecure>0</allow_insecure> |
||
138 | <login>jloechte</login> |
||
139 | <type>up</type> |
||
140 | <full_type>username + password</full_type> |
||
141 | <formats> |
||
142 | <format>exe</format> |
||
143 | </formats> |
||
144 | </credential> |
||
145 | <filters id=""> |
||
146 | <term>first=1 rows=10 sort=name</term> |
||
147 | <keywords> |
||
148 | <keyword> |
||
149 | <column>first</column> |
||
150 | <relation>=</relation> |
||
151 | <value>1</value> |
||
152 | </keyword> |
||
153 | <keyword> |
||
154 | <column>rows</column> |
||
155 | <relation>=</relation> |
||
156 | <value>10</value> |
||
157 | </keyword> |
||
158 | <keyword> |
||
159 | <column>sort</column> |
||
160 | <relation>=</relation> |
||
161 | <value>name</value> |
||
162 | </keyword> |
||
163 | </keywords> |
||
164 | </filters> |
||
165 | <sort> |
||
166 | <field>name<order>ascending</order> |
||
167 | </field> |
||
168 | </sort> |
||
169 | <credentials start="1" max="-2"/> |
||
170 | <credential_count>4<filtered>4</filtered> |
||
171 | <page>4</page> |
||
172 | </credential_count> |
||
173 | </get_credentials_response> |
||
174 | """ |
||
175 | ) |
||
176 | mock_gmp.get_credentials = MagicMock(return_value=credentials) |
||
177 | target = etree.XML( |
||
178 | """<create_target_response status="201" status_text="OK, |
||
179 | resource created" id="6c9f73f5-f14c-42bf-ab44-edb8d2493dbc"/>""" |
||
180 | ) |
||
181 | mock_gmp.create_target = MagicMock(return_value=target) |
||
182 | return mock_gmp |
||
183 | |||
230 |