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