django-webhook-subscriber 0.4.0__py3-none-any.whl → 2.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- django_webhook_subscriber/__init__.py +7 -1
- django_webhook_subscriber/admin.py +831 -182
- django_webhook_subscriber/apps.py +3 -20
- django_webhook_subscriber/conf.py +11 -24
- django_webhook_subscriber/delivery.py +414 -159
- django_webhook_subscriber/http.py +51 -0
- django_webhook_subscriber/management/commands/webhook.py +169 -0
- django_webhook_subscriber/management/commands/webhook_cache.py +173 -0
- django_webhook_subscriber/management/commands/webhook_logs.py +226 -0
- django_webhook_subscriber/management/commands/webhook_performance_test.py +469 -0
- django_webhook_subscriber/management/commands/webhook_send.py +96 -0
- django_webhook_subscriber/management/commands/webhook_status.py +139 -0
- django_webhook_subscriber/managers.py +36 -14
- django_webhook_subscriber/migrations/0002_remove_webhookregistry_content_type_and_more.py +192 -0
- django_webhook_subscriber/models.py +291 -114
- django_webhook_subscriber/serializers.py +16 -50
- django_webhook_subscriber/tasks.py +434 -56
- django_webhook_subscriber/tests/factories.py +40 -0
- django_webhook_subscriber/tests/settings.py +27 -8
- django_webhook_subscriber/tests/test_delivery.py +453 -190
- django_webhook_subscriber/tests/test_http.py +32 -0
- django_webhook_subscriber/tests/test_managers.py +26 -37
- django_webhook_subscriber/tests/test_models.py +341 -251
- django_webhook_subscriber/tests/test_serializers.py +22 -56
- django_webhook_subscriber/tests/test_tasks.py +477 -189
- django_webhook_subscriber/tests/test_utils.py +98 -94
- django_webhook_subscriber/utils.py +87 -69
- django_webhook_subscriber/validators.py +53 -0
- django_webhook_subscriber-2.0.0.dist-info/METADATA +774 -0
- django_webhook_subscriber-2.0.0.dist-info/RECORD +38 -0
- django_webhook_subscriber/management/commands/check_webhook_tasks.py +0 -113
- django_webhook_subscriber/management/commands/clean_webhook_logs.py +0 -65
- django_webhook_subscriber/management/commands/test_webhook.py +0 -96
- django_webhook_subscriber/signals.py +0 -152
- django_webhook_subscriber/testing.py +0 -14
- django_webhook_subscriber/tests/test_signals.py +0 -268
- django_webhook_subscriber-0.4.0.dist-info/METADATA +0 -448
- django_webhook_subscriber-0.4.0.dist-info/RECORD +0 -33
- {django_webhook_subscriber-0.4.0.dist-info → django_webhook_subscriber-2.0.0.dist-info}/WHEEL +0 -0
- {django_webhook_subscriber-0.4.0.dist-info → django_webhook_subscriber-2.0.0.dist-info}/licenses/LICENSE +0 -0
- {django_webhook_subscriber-0.4.0.dist-info → django_webhook_subscriber-2.0.0.dist-info}/top_level.txt +0 -0
|
@@ -1,75 +1,42 @@
|
|
|
1
1
|
from django.test import TestCase
|
|
2
|
-
from django.contrib.contenttypes.models import ContentType
|
|
3
|
-
|
|
4
2
|
from rest_framework import serializers
|
|
5
3
|
|
|
6
|
-
from django_webhook_subscriber
|
|
7
|
-
from django_webhook_subscriber.
|
|
4
|
+
from django_webhook_subscriber import models
|
|
5
|
+
from django_webhook_subscriber.serializers import serialize_webhook_instance
|
|
6
|
+
|
|
7
|
+
from .factories import WebhookDeliveryLogFactory
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
class SerializersTests(TestCase):
|
|
11
11
|
def setUp(self):
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
)
|
|
15
|
-
# creating a user instance
|
|
16
|
-
self.webhook = WebhookRegistry.objects.create(
|
|
17
|
-
name='Test Webhook',
|
|
18
|
-
content_type=self.webhook_content_type,
|
|
19
|
-
endpoint='https://example.com/webhook',
|
|
20
|
-
)
|
|
12
|
+
# creating instance to be serialized
|
|
13
|
+
self.instance = WebhookDeliveryLogFactory()
|
|
21
14
|
|
|
22
15
|
def test_default_serialization(self):
|
|
23
16
|
# serializing the user instance
|
|
24
|
-
data =
|
|
17
|
+
data = serialize_webhook_instance(self.instance)
|
|
25
18
|
|
|
26
|
-
# Check that
|
|
27
|
-
self.assertEqual(data[
|
|
28
|
-
self.assertEqual(
|
|
29
|
-
|
|
30
|
-
)
|
|
31
|
-
self.assertEqual(data['event_signal'], 'create')
|
|
32
|
-
self.assertIn('fields', data)
|
|
33
|
-
|
|
34
|
-
# Check that all fields are serialized
|
|
35
|
-
self.assertEqual(data['fields']['name'], 'Test Webhook')
|
|
36
|
-
self.assertEqual(
|
|
37
|
-
data['fields']['endpoint'],
|
|
38
|
-
'https://example.com/webhook',
|
|
39
|
-
)
|
|
40
|
-
self.assertEqual(
|
|
41
|
-
data['fields']['content_type'],
|
|
42
|
-
self.webhook_content_type.pk,
|
|
43
|
-
)
|
|
19
|
+
# Check that fields are correct
|
|
20
|
+
self.assertEqual(data["id"], self.instance.id)
|
|
21
|
+
self.assertEqual(data["payload"], self.instance.payload)
|
|
22
|
+
self.assertEqual(data["subscription"], self.instance.subscription.id)
|
|
44
23
|
|
|
45
24
|
def test_serialization_with_custom_serializer(self):
|
|
46
25
|
class CustomSerializer(serializers.ModelSerializer):
|
|
47
26
|
class Meta:
|
|
48
|
-
model =
|
|
49
|
-
fields = [
|
|
27
|
+
model = models.WebhookDeliveryLog
|
|
28
|
+
fields = ["id", "payload"]
|
|
50
29
|
|
|
51
30
|
# Test with DRF serializer
|
|
52
|
-
data =
|
|
53
|
-
self.
|
|
54
|
-
event_signal='delete',
|
|
31
|
+
data = serialize_webhook_instance(
|
|
32
|
+
self.instance,
|
|
55
33
|
field_serializer=CustomSerializer,
|
|
56
34
|
)
|
|
57
35
|
|
|
58
|
-
# Check the
|
|
59
|
-
self.assertEqual(data[
|
|
60
|
-
self.assertEqual(
|
|
61
|
-
|
|
62
|
-
)
|
|
63
|
-
self.assertEqual(data['event_signal'], 'delete')
|
|
64
|
-
self.assertIn('fields', data)
|
|
65
|
-
|
|
66
|
-
# Check the fields
|
|
67
|
-
self.assertEqual(data['fields']['name'], 'Test Webhook')
|
|
68
|
-
self.assertEqual(
|
|
69
|
-
data['fields']['endpoint'],
|
|
70
|
-
'https://example.com/webhook',
|
|
71
|
-
)
|
|
72
|
-
self.assertNotIn('content_type', data['fields'])
|
|
36
|
+
# Check the fields are correct
|
|
37
|
+
self.assertEqual(data["id"], self.instance.id)
|
|
38
|
+
self.assertEqual(data["payload"], self.instance.payload)
|
|
39
|
+
self.assertNotIn("subscription", data)
|
|
73
40
|
|
|
74
41
|
def test_serialization_with_invalid_serializer(self):
|
|
75
42
|
class InvalidSerializer:
|
|
@@ -77,11 +44,10 @@ class SerializersTests(TestCase):
|
|
|
77
44
|
|
|
78
45
|
# Test with invalid serializer
|
|
79
46
|
msg = (
|
|
80
|
-
|
|
47
|
+
"field_serializer must be a subclass of rest_framework.Serializer"
|
|
81
48
|
)
|
|
82
49
|
with self.assertRaisesMessage(ValueError, msg):
|
|
83
|
-
|
|
84
|
-
self.
|
|
85
|
-
event_signal='create',
|
|
50
|
+
serialize_webhook_instance(
|
|
51
|
+
self.instance,
|
|
86
52
|
field_serializer=InvalidSerializer,
|
|
87
53
|
)
|