You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2019/01/09 20:23:07 UTC

[GitHub] kaxil closed pull request #4464: [AIRFLOW-3646] Rename plugins_manager.py to test_xx to trigger tests

kaxil closed pull request #4464: [AIRFLOW-3646] Rename plugins_manager.py to test_xx to trigger tests
URL: https://github.com/apache/airflow/pull/4464
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/tests/plugins/__init__.py b/tests/plugins/__init__.py
new file mode 100644
index 0000000000..114d189da1
--- /dev/null
+++ b/tests/plugins/__init__.py
@@ -0,0 +1,18 @@
+# -*- coding: utf-8 -*-
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
diff --git a/tests/plugins/test_plugin.py b/tests/plugins/test_plugin.py
index 058a2bb227..68aa989a2e 100644
--- a/tests/plugins/test_plugin.py
+++ b/tests/plugins/test_plugin.py
@@ -58,7 +58,7 @@ def plugin_macro():
 
 
 # Creating a flask admin BaseView
-class TestView(BaseView):
+class PluginTestView(BaseView):
     @expose('/')
     def test(self):
         # in this example, put your test_plugin/test.html
@@ -66,11 +66,11 @@ def test(self):
         return self.render("test_plugin/test.html", content="Hello galaxy!")
 
 
-v = TestView(category="Test Plugin", name="Test View")
+v = PluginTestView(category="Test Plugin", name="Test View")
 
 
 # Creating a flask appbuilder BaseView
-class TestAppBuilderBaseView(AppBuilderBaseView):
+class PluginTestAppBuilderBaseView(AppBuilderBaseView):
     default_view = "test"
 
     @expose("/")
@@ -78,7 +78,7 @@ def test(self):
         return self.render("test_plugin/test.html", content="Hello galaxy!")
 
 
-v_appbuilder_view = TestAppBuilderBaseView()
+v_appbuilder_view = PluginTestAppBuilderBaseView()
 v_appbuilder_package = {"name": "Test View",
                         "category": "Test Plugin",
                         "view": v_appbuilder_view}
diff --git a/tests/plugins/test_plugins_manager_rbac.py b/tests/plugins/test_plugins_manager_rbac.py
new file mode 100644
index 0000000000..b33464d397
--- /dev/null
+++ b/tests/plugins/test_plugins_manager_rbac.py
@@ -0,0 +1,68 @@
+# -*- coding: utf-8 -*-
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+from __future__ import absolute_import
+from __future__ import division
+from __future__ import print_function
+from __future__ import unicode_literals
+
+import unittest
+
+
+from airflow.configuration import conf
+from airflow.www_rbac import app as application
+
+
+class PluginsTestRBAC(unittest.TestCase):
+    def setUp(self):
+        conf.load_test_config()
+        self.app, self.appbuilder = application.create_app(testing=True)
+
+    def test_flaskappbuilder_views(self):
+        from tests.plugins.test_plugin import v_appbuilder_package
+        appbuilder_class_name = str(v_appbuilder_package['view'].__class__.__name__)
+        plugin_views = [view for view in self.appbuilder.baseviews
+                        if view.blueprint.name == appbuilder_class_name]
+
+        self.assertTrue(len(plugin_views) == 1)
+
+        # view should have a menu item matching category of v_appbuilder_package
+        links = [menu_item for menu_item in self.appbuilder.menu.menu
+                 if menu_item.name == v_appbuilder_package['category']]
+
+        self.assertTrue(len(links) == 1)
+
+        # menu link should also have a link matching the name of the package.
+        link = links[0]
+        self.assertEqual(link.name, v_appbuilder_package['category'])
+        self.assertEqual(link.childs[0].name, v_appbuilder_package['name'])
+
+    def test_flaskappbuilder_menu_links(self):
+        from tests.plugins.test_plugin import appbuilder_mitem
+
+        # menu item should exist matching appbuilder_mitem
+        links = [menu_item for menu_item in self.appbuilder.menu.menu
+                 if menu_item.name == appbuilder_mitem['category']]
+
+        self.assertTrue(len(links) == 1)
+
+        # menu link should also have a link matching the name of the package.
+        link = links[0]
+        self.assertEqual(link.name, appbuilder_mitem['category'])
+        self.assertEqual(link.childs[0].name, appbuilder_mitem['name'])
diff --git a/tests/plugins_manager.py b/tests/plugins/test_plugins_manager_www.py
similarity index 63%
rename from tests/plugins_manager.py
rename to tests/plugins/test_plugins_manager_www.py
index eeb6494100..130bd32c73 100644
--- a/tests/plugins_manager.py
+++ b/tests/plugins/test_plugins_manager_www.py
@@ -27,13 +27,11 @@
 from flask.blueprints import Blueprint
 from flask_admin.menu import MenuLink, MenuView
 
-from airflow.configuration import conf
 from airflow.hooks.base_hook import BaseHook
 from airflow.models import BaseOperator
 from airflow.sensors.base_sensor_operator import BaseSensorOperator
 from airflow.executors.base_executor import BaseExecutor
-from airflow.www.app import cached_app
-from airflow.www_rbac import app as application
+from airflow.www.app import create_app
 
 
 class PluginsTest(unittest.TestCase):
@@ -67,7 +65,7 @@ def test_macros(self):
         self.assertTrue(callable(plugin_macro))
 
     def test_admin_views(self):
-        app = cached_app()
+        app = create_app(testing=True)
         [admin] = app.extensions['admin']
         category = admin._menu_categories['Test Plugin']
         [admin_view] = [v for v in category.get_children()
@@ -75,52 +73,13 @@ def test_admin_views(self):
         self.assertEqual('Test View', admin_view.name)
 
     def test_flask_blueprints(self):
-        app = cached_app()
+        app = create_app(testing=True)
         self.assertIsInstance(app.blueprints['test_plugin'], Blueprint)
 
     def test_menu_links(self):
-        app = cached_app()
+        app = create_app(testing=True)
         [admin] = app.extensions['admin']
         category = admin._menu_categories['Test Plugin']
         [menu_link] = [ml for ml in category.get_children()
                        if isinstance(ml, MenuLink)]
         self.assertEqual('Test Menu Link', menu_link.name)
-
-
-class PluginsTestRBAC(unittest.TestCase):
-    def setUp(self):
-        conf.load_test_config()
-        self.app, self.appbuilder = application.create_app(testing=True)
-
-    def test_flaskappbuilder_views(self):
-        from tests.plugins.test_plugin import v_appbuilder_package
-        appbuilder_class_name = str(v_appbuilder_package['view'].__class__.__name__)
-        plugin_views = [view for view in self.appbuilder.baseviews
-                        if view.blueprint.name == appbuilder_class_name]
-
-        self.assertTrue(len(plugin_views) == 1)
-
-        # view should have a menu item matching category of v_appbuilder_package
-        links = [menu_item for menu_item in self.appbuilder.menu.menu
-                 if menu_item.name == v_appbuilder_package['category']]
-
-        self.assertTrue(len(links) == 1)
-
-        # menu link should also have a link matching the name of the package.
-        link = links[0]
-        self.assertEqual(link.name, v_appbuilder_package['category'])
-        self.assertEqual(link.childs[0].name, v_appbuilder_package['name'])
-
-    def test_flaskappbuilder_menu_links(self):
-        from tests.plugins.test_plugin import appbuilder_mitem
-
-        # menu item should exist matching appbuilder_mitem
-        links = [menu_item for menu_item in self.appbuilder.menu.menu
-                 if menu_item.name == appbuilder_mitem['category']]
-
-        self.assertTrue(len(links) == 1)
-
-        # menu link should also have a link matching the name of the package.
-        link = links[0]
-        self.assertEqual(link.name, appbuilder_mitem['category'])
-        self.assertEqual(link.childs[0].name, appbuilder_mitem['name'])


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services