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