| Conditions | 1 |
| Total Lines | 127 |
| Lines | 0 |
| Ratio | 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 | # Licensed to the StackStorm, Inc ('StackStorm') under one or more |
||
| 61 | def test_node_create_alias(self): |
||
| 62 | format_strings = self.action_alias_db.get_format_strings() |
||
| 63 | |||
| 64 | # First Format 'orion node create' |
||
| 65 | format_string = self.action_alias_db.formats[0]['representation'][0] |
||
| 66 | command = "orion node create router1 ip 192.168.0.1 snmp read platform orion" |
||
| 67 | expected_parameters = { |
||
| 68 | 'ip_address': "192.168.0.1", |
||
| 69 | 'node': 'router1', |
||
| 70 | 'platform': 'orion', |
||
| 71 | 'poller': 'primary', |
||
| 72 | 'std_community': 'read' |
||
| 73 | } |
||
| 74 | self.assertExtractedParametersMatch(format_string=format_string, |
||
| 75 | command=command, |
||
| 76 | parameters=expected_parameters) |
||
| 77 | self.assertCommandMatchesExactlyOneFormatString( |
||
| 78 | format_strings=format_strings, |
||
| 79 | command=command) |
||
| 80 | |||
| 81 | command = "orion node create router1 ip 192.168.0.1 platform orion poller1" |
||
| 82 | expected_parameters = { |
||
| 83 | 'ip_address': "192.168.0.1", |
||
| 84 | 'node': 'router1', |
||
| 85 | 'platform': 'orion', |
||
| 86 | 'poller': 'poller1', |
||
| 87 | 'std_community': None |
||
| 88 | } |
||
| 89 | self.assertExtractedParametersMatch(format_string=format_string, |
||
| 90 | command=command, |
||
| 91 | parameters=expected_parameters) |
||
| 92 | self.assertCommandMatchesExactlyOneFormatString( |
||
| 93 | format_strings=format_strings, |
||
| 94 | command=command) |
||
| 95 | |||
| 96 | command = "orion node create router1 ip 192.168.0.1 snmp read" |
||
| 97 | expected_parameters = { |
||
| 98 | 'ip_address': "192.168.0.1", |
||
| 99 | 'node': 'router1', |
||
| 100 | 'platform': None, |
||
| 101 | 'poller': 'primary', |
||
| 102 | 'std_community': 'read' |
||
| 103 | } |
||
| 104 | self.assertExtractedParametersMatch(format_string=format_string, |
||
| 105 | command=command, |
||
| 106 | parameters=expected_parameters) |
||
| 107 | self.assertCommandMatchesExactlyOneFormatString( |
||
| 108 | format_strings=format_strings, |
||
| 109 | command=command) |
||
| 110 | |||
| 111 | command = "orion node create router1 ip 192.168.0.1" |
||
| 112 | expected_parameters = { |
||
| 113 | 'ip_address': "192.168.0.1", |
||
| 114 | 'node': 'router1', |
||
| 115 | 'platform': None, |
||
| 116 | 'poller': 'primary', |
||
| 117 | 'std_community': None |
||
| 118 | } |
||
| 119 | self.assertExtractedParametersMatch(format_string=format_string, |
||
| 120 | command=command, |
||
| 121 | parameters=expected_parameters) |
||
| 122 | self.assertCommandMatchesExactlyOneFormatString( |
||
| 123 | format_strings=format_strings, |
||
| 124 | command=command) |
||
| 125 | |||
| 126 | # Second format 'create orion node' |
||
| 127 | format_string = self.action_alias_db.formats[1]['representation'][0] |
||
| 128 | |||
| 129 | command = "create orion node router1 at 192.168.0.1 with read on orion poller1" |
||
| 130 | expected_parameters = { |
||
| 131 | 'ip_address': "192.168.0.1", |
||
| 132 | 'node': 'router1', |
||
| 133 | 'platform': 'orion', |
||
| 134 | 'poller': 'poller1', |
||
| 135 | 'std_community': 'read' |
||
| 136 | } |
||
| 137 | self.assertExtractedParametersMatch(format_string=format_string, |
||
| 138 | command=command, |
||
| 139 | parameters=expected_parameters) |
||
| 140 | self.assertCommandMatchesExactlyOneFormatString( |
||
| 141 | format_strings=format_strings, |
||
| 142 | command=command) |
||
| 143 | |||
| 144 | command = "create orion node router1 at 192.168.0.1 with read" |
||
| 145 | expected_parameters = { |
||
| 146 | 'ip_address': "192.168.0.1", |
||
| 147 | 'node': 'router1', |
||
| 148 | 'platform': None, |
||
| 149 | 'poller': 'primary', |
||
| 150 | 'std_community': 'read' |
||
| 151 | } |
||
| 152 | self.assertExtractedParametersMatch(format_string=format_string, |
||
| 153 | command=command, |
||
| 154 | parameters=expected_parameters) |
||
| 155 | self.assertCommandMatchesExactlyOneFormatString( |
||
| 156 | format_strings=format_strings, |
||
| 157 | command=command) |
||
| 158 | |||
| 159 | command = "create orion node router1 at 192.168.0.1 on orion" |
||
| 160 | expected_parameters = { |
||
| 161 | 'ip_address': "192.168.0.1", |
||
| 162 | 'node': 'router1', |
||
| 163 | 'platform': 'orion', |
||
| 164 | 'poller': 'primary', |
||
| 165 | 'std_community': None |
||
| 166 | } |
||
| 167 | self.assertExtractedParametersMatch(format_string=format_string, |
||
| 168 | command=command, |
||
| 169 | parameters=expected_parameters) |
||
| 170 | self.assertCommandMatchesExactlyOneFormatString( |
||
| 171 | format_strings=format_strings, |
||
| 172 | command=command) |
||
| 173 | |||
| 174 | command = "create orion node router1 at 192.168.0.1" |
||
| 175 | expected_parameters = { |
||
| 176 | 'ip_address': "192.168.0.1", |
||
| 177 | 'node': 'router1', |
||
| 178 | 'platform': None, |
||
| 179 | 'poller': 'primary', |
||
| 180 | 'std_community': None |
||
| 181 | } |
||
| 182 | self.assertExtractedParametersMatch(format_string=format_string, |
||
| 183 | command=command, |
||
| 184 | parameters=expected_parameters) |
||
| 185 | self.assertCommandMatchesExactlyOneFormatString( |
||
| 186 | format_strings=format_strings, |
||
| 187 | command=command) |
||
| 188 |