[GitHub] [airflow] kaxil edited a comment on issue #8308: Fix Extra Links in Gannt View

2020-04-21 Thread GitBox


kaxil edited a comment on issue #8308:
URL: https://github.com/apache/airflow/pull/8308#issuecomment-617461852


   > @ashb we can also mock jinja and check template params. POC: #8505
   
   Was able to use the `app_context` and recreate this:
   
   
   ```python
   @mock.patch('airflow.www.views.dagbag.get_dag')
   @mock.patch('airflow.www.views.BaseView.render_template')
   def test_extra_link_in_gantt_view(self, mock_render_template, 
get_dag_function):
   from tests.test_utils.mock_operators import Dummy2TestOperator
   dag = DAG('ex_dag', start_date=self.default_date)
   task = Dummy2TestOperator(task_id="some_dummy_task_2", dag=dag)
   get_dag_function.return_value = dag
   
   exec_date = dates.days_ago(2)
   start_date = datetime(2020, 4, 10, 2, 0, 0)
   end_date = exec_date + timedelta(seconds=30)
   
   with create_session() as session:
   for task in dag.tasks:
   ti = TaskInstance(task=task, execution_date=exec_date, 
state="success")
   ti.start_date = start_date
   ti.end_date = end_date
   session.add(ti)
   
   with self.app.app_context():
   mock_render_template.return_value = make_response("RESPONSE", 
200)
   url = 'gantt?dag_id={}&execution_date={}'.format(dag.dag_id, 
exec_date)
   self.client.get(url, follow_redirects=True)
   
   mock_render_template.assert_called_once_with(
   'airflow/gantt.html',
   base_date=mock.ANY, dag=mock.ANY,
   data={
   'taskNames': ['some_dummy_task_2'],
   'tasks': [
   {
   'task_id': 'some_dummy_task_2',
   'dag_id': 'ex_dag',
   'execution_date': '2020-04-19T00:00:00+00:00',
   'start_date': '2020-04-10T02:00:00+00:00', 
'end_date': '2020-04-19T00:00:30+00:00',
   'duration': None, 'state': 'success', 'try_number': 
1,
   'max_tries': 0, 'hostname': '', 'unixname': 'root',
   'job_id': None, 'pool': 'default_pool', 
'pool_slots': 1, 'queue': 'default',
   'priority_weight': 1,
   'operator': 'Dummy2TestOperator', 'queued_dttm': 
None,
   'pid': None, 'executor_config': {},
   'extraLinks': ['github', 'airflow']
   }
   ], 'height': 50
   },
   demo_mode=False,
   execution_date=mock.ANY, form=mock.ANY, root=mock.ANY, 
scheduler_job=mock.ANY
   )
   ```
   
   arghh we will need to find a way to test individual args such that order of 
elements in list or dict doesn't matter.
   
   
   **EDIT**: The following worked
   
   ```python
   @mock.patch('airflow.www.views.dagbag.get_dag')
   @mock.patch('airflow.www.views.BaseView.render_template')
   def test_extra_link_in_gantt_view(self, mock_render_template, 
get_dag_function):
   from tests.test_utils.mock_operators import Dummy2TestOperator
   dag = DAG('ex_dag', start_date=self.default_date)
   Dummy2TestOperator(task_id="some_dummy_task_2", dag=dag)
   
   get_dag_function.return_value = dag
   
   exec_date = dates.days_ago(2)
   start_date = datetime(2020, 4, 10, 2, 0, 0)
   end_date = exec_date + timedelta(seconds=30)
   
   with create_session() as session:
   for task in dag.tasks:
   ti = TaskInstance(task=task, execution_date=exec_date, 
state="success")
   ti.start_date = start_date
   ti.end_date = end_date
   session.add(ti)
   
   with self.app.app_context():
   mock_render_template.return_value = make_response("RESPONSE", 
200)
   url = 'gantt?dag_id={}&execution_date={}'.format(dag.dag_id, 
exec_date)
   self.client.get(url, follow_redirects=True, data=dict(
   username='test',
   password='test'
   ))
   
   self.assertCountEqual(
   
mock_render_template.call_args[1]['data']['tasks'][0]['extraLinks'],
   ['airflow', 'github']
   )
   ```



This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [airflow] kaxil edited a comment on issue #8308: Fix Extra Links in Gannt View

2020-04-21 Thread GitBox


kaxil edited a comment on issue #8308:
URL: https://github.com/apache/airflow/pull/8308#issuecomment-617461852


   > @ashb we can also mock jinja and check template params. POC: #8505
   
   Was able to use the `app_context` and recreate this:
   
   
   ```python
   @mock.patch('airflow.www.views.dagbag.get_dag')
   @mock.patch('airflow.www.views.BaseView.render_template')
   def test_extra_link_in_gantt_view(self, mock_render_template, 
get_dag_function):
   from tests.test_utils.mock_operators import Dummy2TestOperator
   dag = DAG('ex_dag', start_date=self.default_date)
   task = Dummy2TestOperator(task_id="some_dummy_task_2", dag=dag)
   get_dag_function.return_value = dag
   
   exec_date = dates.days_ago(2)
   start_date = datetime(2020, 4, 10, 2, 0, 0)
   end_date = exec_date + timedelta(seconds=30)
   
   with create_session() as session:
   for task in dag.tasks:
   ti = TaskInstance(task=task, execution_date=exec_date, 
state="success")
   ti.start_date = start_date
   ti.end_date = end_date
   session.add(ti)
   
   with self.app.app_context():
   mock_render_template.return_value = make_response("RESPONSE", 
200)
   url = 'gantt?dag_id={}&execution_date={}'.format(dag.dag_id, 
exec_date)
   self.client.get(url, follow_redirects=True)
   
   mock_render_template.assert_called_once_with(
   'airflow/gantt.html',
   base_date=mock.ANY, dag=mock.ANY,
   data={
   'taskNames': ['some_dummy_task_2'],
   'tasks': [
   {
   'task_id': 'some_dummy_task_2',
   'dag_id': 'ex_dag',
   'execution_date': '2020-04-19T00:00:00+00:00',
   'start_date': '2020-04-10T02:00:00+00:00', 
'end_date': '2020-04-19T00:00:30+00:00',
   'duration': None, 'state': 'success', 'try_number': 
1,
   'max_tries': 0, 'hostname': '', 'unixname': 'root',
   'job_id': None, 'pool': 'default_pool', 
'pool_slots': 1, 'queue': 'default',
   'priority_weight': 1,
   'operator': 'Dummy2TestOperator', 'queued_dttm': 
None,
   'pid': None, 'executor_config': {},
   'extraLinks': ['github', 'airflow']
   }
   ], 'height': 50
   },
   demo_mode=False,
   execution_date=mock.ANY, form=mock.ANY, root=mock.ANY, 
scheduler_job=mock.ANY
   )
   ```
   
   arghh we will need to find a way to test individual args such that order of 
elements in list or dict doesn't matter.
   
   
   **EDIT**: The following worked
   
   ```python
   @mock.patch('airflow.www.views.dagbag.get_dag')
   @mock.patch('airflow.www.views.BaseView.render_template')
   def test_extra_link_in_gantt_view(self, mock_render_template, 
get_dag_function):
   from tests.test_utils.mock_operators import Dummy2TestOperator
   dag = DAG('ex_dag', start_date=self.default_date)
   Dummy2TestOperator(task_id="some_dummy_task_2", dag=dag)
   
   get_dag_function.return_value = dag
   
   exec_date = dates.days_ago(2)
   start_date = datetime(2020, 4, 10, 2, 0, 0)
   end_date = exec_date + timedelta(seconds=30)
   
   with create_session() as session:
   for task in dag.tasks:
   ti = TaskInstance(task=task, execution_date=exec_date, 
state="success")
   ti.start_date = start_date
   ti.end_date = end_date
   session.add(ti)
   
   with self.app.app_context():
   mock_render_template.return_value = make_response("RESPONSE", 
200)
   url = 'gantt?dag_id={}&execution_date={}'.format(dag.dag_id, 
exec_date)
   self.client.get(url, follow_redirects=True, data=dict(
   username='test',
   password='test'
   ))
   
   self.assertCountEqual(
   
mock_render_template.call_args[1]['data']['tasks'][0]['extraLinks'],
   ['airflow', 'github']
   )
   ```



This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [airflow] kaxil edited a comment on issue #8308: Fix Extra Links in Gannt View

2020-04-21 Thread GitBox


kaxil edited a comment on issue #8308:
URL: https://github.com/apache/airflow/pull/8308#issuecomment-617461852







This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [airflow] kaxil edited a comment on issue #8308: Fix Extra Links in Gannt View

2020-04-21 Thread GitBox


kaxil edited a comment on issue #8308:
URL: https://github.com/apache/airflow/pull/8308#issuecomment-617463114


   Waiting to hear what Ash thinks.
   
   The thing I like about your approach @mik-laj is like you said separates 
testing **templates** and **flask views**. On the other hand, the things we 
were doing until now is more like system test but I am leaning towards what you 
suggested because we were indeed searching for strings in the webserver source 
code :)



This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [airflow] kaxil edited a comment on issue #8308: Fix Extra Links in Gannt View

2020-04-21 Thread GitBox


kaxil edited a comment on issue #8308:
URL: https://github.com/apache/airflow/pull/8308#issuecomment-617461852


   > @ashb we can also mock jinja and check template params. POC: #8505
   
   Was able to use the `app_context` and recreate this:
   
   
   ```python
   @mock.patch('airflow.www.views.dagbag.get_dag')
   @mock.patch('airflow.www.views.BaseView.render_template')
   def test_extra_link_in_gantt_view(self, mock_render_template, 
get_dag_function):
   from tests.test_utils.mock_operators import Dummy2TestOperator
   dag = DAG('ex_dag', start_date=self.default_date)
   task = Dummy2TestOperator(task_id="some_dummy_task_2", dag=dag)
   get_dag_function.return_value = dag
   
   exec_date = dates.days_ago(2)
   start_date = datetime(2020, 4, 10, 2, 0, 0)
   end_date = exec_date + timedelta(seconds=30)
   
   with create_session() as session:
   for task in dag.tasks:
   ti = TaskInstance(task=task, execution_date=exec_date, 
state="success")
   ti.start_date = start_date
   ti.end_date = end_date
   session.add(ti)
   
   with self.app.app_context():
   mock_render_template.return_value = make_response("RESPONSE", 
200)
   url = 'gantt?dag_id={}&execution_date={}'.format(dag.dag_id, 
exec_date)
   self.client.get(url, follow_redirects=True)
   
   mock_render_template.assert_called_once_with(
   'airflow/gantt.html',
   base_date=mock.ANY, dag=mock.ANY,
   data={
   'taskNames': ['some_dummy_task_2'],
   'tasks': [
   {
   'task_id': 'some_dummy_task_2',
   'dag_id': 'ex_dag',
   'execution_date': '2020-04-19T00:00:00+00:00',
   'start_date': '2020-04-10T02:00:00+00:00', 
'end_date': '2020-04-19T00:00:30+00:00',
   'duration': None, 'state': 'success', 'try_number': 
1,
   'max_tries': 0, 'hostname': '', 'unixname': 'root',
   'job_id': None, 'pool': 'default_pool', 
'pool_slots': 1, 'queue': 'default',
   'priority_weight': 1,
   'operator': 'Dummy2TestOperator', 'queued_dttm': 
None,
   'pid': None, 'executor_config': {},
   'extraLinks': ['github', 'airflow']
   }
   ], 'height': 50
   },
   demo_mode=False,
   execution_date=mock.ANY, form=mock.ANY, root=mock.ANY, 
scheduler_job=mock.ANY
   )
   ```
   



This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [airflow] kaxil edited a comment on issue #8308: Fix Extra Links in Gannt View

2020-04-14 Thread GitBox
kaxil edited a comment on issue #8308: Fix Extra Links in Gannt View
URL: https://github.com/apache/airflow/pull/8308#issuecomment-613717782
 
 
   > Should we add tests to avoid regression?
   
   Was just typing that  :D . We don't have any tests for Modal or at least I 
don't know, so any pointers would be helpful.
   
   
![image](https://user-images.githubusercontent.com/8811558/79281282-5727fd00-7eaa-11ea-8c4d-5e7bf1d65505.png)
   


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


With regards,
Apache Git Services