| Conditions | 6 |
| Total Lines | 78 |
| Code Lines | 63 |
| 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 | """Module to test the EVCBase class.""" |
||
| 161 | def test_as_dict(self): |
||
| 162 | """Test the method as_dict.""" |
||
| 163 | attributes = { |
||
| 164 | "controller": get_controller_mock(), |
||
| 165 | "id": "custom_id", |
||
| 166 | "name": "custom_name", |
||
| 167 | "uni_a": get_uni_mocked(is_valid=True), |
||
| 168 | "uni_z": get_uni_mocked(is_valid=True), |
||
| 169 | "start_date": '2018-08-21T18:44:54', |
||
| 170 | "end_date": '2018-08-21T18:44:55', |
||
| 171 | 'primary_links': [], |
||
| 172 | 'request_time': '2018-08-21T19:10:41', |
||
| 173 | 'creation_time': '2018-08-21T18:44:54', |
||
| 174 | 'owner': "my_name", |
||
| 175 | 'circuit_scheduler': [ |
||
| 176 | CircuitSchedule.from_dict({"id":234243247, "action":"create", |
||
| 177 | "frequency":"1 * * * *"}), |
||
| 178 | CircuitSchedule.from_dict({"id":234243239, "action":"create", |
||
| 179 | "interval":{"hours": 2}}) |
||
| 180 | ], |
||
| 181 | 'enabled': True, |
||
| 182 | 'priority': 2 |
||
| 183 | } |
||
| 184 | evc = EVC(**attributes) |
||
| 185 | |||
| 186 | expected_dict = { |
||
| 187 | 'id': 'custom_id', |
||
| 188 | 'name': 'custom_name', |
||
| 189 | 'uni_a': attributes['uni_a'].as_dict(), |
||
| 190 | 'uni_z': attributes['uni_z'].as_dict(), |
||
| 191 | 'start_date': '2018-08-21T18:44:54', |
||
| 192 | 'end_date': '2018-08-21T18:44:55', |
||
| 193 | 'bandwidth': 0, |
||
| 194 | 'primary_links': [], |
||
| 195 | 'backup_links': [], |
||
| 196 | 'current_path': [], |
||
| 197 | 'primary_path': [], |
||
| 198 | 'backup_path': [], |
||
| 199 | 'dynamic_backup_path': False, |
||
| 200 | 'request_time': '2018-08-21T19:10:41', |
||
| 201 | 'creation_time': '2018-08-21T18:44:54', |
||
| 202 | 'circuit_scheduler': [ |
||
| 203 | { |
||
| 204 | "id": 234243247, |
||
| 205 | "action": "create", |
||
| 206 | "frequency": "1 * * * *" |
||
| 207 | }, |
||
| 208 | { |
||
| 209 | "id": 234243239, |
||
| 210 | "action": "create", |
||
| 211 | "interval": { |
||
| 212 | "hours": 2 |
||
| 213 | } |
||
| 214 | } |
||
| 215 | ], |
||
| 216 | 'active': False, |
||
| 217 | 'enabled': True, |
||
| 218 | 'priority': 2 |
||
| 219 | } |
||
| 220 | actual_dict = evc.as_dict() |
||
| 221 | for name, value in expected_dict.items(): |
||
| 222 | actual = actual_dict.get(name) |
||
| 223 | if name == 'circuit_scheduler': |
||
| 224 | obj_value = {} |
||
| 225 | obj_actual = {} |
||
| 226 | |||
| 227 | for index, actual_item in enumerate(actual): |
||
| 228 | actual_item = actual_item.as_dict() |
||
| 229 | for actual_name, actual_value in actual_item.items(): |
||
| 230 | obj_actual[actual_name] = actual_value |
||
| 231 | |||
| 232 | # Check the scheduled expected items |
||
| 233 | circuit_schedule = value[index] |
||
| 234 | for schedule_name, schedule_value in circuit_schedule.items(): |
||
| 235 | obj_value[schedule_name] = schedule_value |
||
| 236 | self.assertEqual(obj_value[schedule_name], obj_actual[schedule_name]) |
||
| 237 | else: |
||
| 238 | self.assertEqual(value, actual) |
||
| 239 |