|
|
@@ -89,12 +89,16 @@ class WebhookTestCase(TestCase, BaseFilterSetTests):
|
|
|
|
|
|
@classmethod
|
|
|
def setUpTestData(cls):
|
|
|
- content_types = ContentType.objects.filter(model__in=['site', 'rack', 'device'])
|
|
|
+ content_types = ContentType.objects.filter(model__in=['region', 'site', 'rack', 'location', 'device'])
|
|
|
|
|
|
webhooks = (
|
|
|
Webhook(
|
|
|
name='Webhook 1',
|
|
|
type_create=True,
|
|
|
+ type_update=False,
|
|
|
+ type_delete=False,
|
|
|
+ type_job_start=False,
|
|
|
+ type_job_end=False,
|
|
|
payload_url='http://example.com/?1',
|
|
|
enabled=True,
|
|
|
http_method='GET',
|
|
|
@@ -102,7 +106,11 @@ class WebhookTestCase(TestCase, BaseFilterSetTests):
|
|
|
),
|
|
|
Webhook(
|
|
|
name='Webhook 2',
|
|
|
+ type_create=False,
|
|
|
type_update=True,
|
|
|
+ type_delete=False,
|
|
|
+ type_job_start=False,
|
|
|
+ type_job_end=False,
|
|
|
payload_url='http://example.com/?2',
|
|
|
enabled=True,
|
|
|
http_method='POST',
|
|
|
@@ -110,26 +118,56 @@ class WebhookTestCase(TestCase, BaseFilterSetTests):
|
|
|
),
|
|
|
Webhook(
|
|
|
name='Webhook 3',
|
|
|
+ type_create=False,
|
|
|
+ type_update=False,
|
|
|
type_delete=True,
|
|
|
+ type_job_start=False,
|
|
|
+ type_job_end=False,
|
|
|
payload_url='http://example.com/?3',
|
|
|
enabled=False,
|
|
|
http_method='PATCH',
|
|
|
ssl_verification=False,
|
|
|
),
|
|
|
+ Webhook(
|
|
|
+ name='Webhook 4',
|
|
|
+ type_create=False,
|
|
|
+ type_update=False,
|
|
|
+ type_delete=False,
|
|
|
+ type_job_start=True,
|
|
|
+ type_job_end=False,
|
|
|
+ payload_url='http://example.com/?4',
|
|
|
+ enabled=False,
|
|
|
+ http_method='PATCH',
|
|
|
+ ssl_verification=False,
|
|
|
+ ),
|
|
|
+ Webhook(
|
|
|
+ name='Webhook 5',
|
|
|
+ type_create=False,
|
|
|
+ type_update=False,
|
|
|
+ type_delete=False,
|
|
|
+ type_job_start=False,
|
|
|
+ type_job_end=True,
|
|
|
+ payload_url='http://example.com/?5',
|
|
|
+ enabled=False,
|
|
|
+ http_method='PATCH',
|
|
|
+ ssl_verification=False,
|
|
|
+ ),
|
|
|
)
|
|
|
Webhook.objects.bulk_create(webhooks)
|
|
|
webhooks[0].content_types.add(content_types[0])
|
|
|
webhooks[1].content_types.add(content_types[1])
|
|
|
webhooks[2].content_types.add(content_types[2])
|
|
|
+ webhooks[3].content_types.add(content_types[3])
|
|
|
+ webhooks[4].content_types.add(content_types[4])
|
|
|
|
|
|
def test_name(self):
|
|
|
params = {'name': ['Webhook 1', 'Webhook 2']}
|
|
|
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
|
|
|
|
|
|
def test_content_types(self):
|
|
|
- params = {'content_types': 'dcim.site'}
|
|
|
+ params = {'content_types': 'dcim.region'}
|
|
|
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 1)
|
|
|
- params = {'content_type_id': [ContentType.objects.get_for_model(Site).pk]}
|
|
|
+ params = {'content_type_id': [ContentType.objects.get_for_model(Region).pk]}
|
|
|
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 1)
|
|
|
|
|
|
def test_type_create(self):
|
|
|
@@ -144,6 +182,14 @@ class WebhookTestCase(TestCase, BaseFilterSetTests):
|
|
|
params = {'type_delete': True}
|
|
|
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 1)
|
|
|
|
|
|
+ def test_type_job_start(self):
|
|
|
+ params = {'type_job_start': True}
|
|
|
+ self.assertEqual(self.filterset(params, self.queryset).qs.count(), 1)
|
|
|
+
|
|
|
+ def test_type_job_end(self):
|
|
|
+ params = {'type_job_end': True}
|
|
|
+ self.assertEqual(self.filterset(params, self.queryset).qs.count(), 1)
|
|
|
+
|
|
|
def test_enabled(self):
|
|
|
params = {'enabled': True}
|
|
|
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
|