Conditions | 1 |
Total Lines | 80 |
Code Lines | 23 |
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 -*- |
||
132 | @patch('gvm.protocols.latest.Gmp', new_callable=GmpMockFactory) |
||
133 | def test_create_and_start_task(self, mock_gmp: GmpMockFactory): |
||
134 | alert_name = 'test_alert' |
||
135 | alert_id = '3eefd4b9-59ec-48d6-b84d-f6a73bdb909f' |
||
136 | target_id = '3b76a0c2-14fc-4de2-868c-35132977a25e' |
||
137 | config_id = 'daba56c8-73ec-11df-a475-002264764cea' |
||
138 | scanner_id = '08b69003-5fc2-4037-a479-93b440211c73' |
||
139 | |||
140 | task_id = 'd78453ab-d907-44b6-abe0-2ef54a77f1c2' |
||
141 | |||
142 | mock_gmp.mock_response( |
||
143 | 'create_task', |
||
144 | '<create_task_response status="201" status_text=' |
||
145 | f'"OK, resource created" id="{task_id}"/>', |
||
146 | ) |
||
147 | |||
148 | mock_gmp.mock_response( |
||
149 | 'get_tasks', |
||
150 | """ |
||
151 | <get_tasks_response status="200" status_text="OK"> |
||
152 | <apply_overrides>0</apply_overrides> |
||
153 | <filters id=""> |
||
154 | <term> |
||
155 | apply_overrides=0 min_qod=70 |
||
156 | name="Alert Scan for Alert test_alert" first=1 rows=100 sort=name |
||
157 | </term> |
||
158 | <keywords> |
||
159 | <keyword> |
||
160 | <column>apply_overrides</column> |
||
161 | <relation>=</relation> |
||
162 | <value>0</value> |
||
163 | </keyword> |
||
164 | <keyword> |
||
165 | <column>min_qod</column> |
||
166 | <relation>=</relation> |
||
167 | <value>70</value> |
||
168 | </keyword> |
||
169 | <keyword> |
||
170 | <column>name</column> |
||
171 | <relation>=</relation> |
||
172 | <value>"Alert Scan for Alert test_alert"</value> |
||
173 | </keyword> |
||
174 | <keyword> |
||
175 | <column>first</column> |
||
176 | <relation>=</relation> |
||
177 | <value>1</value> |
||
178 | </keyword> |
||
179 | <keyword> |
||
180 | <column>rows</column> |
||
181 | <relation>=</relation> |
||
182 | <value>100</value> |
||
183 | </keyword> |
||
184 | <keyword> |
||
185 | <column>sort</column> |
||
186 | <relation>=</relation> |
||
187 | <value>name</value> |
||
188 | </keyword> |
||
189 | </keywords> |
||
190 | </filters> |
||
191 | <sort> |
||
192 | <field>name<order>ascending</order></field> |
||
193 | </sort> |
||
194 | <tasks start="1" max="100"/> |
||
195 | <task_count>27<filtered>0</filtered><page>0</page></task_count> |
||
196 | </get_tasks_response> |
||
197 | """, |
||
198 | ) |
||
199 | |||
200 | task_name = "Alert Scan for Alert {}".format(alert_name) |
||
201 | |||
202 | returned_name = self.start_alert_scan.create_and_start_task( |
||
203 | gmp=mock_gmp.gmp_protocol, |
||
204 | config_id=config_id, |
||
205 | target_id=target_id, |
||
206 | scanner_id=scanner_id, |
||
207 | alert_id=alert_id, |
||
208 | alert_name=alert_name, |
||
209 | ) |
||
210 | |||
211 | self.assertEqual(task_name, returned_name) |
||
212 |