def test_instance_query_dml(self, mock_hook): mock_hook.return_value.execute_dml.return_value = None op = CloudSpannerInstanceDatabaseQueryOperator(project_id=PROJECT_ID, instance_id=INSTANCE_ID, database_id=DB_ID, query=INSERT_QUERY, task_id="id") op.execute(None) mock_hook.assert_called_once_with(gcp_conn_id="google_cloud_default") mock_hook.return_value.execute_dml.assert_called_once_with( PROJECT_ID, INSTANCE_ID, DB_ID, [INSERT_QUERY])
def test_instance_query_dml_list(self, mock_hook): mock_hook.return_value.execute_dml.return_value = None op = CloudSpannerInstanceDatabaseQueryOperator( project_id=PROJECT_ID, instance_id=INSTANCE_ID, database_id=DB_ID, query=[INSERT_QUERY, INSERT_QUERY_2], task_id="id" ) op.execute(None) mock_hook.assert_called_once_with(gcp_conn_id="google_cloud_default") mock_hook.return_value.execute_dml.assert_called_once_with( PROJECT_ID, INSTANCE_ID, DB_ID, [INSERT_QUERY, INSERT_QUERY_2] )
def test_instance_query_missing_project_id(self, mock_hook): mock_hook.return_value.execute_sql.return_value = None op = CloudSpannerInstanceDatabaseQueryOperator(instance_id=INSTANCE_ID, database_id=DB_ID, query=INSERT_QUERY, task_id="id") result = op.execute(None) mock_hook.assert_called_once_with(gcp_conn_id="google_cloud_default") mock_hook.return_value.execute_dml.assert_called_once_with( project_id=None, instance_id=INSTANCE_ID, database_id=DB_ID, queries=[INSERT_QUERY]) self.assertIsNone(result)
def test_instance_query_missing_project_id(self, mock_hook): mock_hook.return_value.execute_sql.return_value = None op = CloudSpannerInstanceDatabaseQueryOperator( instance_id=INSTANCE_ID, database_id=DB_ID, query=INSERT_QUERY, task_id="id" ) result = op.execute(None) mock_hook.assert_called_once_with(gcp_conn_id="google_cloud_default") mock_hook.return_value.execute_dml.assert_called_once_with( project_id=None, instance_id=INSTANCE_ID, database_id=DB_ID, queries=[INSERT_QUERY] ) self.assertIsNone(result)
def test_instance_query(self, mock_hook): mock_hook.return_value.execute_sql.return_value = None op = CloudSpannerInstanceDatabaseQueryOperator( project_id=PROJECT_ID, instance_id=INSTANCE_ID, database_id=DB_ID, query=INSERT_QUERY, task_id="id" ) result = op.execute(None) # pylint: disable=assignment-from-no-return mock_hook.assert_called_once_with(gcp_conn_id="google_cloud_default") mock_hook.return_value.execute_dml.assert_called_once_with( project_id=PROJECT_ID, instance_id=INSTANCE_ID, database_id=DB_ID, queries=[INSERT_QUERY] ) self.assertIsNone(result)