@@ -470,6 +470,64 @@ def create_and_cleanup(name: str, dev_table_only: bool):
470
470
)
471
471
472
472
473
+ def test_cleanup_view (adapter_mock , make_snapshot ):
474
+ evaluator = SnapshotEvaluator (adapter_mock )
475
+
476
+ model = SqlModel (
477
+ name = "catalog.test_schema.test_model" ,
478
+ kind = ViewKind (materialized = False ),
479
+ query = parse_one ("SELECT a FROM tbl" ),
480
+ )
481
+
482
+ snapshot = make_snapshot (model )
483
+ snapshot .categorize_as (SnapshotChangeCategory .BREAKING , forward_only = True )
484
+
485
+ evaluator .promote ([snapshot ], EnvironmentNamingInfo (name = "test_env" ))
486
+ evaluator .cleanup ([SnapshotTableCleanupTask (snapshot = snapshot .table_info , dev_table_only = True )])
487
+
488
+ adapter_mock .get_data_object .assert_not_called ()
489
+ adapter_mock .drop_view .assert_called_once_with (
490
+ f"catalog.sqlmesh__test_schema.test_schema__test_model__{ snapshot .fingerprint .to_version ()} __dev" ,
491
+ cascade = True ,
492
+ ignore_if_not_exists = False ,
493
+ )
494
+
495
+
496
+ def test_cleanup_materialized_view (adapter_mock , make_snapshot ):
497
+ evaluator = SnapshotEvaluator (adapter_mock )
498
+
499
+ model = SqlModel (
500
+ name = "catalog.test_schema.test_model" ,
501
+ kind = ViewKind (materialized = True ),
502
+ query = parse_one ("SELECT a FROM tbl" ),
503
+ )
504
+
505
+ snapshot = make_snapshot (model )
506
+ snapshot .categorize_as (SnapshotChangeCategory .BREAKING , forward_only = True )
507
+
508
+ adapter_mock .drop_view .side_effect = [RuntimeError ("failed to drop view" ), None ]
509
+
510
+ evaluator .promote ([snapshot ], EnvironmentNamingInfo (name = "test_env" ))
511
+ evaluator .cleanup ([SnapshotTableCleanupTask (snapshot = snapshot .table_info , dev_table_only = True )])
512
+
513
+ adapter_mock .get_data_object .assert_not_called ()
514
+ adapter_mock .drop_view .assert_has_calls (
515
+ [
516
+ call (
517
+ f"catalog.sqlmesh__test_schema.test_schema__test_model__{ snapshot .fingerprint .to_version ()} __dev" ,
518
+ cascade = True ,
519
+ ignore_if_not_exists = False ,
520
+ ),
521
+ call (
522
+ f"catalog.sqlmesh__test_schema.test_schema__test_model__{ snapshot .fingerprint .to_version ()} __dev" ,
523
+ materialized = True ,
524
+ cascade = True ,
525
+ ignore_if_not_exists = True ,
526
+ ),
527
+ ]
528
+ )
529
+
530
+
473
531
def test_cleanup_fails (adapter_mock , make_snapshot ):
474
532
adapter_mock .drop_table .side_effect = RuntimeError ("test_error" )
475
533
0 commit comments