| Conditions | 2 | 
| Total Lines | 68 | 
| Code Lines | 20 | 
| 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 -*- | ||
| 37 |     @patch('builtins.input', lambda *args: 'y') | ||
| 38 |     @patch('gvm.protocols.latest.Gmp', new_callable=GmpMockFactory) | ||
| 39 | def test_sent_task(self, mock_gmp: GmpMockFactory): | ||
| 40 | task_xml_path = CWD / 'example_task.xml' | ||
| 41 | task_xml_str = task_xml_path.read_text() | ||
| 42 | |||
| 43 | self.send_tasks.numerical_option = MagicMock(return_value=1) | ||
| 44 | |||
| 45 | mock_gmp.mock_response( | ||
| 46 | 'get_configs', | ||
| 47 | '<get_configs_response status="200" status_text="OK">' | ||
| 48 | '<config id="d21f6c81-2b88-4ac1-b7b4-a2a9f2ad4663">' | ||
| 49 | '<name>Base</name>' | ||
| 50 | '</config>' | ||
| 51 | '<config id="3fe6b460-e6ca-4af7-b712-1d7e9ea96eb0">' | ||
| 52 | '<name>BSI TR-03116: Part 4 (Date: 10. Januar 2020)</name>' | ||
| 53 | '</config>' | ||
| 54 | '<config id="8715c877-47a0-438d-98a3-27c7a6ab2196">' | ||
| 55 | '<name>Discovery</name>' | ||
| 56 | '</config>' | ||
| 57 | '</get_configs_response>', | ||
| 58 | ) | ||
| 59 | |||
| 60 | mock_gmp.mock_response( | ||
| 61 | 'get_scanners', | ||
| 62 | '<get_scanners_response status="200" status_text="OK">' | ||
| 63 | '<scanner id="c1c85af7-0cca-4690-8ccc-c79feb5588cf">' | ||
| 64 | '<name>as</name>' | ||
| 65 | '</scanner>' | ||
| 66 | '<scanner id="6acd0832-df90-11e4-b9d5-28d24461215b">' | ||
| 67 | '<name>CVE</name>' | ||
| 68 | '</scanner>' | ||
| 69 | '<scanner id="08b69003-5fc2-4037-a479-93b440211c73">' | ||
| 70 | '<name>OpenVAS Default</name>' | ||
| 71 | '</scanner>' | ||
| 72 | '</get_scanners_response>', | ||
| 73 | ) | ||
| 74 | |||
| 75 | mock_gmp.mock_response( | ||
| 76 | 'get_targets', | ||
| 77 | '<get_targets_response status="200" status_text="OK">' | ||
| 78 | '<target id="60f95d0e-029e-4931-a13a-b1d11260517d">' | ||
| 79 | '<name>own</name>' | ||
| 80 | '</target>' | ||
| 81 | '<target id="ead9576c-5a4d-4081-b98d-ccd77d5d16f8">' | ||
| 82 | '<name>Target for xn</name>' | ||
| 83 | '</target>' | ||
| 84 | '<target id="6c9f73f5-f14c-42bf-ab44-edb8d2493dbc">' | ||
| 85 | '<name>Unnamed</name>' | ||
| 86 | '</target>' | ||
| 87 | '<target id="a1f478c1-27d0-4d8c-959f-150625186421">' | ||
| 88 | '<name>work</name>' | ||
| 89 | '</target>' | ||
| 90 | '<target id="5ca97fe1-694d-4e4a-bd4c-55529719d17e">' | ||
| 91 | '<name>work2</name>' | ||
| 92 | '</target>' | ||
| 93 | '</get_targets_response>', | ||
| 94 | ) | ||
| 95 | |||
| 96 | mock_gmp.mock_response( | ||
| 97 | 'create_task', | ||
| 98 | '<create_task_response status="201" status_text="OK,' | ||
| 99 | 'resource created" id="c8ef0597-e2c1-4e23-869f-072fa2914bf2"/>', | ||
| 100 | ) | ||
| 101 | |||
| 102 | task = etree.XML(task_xml_str) | ||
| 103 | |||
| 104 | self.send_tasks.parse_send_xml_tree(mock_gmp.gmp_protocol, task) | ||
| 105 |