示例#1
0
    def setUpTestData(cls):
        webhooks = (
            Webhook(
                name="api-test-1",
                type_create=True,
                payload_url="http://api-test-1.com/test1",
                http_method="POST",
                http_content_type="application/json",
                ssl_verification=True,
            ),
            Webhook(
                name="api-test-2",
                type_update=True,
                payload_url="http://api-test-2.com/test2",
                http_method="POST",
                http_content_type="application/json",
                ssl_verification=True,
            ),
            Webhook(
                name="api-test-3",
                type_delete=True,
                payload_url="http://api-test-3.com/test3",
                http_method="POST",
                http_content_type="application/json",
                ssl_verification=True,
            ),
        )

        obj_type = ContentType.objects.get_for_model(DeviceType)

        for webhook in webhooks:
            webhook.save()
            webhook.content_types.set([obj_type])
示例#2
0
 def setUpTestData(cls):
     webhooks = (
         Webhook(
             name="webhook-1",
             enabled=True,
             type_create=True,
             payload_url="http://test-url.com/test-1",
             http_content_type=HTTP_CONTENT_TYPE_JSON,
         ),
         Webhook(
             name="webhook-2",
             enabled=True,
             type_update=True,
             payload_url="http://test-url.com/test-2",
             http_content_type=HTTP_CONTENT_TYPE_JSON,
         ),
         Webhook(
             name="webhook-3",
             enabled=True,
             type_delete=True,
             payload_url="http://test-url.com/test-3",
             http_content_type=HTTP_CONTENT_TYPE_JSON,
         ),
     )
     obj_type = ContentType.objects.get_for_model(Site)
     for webhook in webhooks:
         webhook.save()
         webhook.content_types.set([obj_type])
示例#3
0
    def setUpTestData(cls):
        webhooks = (
            Webhook(
                name="webhook-1",
                enabled=True,
                type_create=True,
                payload_url="http://test-url.com/test-1",
                http_content_type=HTTP_CONTENT_TYPE_JSON,
            ),
            Webhook(
                name="webhook-2",
                enabled=True,
                type_update=True,
                payload_url="http://test-url.com/test-2",
                http_content_type=HTTP_CONTENT_TYPE_JSON,
            ),
            Webhook(
                name="webhook-3",
                enabled=True,
                type_delete=True,
                payload_url="http://test-url.com/test-3",
                http_content_type=HTTP_CONTENT_TYPE_JSON,
            ),
        )

        obj_type = ContentType.objects.get_for_model(ConsolePort)

        for webhook in webhooks:
            webhook.save()
            webhook.content_types.set([obj_type])

        cls.form_data = {
            "name": "webhook-4",
            "content_types": [obj_type.pk],
            "enabled": True,
            "type_create": True,
            "payload_url": "http://test-url.com/test-4",
            "http_method": "POST",
            "http_content_type": "application/json",
        }
示例#4
0
    def validate(self, data):
        validated_data = super().validate(data)

        conflicts = Webhook.check_for_conflicts(
            instance=self.instance,
            content_types=data.get("content_types"),
            payload_url=data.get("payload_url"),
            type_create=data.get("type_create"),
            type_update=data.get("type_update"),
            type_delete=data.get("type_delete"),
        )

        if conflicts:
            raise serializers.ValidationError(conflicts)

        return validated_data
示例#5
0
    def setUp(self):
        self.user = User.objects.create_user(username="******",
                                             email="*****@*****.**",
                                             password="******")

        site_ct = ContentType.objects.get_for_model(Site)
        DUMMY_URL = "http://localhost/"
        DUMMY_SECRET = "LOOKATMEIMASECRETSTRING"

        webhooks = Webhook.objects.bulk_create((Webhook(
            name="Site Create Webhook",
            type_create=True,
            payload_url=DUMMY_URL,
            secret=DUMMY_SECRET,
        ), ))
        for webhook in webhooks:
            webhook.content_types.set([site_ct])

        self.queue = django_rq.get_queue("webhooks")
        self.queue.empty()  # Begin each test with an empty queue
示例#6
0
 def test_webhook_render_body_with_utf8(self):
     self.assertEqual(Webhook().render_body({"utf8": "I am UTF-8! 😀"}),
                      '{"utf8": "I am UTF-8! 😀"}')