airflow-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From msu...@apache.org
Subject incubator-airflow git commit: [AIRFLOW-1478] Chart owner column should be sortable
Date Fri, 04 Aug 2017 12:44:29 GMT
Repository: incubator-airflow
Updated Branches:
  refs/heads/master 84215b367 -> 651e6063d


[AIRFLOW-1478] Chart owner column should be sortable

Closes #2493 from skudriashev/airflow-1478


Project: http://git-wip-us.apache.org/repos/asf/incubator-airflow/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-airflow/commit/651e6063
Tree: http://git-wip-us.apache.org/repos/asf/incubator-airflow/tree/651e6063
Diff: http://git-wip-us.apache.org/repos/asf/incubator-airflow/diff/651e6063

Branch: refs/heads/master
Commit: 651e6063deaf978513940c4ee5579a82ea2b787a
Parents: 84215b3
Author: Stanislav Kudriashev <stas.kudriashev@gmail.com>
Authored: Fri Aug 4 18:14:47 2017 +0530
Committer: Sumit Maheshwari <sumeet.manit@gmail.com>
Committed: Fri Aug 4 18:14:47 2017 +0530

----------------------------------------------------------------------
 airflow/www/views.py    | 17 ++++++++++--
 tests/www/test_views.py | 62 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 77 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-airflow/blob/651e6063/airflow/www/views.py
----------------------------------------------------------------------
diff --git a/airflow/www/views.py b/airflow/www/views.py
index 046c2e1..07e0e18 100644
--- a/airflow/www/views.py
+++ b/airflow/www/views.py
@@ -2095,9 +2095,22 @@ class ChartModelView(wwwutils.DataProfilingMixin, AirflowModelView):
         'height',
         'sql_layout',
         'sql',
-        'default_params',)
+        'default_params',
+    )
     column_list = (
-        'label', 'conn_id', 'chart_type', 'owner', 'last_modified',)
+        'label',
+        'conn_id',
+        'chart_type',
+        'owner',
+        'last_modified',
+    )
+    column_sortable_list = (
+        'label',
+        'conn_id',
+        'chart_type',
+        ('owner', 'owner.username'),
+        'last_modified',
+    )
     column_formatters = dict(label=label_link, last_modified=datetime_f)
     column_default_sort = ('last_modified', True)
     create_template = 'airflow/chart/create.html'

http://git-wip-us.apache.org/repos/asf/incubator-airflow/blob/651e6063/tests/www/test_views.py
----------------------------------------------------------------------
diff --git a/tests/www/test_views.py b/tests/www/test_views.py
index 5a20cbd..5c0eefa 100644
--- a/tests/www/test_views.py
+++ b/tests/www/test_views.py
@@ -20,6 +20,68 @@ from airflow.settings import Session
 from airflow.www import app as application
 
 
+class TestChartModelView(unittest.TestCase):
+
+    CREATE_ENDPOINT = '/admin/chart/new/?url=/admin/chart/'
+
+    @classmethod
+    def setUpClass(cls):
+        super(TestChartModelView, cls).setUpClass()
+        session = Session()
+        session.query(models.Chart).delete()
+        session.query(models.User).delete()
+        session.commit()
+        user = models.User(username='airflow')
+        session.add(user)
+        session.commit()
+        session.close()
+
+    def setUp(self):
+        super(TestChartModelView, self).setUp()
+        configuration.load_test_config()
+        app = application.create_app(testing=True)
+        app.config['WTF_CSRF_METHODS'] = []
+        self.app = app.test_client()
+        self.session = Session()
+        self.chart = {
+            'label': 'chart',
+            'owner': 'airflow',
+            'conn_id': 'airflow_ci',
+        }
+
+    def tearDown(self):
+        self.session.query(models.Chart).delete()
+        self.session.commit()
+        self.session.close()
+        super(TestChartModelView, self).tearDown()
+
+    @classmethod
+    def tearDownClass(cls):
+        session = Session()
+        session.query(models.User).delete()
+        session.commit()
+        session.close()
+        super(TestChartModelView, cls).tearDownClass()
+
+    def test_create_chart(self):
+        response = self.app.post(
+            self.CREATE_ENDPOINT,
+            data=self.chart,
+            follow_redirects=True,
+        )
+        self.assertEqual(response.status_code, 200)
+        self.assertEqual(self.session.query(models.Chart).count(), 1)
+
+    def test_get_chart(self):
+        response = self.app.get(
+            '/admin/chart?sort=3',
+            follow_redirects=True,
+        )
+        print(response.data)
+        self.assertEqual(response.status_code, 200)
+        self.assertIn('Sort by Owner', response.data.decode('utf-8'))
+
+
 class TestKnownEventView(unittest.TestCase):
 
     CREATE_ENDPOINT = '/admin/knownevent/new/?url=/admin/knownevent/'


Mime
View raw message