Exemple #1
0
    def test_execute(self, mock_hook):
        operator = StackdriverListNotificationChannelsOperator(task_id=TEST_TASK_ID, filter_=TEST_FILTER)
        mock_hook.return_value.list_notification_channels.return_value = [
            NotificationChannel(name="test-123")
        ]

        result = operator.execute(None)
        mock_hook.return_value.list_notification_channels.assert_called_once_with(
            project_id=None,
            filter_=TEST_FILTER,
            format_=None,
            order_by=None,
            page_size=None,
            retry=DEFAULT,
            timeout=DEFAULT,
            metadata=None,
        )
        assert [
            {
                'description': '',
                'display_name': '',
                'labels': {},
                'name': 'test-123',
                'type_': '',
                'user_labels': {},
                'verification_status': 0,
            }
        ] == result
Exemple #2
0
 def test_execute(self, mock_hook):
     operator = StackdriverListNotificationChannelsOperator(task_id=TEST_TASK_ID, filter_=TEST_FILTER)
     operator.execute(None)
     mock_hook.return_value.list_notification_channels.assert_called_once_with(
         project_id=None,
         filter_=TEST_FILTER,
         format_=None,
         order_by=None,
         page_size=None,
         retry=DEFAULT,
         timeout=DEFAULT,
         metadata=None,
     )
Exemple #3
0
    def test_execute(self, mock_hook):
        operator = StackdriverListNotificationChannelsOperator(
            task_id=TEST_TASK_ID, filter_=TEST_FILTER)
        mock_hook.return_value.list_notification_channels.return_value = [
            NotificationChannel(name="test-123")
        ]

        result = operator.execute(None)
        mock_hook.return_value.list_notification_channels.assert_called_once_with(
            project_id=None,
            filter_=TEST_FILTER,
            format_=None,
            order_by=None,
            page_size=None,
            retry=DEFAULT,
            timeout=DEFAULT,
            metadata=None,
        )
        # Depending on the version of google-apitools installed we might receive the response either with or
        # without mutation_records.
        assert result in [
            [{
                'description': '',
                'display_name': '',
                'labels': {},
                'name': 'test-123',
                'type_': '',
                'user_labels': {},
                'verification_status': 0,
            }],
            [{
                'description': '',
                'display_name': '',
                'labels': {},
                'mutation_records': [],
                'name': 'test-123',
                'type_': '',
                'user_labels': {},
                'verification_status': 0,
            }],
        ]
    )
    # [END howto_operator_gcp_stackdriver_upsert_notification_channel]

    # [START howto_operator_gcp_stackdriver_enable_notification_channel]
    enable_notification_channel = StackdriverEnableNotificationChannelsOperator(
        task_id='enable-notification-channel', filter_='type="slack"')
    # [END howto_operator_gcp_stackdriver_enable_notification_channel]

    # [START howto_operator_gcp_stackdriver_disable_notification_channel]
    disable_notification_channel = StackdriverDisableNotificationChannelsOperator(
        task_id='disable-notification-channel',
        filter_='displayName="channel1"')
    # [END howto_operator_gcp_stackdriver_disable_notification_channel]

    # [START howto_operator_gcp_stackdriver_list_notification_channel]
    list_notification_channel = StackdriverListNotificationChannelsOperator(
        task_id='list-notification-channel', filter_='type="slack"')
    # [END howto_operator_gcp_stackdriver_list_notification_channel]

    # [START howto_operator_gcp_stackdriver_upsert_alert_policy]
    create_alert_policy = StackdriverUpsertAlertOperator(
        task_id='create-alert-policies',
        alerts=json.dumps(
            {"policies": [TEST_ALERT_POLICY_1, TEST_ALERT_POLICY_2]}),
    )
    # [END howto_operator_gcp_stackdriver_upsert_alert_policy]

    # [START howto_operator_gcp_stackdriver_enable_alert_policy]
    enable_alert_policy = StackdriverEnableAlertPoliciesOperator(
        task_id='enable-alert-policies',
        filter_='(displayName="test alert 1" OR displayName="test alert 2")',
    )