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