Skip to content

Commit

Permalink
Merge pull request apache#1221 from jgao54/mock-request-in-test
Browse files Browse the repository at this point in the history
Fix HttpOpSensorTest to use fake request session
  • Loading branch information
bolkedebruin committed Mar 28, 2016
2 parents 0e325d9 + f6996c2 commit a136b2f
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions tests/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1123,6 +1123,18 @@ def postgres_operator_test(self):
end_date=DEFAULT_DATE,
force=True)

class FakeSession(object):
def __init__(self):
from requests import Response
self.response = Response()
self.response.status_code = 200
self.response._content = 'airbnb/airflow'.encode('ascii', 'ignore')

def send(self, request, **kwargs):
return self.response

def prepare_request(self, request):
return self.response

class HttpOpSensorTest(unittest.TestCase):
def setUp(self):
Expand All @@ -1131,6 +1143,7 @@ def setUp(self):
dag = DAG(TEST_DAG_ID, default_args=args)
self.dag = dag

@mock.patch('requests.Session', FakeSession)
def test_get(self):
t = operators.SimpleHttpOperator(
task_id='get_op',
Expand All @@ -1141,6 +1154,7 @@ def test_get(self):
dag=self.dag)
t.run(start_date=DEFAULT_DATE, end_date=DEFAULT_DATE, force=True)

@mock.patch('requests.Session', FakeSession)
def test_get_response_check(self):
t = operators.SimpleHttpOperator(
task_id='get_op',
Expand All @@ -1152,6 +1166,7 @@ def test_get_response_check(self):
dag=self.dag)
t.run(start_date=DEFAULT_DATE, end_date=DEFAULT_DATE, force=True)

@mock.patch('requests.Session', FakeSession)
def test_sensor(self):
sensor = operators.HttpSensor(
task_id='http_sensor_check',
Expand Down

0 comments on commit a136b2f

Please sign in to comment.