feluelle commented on a change in pull request #5101: [AIRFLOW-4319] Add tests
for Bigquery related Operators
URL: https://github.com/apache/airflow/pull/5101#discussion_r275464796
##########
File path: tests/contrib/operators/test_bigquery_operator.py
##########
@@ -250,3 +255,125 @@ def test_bigquery_operator_defaults(self, mock_hook):
ti = TaskInstance(task=operator, execution_date=DEFAULT_DATE)
ti.render_templates()
self.assertTrue(isinstance(ti.task.sql, six.string_types))
+
+
+class BigQueryGetDataOperatorTest(unittest.TestCase):
+
+ @mock.patch('airflow.contrib.operators.bigquery_get_data.BigQueryHook')
+ def test_execute(self, mock_hook):
+
+ max_results = '100'
+ selected_fields = 'DATE'
+ operator = BigQueryGetDataOperator(task_id=TASK_ID,
+ dataset_id=TEST_DATASET,
+ table_id=TEST_TABLE_ID,
+ max_results=max_results,
+ selected_fields=selected_fields,
+ )
+ operator.execute(None)
+ mock_hook.return_value \
+ .get_conn() \
Review comment:
> Will there be any other difference between those 2 (() & return_value )
I don't think so.
I first run into it when I had to test for more than one function call via
[assert_has_calls](https://docs.python.org/3/library/unittest.mock.html#unittest.mock.Mock.assert_has_calls)
> Or when you would you want to use () instead of return_value ?
That's a good question.
I think primarily it is to provide a way to test functionality that does not
yet exist. Like in the mock examples
https://docs.python.org/3/library/unittest.mock.html
But you could also test if an object behaves like a singleton where you only
want it to be instantiated once. You can then just call the mock in your test
again and assert for what you expect to be happen.
----------------------------------------------------------------
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:
[email protected]
With regards,
Apache Git Services