@@ -788,5 +788,38 @@ def test_start_date_filter(self):
788
788
self .assertEqual (resp .status_code , 200 )
789
789
790
790
791
+ class TestDeleteDag (unittest .TestCase ):
792
+
793
+ def setUp (self ):
794
+ conf .load_test_config ()
795
+ app = application .create_app (testing = True )
796
+ app .config ['WTF_CSRF_METHODS' ] = []
797
+ self .app = app .test_client ()
798
+
799
+ def test_delete_dag_button_normal (self ):
800
+ resp = self .app .get ('/' , follow_redirects = True )
801
+ self .assertIn ('/delete?dag_id=example_bash_operator' , resp .data .decode ('utf-8' ))
802
+ self .assertIn ("return confirmDeleteDag('example_bash_operator')" , resp .data .decode ('utf-8' ))
803
+
804
+ def test_delete_dag_button_for_dag_on_scheduler_only (self ):
805
+ # Test for JIRA AIRFLOW-3233 (PR 4069):
806
+ # The delete-dag URL should be generated correctly for DAGs
807
+ # that exist on the scheduler (DB) but not the webserver DagBag
808
+
809
+ test_dag_id = "non_existent_dag"
810
+
811
+ session = Session ()
812
+ DM = models .DagModel
813
+ session .query (DM ).filter (DM .dag_id == 'example_bash_operator' ).update ({'dag_id' : test_dag_id })
814
+ session .commit ()
815
+
816
+ resp = self .app .get ('/' , follow_redirects = True )
817
+ self .assertIn ('/delete?dag_id={}' .format (test_dag_id ), resp .data .decode ('utf-8' ))
818
+ self .assertIn ("return confirmDeleteDag('{}')" .format (test_dag_id ), resp .data .decode ('utf-8' ))
819
+
820
+ session .query (DM ).filter (DM .dag_id == test_dag_id ).update ({'dag_id' : 'example_bash_operator' })
821
+ session .commit ()
822
+
823
+
791
824
if __name__ == '__main__' :
792
825
unittest .main ()
0 commit comments