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.
Files changed (41) hide show
  1. django_webhook_subscriber/__init__.py +7 -1
  2. django_webhook_subscriber/admin.py +831 -182
  3. django_webhook_subscriber/apps.py +3 -20
  4. django_webhook_subscriber/conf.py +11 -24
  5. django_webhook_subscriber/delivery.py +414 -159
  6. django_webhook_subscriber/http.py +51 -0
  7. django_webhook_subscriber/management/commands/webhook.py +169 -0
  8. django_webhook_subscriber/management/commands/webhook_cache.py +173 -0
  9. django_webhook_subscriber/management/commands/webhook_logs.py +226 -0
  10. django_webhook_subscriber/management/commands/webhook_performance_test.py +469 -0
  11. django_webhook_subscriber/management/commands/webhook_send.py +96 -0
  12. django_webhook_subscriber/management/commands/webhook_status.py +139 -0
  13. django_webhook_subscriber/managers.py +36 -14
  14. django_webhook_subscriber/migrations/0002_remove_webhookregistry_content_type_and_more.py +192 -0
  15. django_webhook_subscriber/models.py +291 -114
  16. django_webhook_subscriber/serializers.py +16 -50
  17. django_webhook_subscriber/tasks.py +434 -56
  18. django_webhook_subscriber/tests/factories.py +40 -0
  19. django_webhook_subscriber/tests/settings.py +27 -8
  20. django_webhook_subscriber/tests/test_delivery.py +453 -190
  21. django_webhook_subscriber/tests/test_http.py +32 -0
  22. django_webhook_subscriber/tests/test_managers.py +26 -37
  23. django_webhook_subscriber/tests/test_models.py +341 -251
  24. django_webhook_subscriber/tests/test_serializers.py +22 -56
  25. django_webhook_subscriber/tests/test_tasks.py +477 -189
  26. django_webhook_subscriber/tests/test_utils.py +98 -94
  27. django_webhook_subscriber/utils.py +87 -69
  28. django_webhook_subscriber/validators.py +53 -0
  29. django_webhook_subscriber-2.0.0.dist-info/METADATA +774 -0
  30. django_webhook_subscriber-2.0.0.dist-info/RECORD +38 -0
  31. django_webhook_subscriber/management/commands/check_webhook_tasks.py +0 -113
  32. django_webhook_subscriber/management/commands/clean_webhook_logs.py +0 -65
  33. django_webhook_subscriber/management/commands/test_webhook.py +0 -96
  34. django_webhook_subscriber/signals.py +0 -152
  35. django_webhook_subscriber/testing.py +0 -14
  36. django_webhook_subscriber/tests/test_signals.py +0 -268
  37. django_webhook_subscriber-0.4.0.dist-info/METADATA +0 -448
  38. django_webhook_subscriber-0.4.0.dist-info/RECORD +0 -33
  39. {django_webhook_subscriber-0.4.0.dist-info → django_webhook_subscriber-2.0.0.dist-info}/WHEEL +0 -0
  40. {django_webhook_subscriber-0.4.0.dist-info → django_webhook_subscriber-2.0.0.dist-info}/licenses/LICENSE +0 -0
  41. {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.serializers import serialize_instance
7
- from django_webhook_subscriber.models import WebhookRegistry
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
- self.webhook_content_type = ContentType.objects.get_for_model(
13
- WebhookRegistry
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 = serialize_instance(self.webhook, 'create')
17
+ data = serialize_webhook_instance(self.instance)
25
18
 
26
- # Check that structure is correct
27
- self.assertEqual(data['pk'], self.webhook.pk)
28
- self.assertEqual(
29
- data['source'], 'django_webhook_subscriber.webhookregistry'
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 = WebhookRegistry
49
- fields = ['endpoint', 'name']
27
+ model = models.WebhookDeliveryLog
28
+ fields = ["id", "payload"]
50
29
 
51
30
  # Test with DRF serializer
52
- data = serialize_instance(
53
- self.webhook,
54
- event_signal='delete',
31
+ data = serialize_webhook_instance(
32
+ self.instance,
55
33
  field_serializer=CustomSerializer,
56
34
  )
57
35
 
58
- # Check the structure
59
- self.assertEqual(data['pk'], self.webhook.pk)
60
- self.assertEqual(
61
- data['source'], 'django_webhook_subscriber.webhookregistry'
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
- 'field_serializer must be a subclass of rest_framework.Serializer'
47
+ "field_serializer must be a subclass of rest_framework.Serializer"
81
48
  )
82
49
  with self.assertRaisesMessage(ValueError, msg):
83
- serialize_instance(
84
- self.webhook,
85
- event_signal='create',
50
+ serialize_webhook_instance(
51
+ self.instance,
86
52
  field_serializer=InvalidSerializer,
87
53
  )