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
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import requests
|
|
2
|
+
from requests.adapters import HTTPAdapter
|
|
3
|
+
from django.test import TestCase
|
|
4
|
+
|
|
5
|
+
from django_webhook_subscriber.http import webhook_session
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class CreateWebhookSessionFunctionTests(TestCase):
|
|
9
|
+
def test_webhook_session_context_manager(self):
|
|
10
|
+
with webhook_session() as session:
|
|
11
|
+
# Asserting session is a requests.Session instance
|
|
12
|
+
self.assertIsInstance(session, requests.Session)
|
|
13
|
+
|
|
14
|
+
# Asserting pool_connections and pool_maxsize
|
|
15
|
+
adapter = session.get_adapter("http://")
|
|
16
|
+
self.assertEqual(adapter._pool_connections, 2)
|
|
17
|
+
self.assertEqual(adapter._pool_maxsize, 5)
|
|
18
|
+
|
|
19
|
+
# Asserting max_retries is 0
|
|
20
|
+
self.assertEqual(adapter.max_retries.total, 0)
|
|
21
|
+
|
|
22
|
+
# Asserting default headers are set
|
|
23
|
+
self.assertIn("User-Agent", session.headers)
|
|
24
|
+
self.assertIn("Content-Type", session.headers)
|
|
25
|
+
|
|
26
|
+
# Asserting adapter is mounted
|
|
27
|
+
adapter = session.get_adapter("http://")
|
|
28
|
+
self.assertIsNotNone(adapter)
|
|
29
|
+
self.assertIsInstance(adapter, HTTPAdapter)
|
|
30
|
+
adapter = session.get_adapter("https://")
|
|
31
|
+
self.assertIsNotNone(adapter)
|
|
32
|
+
self.assertIsInstance(adapter, HTTPAdapter)
|
|
@@ -1,35 +1,25 @@
|
|
|
1
|
+
from datetime import timedelta
|
|
2
|
+
|
|
1
3
|
from django.test import TestCase, override_settings
|
|
2
|
-
from django.contrib.contenttypes.models import ContentType
|
|
3
|
-
from django.contrib.auth.models import User
|
|
4
4
|
from django.utils import timezone
|
|
5
|
-
from
|
|
5
|
+
from django_webhook_subscriber import models
|
|
6
6
|
|
|
7
|
-
from
|
|
8
|
-
WebhookRegistry,
|
|
9
|
-
WebhookDeliveryLog,
|
|
10
|
-
)
|
|
7
|
+
from .factories import WebhookSubscriptionFactory
|
|
11
8
|
|
|
12
9
|
|
|
13
10
|
class WebhookDeliveryLogManagerTests(TestCase):
|
|
14
11
|
def setUp(self):
|
|
15
|
-
|
|
16
|
-
self.user_content_type = ContentType.objects.get_for_model(User)
|
|
17
|
-
|
|
18
|
-
# Create a webhook
|
|
19
|
-
self.webhook = WebhookRegistry.objects.create(
|
|
20
|
-
name="Test Webhook",
|
|
21
|
-
content_type=self.user_content_type,
|
|
22
|
-
event_signals=["CREATE", "UPDATE"],
|
|
23
|
-
endpoint="https://example.com/webhook",
|
|
24
|
-
)
|
|
12
|
+
self.subscription = WebhookSubscriptionFactory()
|
|
25
13
|
|
|
26
|
-
def _create_log_entry(self,
|
|
27
|
-
created_at = kwargs.pop(
|
|
14
|
+
def _create_log_entry(self, payload={}, delivery_url=None, **kwargs):
|
|
15
|
+
created_at = kwargs.pop("created_at", None)
|
|
16
|
+
subscription = kwargs.get("subscription", self.subscription)
|
|
17
|
+
delivery_url = delivery_url or self.subscription.endpoint
|
|
28
18
|
|
|
29
|
-
log = WebhookDeliveryLog.objects.create(
|
|
30
|
-
|
|
31
|
-
event_signal=event_signal,
|
|
19
|
+
log = models.WebhookDeliveryLog.objects.create(
|
|
20
|
+
subscription=subscription,
|
|
32
21
|
payload=payload,
|
|
22
|
+
delivery_url=delivery_url,
|
|
33
23
|
**kwargs,
|
|
34
24
|
)
|
|
35
25
|
|
|
@@ -40,34 +30,33 @@ class WebhookDeliveryLogManagerTests(TestCase):
|
|
|
40
30
|
|
|
41
31
|
return log
|
|
42
32
|
|
|
43
|
-
def test_create_log_entry(self
|
|
44
|
-
log = WebhookDeliveryLog.objects.create(
|
|
45
|
-
|
|
46
|
-
event_signal=event_signal,
|
|
33
|
+
def test_create_log_entry(self):
|
|
34
|
+
log = models.WebhookDeliveryLog.objects.create(
|
|
35
|
+
subscription=self.subscription,
|
|
47
36
|
payload={"key": "value"},
|
|
48
37
|
created_at=timezone.now(),
|
|
49
38
|
)
|
|
50
|
-
self.assertEqual(WebhookDeliveryLog.objects.count(), 1)
|
|
51
|
-
self.assertEqual(log.
|
|
39
|
+
self.assertEqual(models.WebhookDeliveryLog.objects.count(), 1)
|
|
40
|
+
self.assertEqual(log.subscription, self.subscription)
|
|
52
41
|
|
|
53
|
-
@override_settings(WEBHOOK_SUBSCRIBER={
|
|
42
|
+
@override_settings(WEBHOOK_SUBSCRIBER={"LOG_RETENTION_DAYS": 1})
|
|
54
43
|
def test_cleanup_old_logs_deletes_old_entries(self):
|
|
55
44
|
|
|
56
45
|
self._create_log_entry(created_at=timezone.now() - timedelta(days=2))
|
|
57
46
|
self._create_log_entry()
|
|
58
47
|
|
|
59
|
-
WebhookDeliveryLog.objects.cleanup_old_logs()
|
|
48
|
+
models.WebhookDeliveryLog.objects.cleanup_old_logs()
|
|
60
49
|
|
|
61
|
-
self.assertEqual(WebhookDeliveryLog.objects.count(), 1)
|
|
50
|
+
self.assertEqual(models.WebhookDeliveryLog.objects.count(), 1)
|
|
62
51
|
|
|
63
|
-
@override_settings(WEBHOOK_SUBSCRIBER={
|
|
52
|
+
@override_settings(WEBHOOK_SUBSCRIBER={"LOG_RETENTION_DAYS": 1})
|
|
64
53
|
def test_create_triggers_cleanup(self):
|
|
65
54
|
# Create an old log
|
|
66
55
|
old_log = self._create_log_entry(
|
|
67
56
|
created_at=timezone.now() - timedelta(days=2),
|
|
68
57
|
)
|
|
69
58
|
# Manually update created_at to simulate old timestamp
|
|
70
|
-
WebhookDeliveryLog.objects.filter(pk=old_log.pk).update(
|
|
59
|
+
models.WebhookDeliveryLog.objects.filter(pk=old_log.pk).update(
|
|
71
60
|
created_at=timezone.now() - timedelta(days=2)
|
|
72
61
|
)
|
|
73
62
|
|
|
@@ -75,19 +64,19 @@ class WebhookDeliveryLogManagerTests(TestCase):
|
|
|
75
64
|
self._create_log_entry()
|
|
76
65
|
|
|
77
66
|
# Only one (new) log should remain
|
|
78
|
-
self.assertEqual(WebhookDeliveryLog.objects.count(), 1)
|
|
67
|
+
self.assertEqual(models.WebhookDeliveryLog.objects.count(), 1)
|
|
79
68
|
|
|
80
|
-
@override_settings(WEBHOOK_SUBSCRIBER={
|
|
69
|
+
@override_settings(WEBHOOK_SUBSCRIBER={"AUTO_CLEANUP": False})
|
|
81
70
|
def test_auto_cleanup_respects_setting(self):
|
|
82
71
|
self._create_log_entry(created_at=timezone.now() - timedelta(days=40))
|
|
83
72
|
self._create_log_entry(created_at=timezone.now())
|
|
84
73
|
|
|
85
74
|
# Cleanup should not run because AUTO_CLEANUP is False
|
|
86
|
-
self.assertEqual(WebhookDeliveryLog.objects.count(), 2)
|
|
75
|
+
self.assertEqual(models.WebhookDeliveryLog.objects.count(), 2)
|
|
87
76
|
|
|
88
77
|
def test_auto_cleanup_respects_setting_default_values(self):
|
|
89
78
|
self._create_log_entry(created_at=timezone.now() - timedelta(days=40))
|
|
90
79
|
self._create_log_entry(created_at=timezone.now())
|
|
91
80
|
|
|
92
81
|
# Cleanup should have run because AUTO_CLEANUP is True
|
|
93
|
-
self.assertEqual(WebhookDeliveryLog.objects.count(), 1)
|
|
82
|
+
self.assertEqual(models.WebhookDeliveryLog.objects.count(), 1)
|