63
63
from airflow .utils import timezone
64
64
from airflow .utils .timezone import datetime
65
65
from airflow .utils .state import State
66
- from airflow .utils .dates import infer_time_unit , round_time , scale_time_units
66
+ from airflow .utils .dates import days_ago , infer_time_unit , round_time , scale_time_units
67
67
from lxml import html
68
68
from airflow .exceptions import AirflowException
69
69
from airflow .configuration import AirflowConfigException , run_command
81
81
DEFAULT_DATE_ISO = DEFAULT_DATE .isoformat ()
82
82
DEFAULT_DATE_DS = DEFAULT_DATE_ISO [:10 ]
83
83
TEST_DAG_ID = 'unit_tests'
84
+ EXAMPLE_DAG_DEFAULT_DATE = days_ago (2 )
84
85
85
86
try :
86
87
import cPickle as pickle
@@ -1651,21 +1652,21 @@ def setUp(self):
1651
1652
1652
1653
self .dagrun_python = self .dag_python .create_dagrun (
1653
1654
run_id = "test_{}" .format (models .DagRun .id_for_date (timezone .utcnow ())),
1654
- execution_date = DEFAULT_DATE ,
1655
+ execution_date = EXAMPLE_DAG_DEFAULT_DATE ,
1655
1656
start_date = timezone .utcnow (),
1656
1657
state = State .RUNNING
1657
1658
)
1658
1659
1659
1660
self .sub_dag .create_dagrun (
1660
1661
run_id = "test_{}" .format (models .DagRun .id_for_date (timezone .utcnow ())),
1661
- execution_date = DEFAULT_DATE ,
1662
+ execution_date = EXAMPLE_DAG_DEFAULT_DATE ,
1662
1663
start_date = timezone .utcnow (),
1663
1664
state = State .RUNNING
1664
1665
)
1665
1666
1666
1667
self .example_xcom .create_dagrun (
1667
1668
run_id = "test_{}" .format (models .DagRun .id_for_date (timezone .utcnow ())),
1668
- execution_date = DEFAULT_DATE ,
1669
+ execution_date = EXAMPLE_DAG_DEFAULT_DATE ,
1669
1670
start_date = timezone .utcnow (),
1670
1671
state = State .RUNNING
1671
1672
)
@@ -1758,7 +1759,7 @@ def test_dag_views(self):
1758
1759
response = self .app .get (
1759
1760
'/admin/airflow/task?'
1760
1761
'task_id=runme_0&dag_id=example_bash_operator&'
1761
- 'execution_date={}' .format (DEFAULT_DATE_DS ))
1762
+ 'execution_date={}' .format (EXAMPLE_DAG_DEFAULT_DATE ))
1762
1763
self .assertIn ("Attributes" , response .data .decode ('utf-8' ))
1763
1764
response = self .app .get (
1764
1765
'/admin/airflow/dag_stats' )
@@ -1770,22 +1771,21 @@ def test_dag_views(self):
1770
1771
"/admin/airflow/success?task_id=print_the_context&"
1771
1772
"dag_id=example_python_operator&upstream=false&downstream=false&"
1772
1773
"future=false&past=false&execution_date={}&"
1773
- "origin=/admin" .format (DEFAULT_DATE_DS ))
1774
+ "origin=/admin" .format (EXAMPLE_DAG_DEFAULT_DATE ))
1774
1775
response = self .app .get (url )
1775
1776
self .assertIn ("Wait a minute" , response .data .decode ('utf-8' ))
1776
- response = self .app .get (url + "&confirmed=true" )
1777
1777
response = self .app .get (
1778
1778
'/admin/airflow/clear?task_id=print_the_context&'
1779
1779
'dag_id=example_python_operator&future=true&past=false&'
1780
1780
'upstream=true&downstream=false&'
1781
1781
'execution_date={}&'
1782
- 'origin=/admin' .format (DEFAULT_DATE_DS ))
1782
+ 'origin=/admin' .format (EXAMPLE_DAG_DEFAULT_DATE ))
1783
1783
self .assertIn ("Wait a minute" , response .data .decode ('utf-8' ))
1784
1784
url = (
1785
1785
"/admin/airflow/success?task_id=section-1&"
1786
1786
"dag_id=example_subdag_operator&upstream=true&downstream=true&"
1787
1787
"future=false&past=false&execution_date={}&"
1788
- "origin=/admin" .format (DEFAULT_DATE_DS ))
1788
+ "origin=/admin" .format (EXAMPLE_DAG_DEFAULT_DATE ))
1789
1789
response = self .app .get (url )
1790
1790
self .assertIn ("Wait a minute" , response .data .decode ('utf-8' ))
1791
1791
self .assertIn ("section-1-task-1" , response .data .decode ('utf-8' ))
@@ -1799,7 +1799,7 @@ def test_dag_views(self):
1799
1799
"dag_id=example_python_operator&future=false&past=false&"
1800
1800
"upstream=false&downstream=true&"
1801
1801
"execution_date={}&"
1802
- "origin=/admin" .format (DEFAULT_DATE_DS ))
1802
+ "origin=/admin" .format (EXAMPLE_DAG_DEFAULT_DATE ))
1803
1803
response = self .app .get (url )
1804
1804
self .assertIn ("Wait a minute" , response .data .decode ('utf-8' ))
1805
1805
response = self .app .get (url + "&confirmed=true" )
@@ -1808,7 +1808,7 @@ def test_dag_views(self):
1808
1808
"dag_id=example_subdag_operator.section-1&future=false&past=false&"
1809
1809
"upstream=false&downstream=true&recursive=true&"
1810
1810
"execution_date={}&"
1811
- "origin=/admin" .format (DEFAULT_DATE_DS ))
1811
+ "origin=/admin" .format (EXAMPLE_DAG_DEFAULT_DATE ))
1812
1812
response = self .app .get (url )
1813
1813
self .assertIn ("Wait a minute" , response .data .decode ('utf-8' ))
1814
1814
self .assertIn ("example_subdag_operator.end" ,
@@ -1835,7 +1835,7 @@ def test_dag_views(self):
1835
1835
"/admin/airflow/run?task_id=runme_0&"
1836
1836
"dag_id=example_bash_operator&ignore_all_deps=false&ignore_ti_state=true&"
1837
1837
"ignore_task_deps=true&execution_date={}&"
1838
- "origin=/admin" .format (DEFAULT_DATE_DS ))
1838
+ "origin=/admin" .format (EXAMPLE_DAG_DEFAULT_DATE ))
1839
1839
response = self .app .get (url )
1840
1840
response = self .app .get (
1841
1841
"/admin/airflow/refresh?dag_id=example_bash_operator" )
@@ -1870,13 +1870,28 @@ def test_fetch_task_instance(self):
1870
1870
url = (
1871
1871
"/admin/airflow/object/task_instances?"
1872
1872
"dag_id=example_python_operator&"
1873
- "execution_date={}" .format (DEFAULT_DATE_DS ))
1873
+ "execution_date={}" .format (EXAMPLE_DAG_DEFAULT_DATE ))
1874
1874
response = self .app .get (url )
1875
1875
self .assertIn ("print_the_context" , response .data .decode ('utf-8' ))
1876
1876
1877
+ def test_dag_view_task_with_python_operator_using_partial (self ):
1878
+ response = self .app .get (
1879
+ '/admin/airflow/task?'
1880
+ 'task_id=test_dagrun_functool_partial&dag_id=test_task_view_type_check&'
1881
+ 'execution_date={}' .format (EXAMPLE_DAG_DEFAULT_DATE ))
1882
+ self .assertIn ("A function with two args" , response .data .decode ('utf-8' ))
1883
+
1884
+ def test_dag_view_task_with_python_operator_using_instance (self ):
1885
+ response = self .app .get (
1886
+ '/admin/airflow/task?'
1887
+ 'task_id=test_dagrun_instance&dag_id=test_task_view_type_check&'
1888
+ 'execution_date={}' .format (EXAMPLE_DAG_DEFAULT_DATE ))
1889
+ self .assertIn ("A __call__ method" , response .data .decode ('utf-8' ))
1890
+
1877
1891
def tearDown (self ):
1878
1892
configuration .conf .set ("webserver" , "expose_config" , "False" )
1879
- self .dag_bash .clear (start_date = DEFAULT_DATE , end_date = timezone .utcnow ())
1893
+ self .dag_bash .clear (start_date = EXAMPLE_DAG_DEFAULT_DATE ,
1894
+ end_date = timezone .utcnow ())
1880
1895
session = Session ()
1881
1896
session .query (models .DagRun ).delete ()
1882
1897
session .query (models .TaskInstance ).delete ()
0 commit comments