Esempio n. 1
0
def test_delete_webhook(db):
    instance = Webhook.create('http://www.foo.bar')
    assert instance.id > 0
    instance.delete()
    assert Webhook.get(instance.id) is None
    assert instance.id not in Webhook.get_all_ids()
    assert instance.id not in Webhook.get_ids_by_type(instance.hook_type)
Esempio n. 2
0
def test_update_webhook_url(db):
    instance = Webhook.create('http://www.foo.bar')
    assert instance.id > 0
    assert instance.url == 'http://www.foo.bar'
    assert instance.hook_type == Webhook.TYPE_NORMAL

    instance.update_url('http://www.foo.me')
    assert instance.url == 'http://www.foo.me'
    assert Webhook.get(instance.id).url == instance.url
Esempio n. 3
0
    def get(self, application_name):
        """List the subscriptions of an application specified with
        the ``application_name``.

        The response looks like::

            {
              "status": "SUCCESS",
              "message": "",
              "data": {
                "webhook_list": [
                  {
                    "webhook_id": 1,
                    "webhook_url": "http://www.example.com",
                    "webhook_type": 0,
                    "event_list": [
                        "CREATE_CONFIG_CLUSTER",
                        "DELETE_CONFIG_CLUSTER",
                        ...
                    ]
                  },
                  ...
                ]
              }
            }

        :param application_name: The name of application.
        :status 200: The request is successful.
        """
        application = check_application(application_name)
        subscriptions = Webhook.search_subscriptions(
            application_id=application.id)
        groups = itertools.groupby(subscriptions, key=attrgetter('webhook_id'))
        webhook_list = []
        for webhook_id, group in groups:
            webhook = Webhook.get(webhook_id)
            webhook_list.append({
                'webhook_id':
                webhook.id,
                'webhook_url':
                webhook.url,
                'webhook_type':
                webhook.hook_type,
                'event_list': [action_types[x.action_type] for x in group]
            })
        return api_response(data={'webhook_list': webhook_list})
Esempio n. 4
0
def test_delete_webhook(
        db, client, test_application, test_application_token,
        admin_token, present_data, input_data):
    webhooks = add_test_webhook_sub(present_data, test_application.id)
    webhook = list(webhooks)[0][0]
    if webhook.is_normal:
        token = test_application_token
    else:
        token = admin_token
    headers = {'Authorization': token}
    query_string = {'application_name': test_application.application_name}
    r = client.delete('/api/webhook/%s' % webhook.id, headers=headers,
                      query_string=query_string)
    assert_response_ok(r)
    assert r.json['data'] is None

    assert Webhook.get(webhook.id) is None
    assert len(Webhook.search_subscriptions(webhook_id=webhook.id)) == 0
Esempio n. 5
0
 def _get_webhook_or_404(self, webhook_id):
     instance = Webhook.get(webhook_id)
     if not instance:
         abort(404, 'Webhook not registered.')
     return instance