def test_execute_no_subscription(self, mock_hook): operator = PubSubSubscriptionCreateOperator(task_id=TASK_ID, topic_project=TEST_PROJECT, topic=TEST_TOPIC) operator.execute(None) mock_hook.return_value.create_subscription.assert_called_once_with( TEST_PROJECT, TEST_TOPIC, None, None, 10, False)
def test_execute_no_subscription(self, mock_hook): operator = PubSubSubscriptionCreateOperator( task_id=TASK_ID, topic_project=TEST_PROJECT, topic=TEST_TOPIC) mock_hook.return_value.create_subscription.return_value = ( TEST_SUBSCRIPTION) response = operator.execute(None) mock_hook.return_value.create_subscription.assert_called_once_with( TEST_PROJECT, TEST_TOPIC, None, None, 10, False) self.assertEqual(response, TEST_SUBSCRIPTION)
def test_execute_different_project_ids(self, mock_hook): another_project = 'another-project' operator = PubSubSubscriptionCreateOperator( task_id=TASK_ID, topic_project=TEST_PROJECT, topic=TEST_TOPIC, subscription=TEST_SUBSCRIPTION, subscription_project=another_project) operator.execute(None) mock_hook.return_value.create_subscription.assert_called_once_with( TEST_PROJECT, TEST_TOPIC, TEST_SUBSCRIPTION, another_project, 10, False)
def test_execute(self, mock_hook): operator = PubSubSubscriptionCreateOperator( task_id=TASK_ID, topic_project=TEST_PROJECT, topic=TEST_TOPIC, subscription=TEST_SUBSCRIPTION) mock_hook.return_value.create_subscription.return_value = ( TEST_SUBSCRIPTION) response = operator.execute(None) mock_hook.return_value.create_subscription.assert_called_once_with( TEST_PROJECT, TEST_TOPIC, TEST_SUBSCRIPTION, None, 10, False) self.assertEqual(response, TEST_SUBSCRIPTION)
def test_execute_different_project_ids(self, mock_hook): another_project = 'another-project' operator = PubSubSubscriptionCreateOperator( task_id=TASK_ID, topic_project=TEST_PROJECT, topic=TEST_TOPIC, subscription=TEST_SUBSCRIPTION, subscription_project=another_project) mock_hook.return_value.create_subscription.return_value = ( TEST_SUBSCRIPTION) response = operator.execute(None) mock_hook.return_value.create_subscription.assert_called_once_with( TEST_PROJECT, TEST_TOPIC, TEST_SUBSCRIPTION, another_project, 10, False) self.assertEqual(response, TEST_SUBSCRIPTION)
'email_on_failure': False, 'email_on_retry': False, 'project': project, 'topic': topic, 'subscription': subscription, } echo_template = ''' {% for m in task_instance.xcom_pull(task_ids='pull-messages') %} echo "AckID: {{ m.get('ackId') }}, Base64-Encoded: {{ m.get('message') }}" {% endfor %} ''' with DAG('pubsub-end-to-end', default_args=default_args, schedule_interval=datetime.timedelta(days=1)) as dag: t1 = PubSubTopicCreateOperator(task_id='create-topic') t2 = PubSubSubscriptionCreateOperator( task_id='create-subscription', topic_project=project, subscription=subscription) t3 = PubSubPublishOperator( task_id='publish-messages', messages=messages) t4 = PubSubPullSensor(task_id='pull-messages', ack_messages=True) t5 = BashOperator(task_id='echo-pulled-messages', bash_command=echo_template) t6 = PubSubSubscriptionDeleteOperator(task_id='delete-subscription') t7 = PubSubTopicDeleteOperator(task_id='delete-topic') t1 >> t2 >> t3 t2 >> t4 >> t5 >> t6 >> t7