Replaced nodes are properly removed and dependencies remapped.
(self)
| 310 | graph.validate_consistency() |
| 311 | |
| 312 | def test_remove_replaced_nodes(self): |
| 313 | """ |
| 314 | Replaced nodes are properly removed and dependencies remapped. |
| 315 | """ |
| 316 | # Add some dummy nodes to be replaced. |
| 317 | graph = MigrationGraph() |
| 318 | graph.add_dummy_node( |
| 319 | key=("app_a", "0001"), origin="app_a.0002", error_message="BAD!" |
| 320 | ) |
| 321 | graph.add_dummy_node( |
| 322 | key=("app_a", "0002"), origin="app_b.0001", error_message="BAD!" |
| 323 | ) |
| 324 | graph.add_dependency( |
| 325 | "app_a.0002", ("app_a", "0002"), ("app_a", "0001"), skip_validation=True |
| 326 | ) |
| 327 | # Add some normal parent and child nodes to test dependency remapping. |
| 328 | graph.add_node(("app_c", "0001"), None) |
| 329 | graph.add_node(("app_b", "0001"), None) |
| 330 | graph.add_dependency( |
| 331 | "app_a.0001", ("app_a", "0001"), ("app_c", "0001"), skip_validation=True |
| 332 | ) |
| 333 | graph.add_dependency( |
| 334 | "app_b.0001", ("app_b", "0001"), ("app_a", "0002"), skip_validation=True |
| 335 | ) |
| 336 | # Try replacing before replacement node exists. |
| 337 | msg = ( |
| 338 | "Unable to find replacement node ('app_a', '0001_squashed_0002'). It was " |
| 339 | "either never added to the migration graph, or has been removed." |
| 340 | ) |
| 341 | with self.assertRaisesMessage(NodeNotFoundError, msg): |
| 342 | graph.remove_replaced_nodes( |
| 343 | replacement=("app_a", "0001_squashed_0002"), |
| 344 | replaced=[("app_a", "0001"), ("app_a", "0002")], |
| 345 | ) |
| 346 | graph.add_node(("app_a", "0001_squashed_0002"), None) |
| 347 | # Ensure `validate_consistency()` still raises an error at this stage. |
| 348 | with self.assertRaisesMessage(NodeNotFoundError, "BAD!"): |
| 349 | graph.validate_consistency() |
| 350 | # Remove the dummy nodes. |
| 351 | graph.remove_replaced_nodes( |
| 352 | replacement=("app_a", "0001_squashed_0002"), |
| 353 | replaced=[("app_a", "0001"), ("app_a", "0002")], |
| 354 | ) |
| 355 | # Ensure graph is now consistent and dependencies have been remapped |
| 356 | graph.validate_consistency() |
| 357 | parent_node = graph.node_map[("app_c", "0001")] |
| 358 | replacement_node = graph.node_map[("app_a", "0001_squashed_0002")] |
| 359 | child_node = graph.node_map[("app_b", "0001")] |
| 360 | self.assertIn(parent_node, replacement_node.parents) |
| 361 | self.assertIn(replacement_node, parent_node.children) |
| 362 | self.assertIn(child_node, replacement_node.children) |
| 363 | self.assertIn(replacement_node, child_node.parents) |
| 364 | |
| 365 | def test_remove_replacement_node(self): |
| 366 | """ |
nothing calls this directly
no test coverage detected