forked from DefectDojo/django-DefectDojo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnotification_webhook_test.py
More file actions
107 lines (93 loc) · 4.56 KB
/
notification_webhook_test.py
File metadata and controls
107 lines (93 loc) · 4.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import sys
import unittest
from base_test_class import BaseTestCase, on_exception_html_source_logger
from selenium.webdriver.common.by import By
class NotificationWebhookTest(BaseTestCase):
@on_exception_html_source_logger
def test_enable_webhook_notifications(self):
"""Enable webhook notifications in system settings."""
driver = self.driver
driver.get(self.base_url + "system_settings")
webhook_checkbox = driver.find_element(By.ID, "id_enable_webhooks_notifications")
if not webhook_checkbox.is_selected():
webhook_checkbox.click()
driver.find_element(By.CSS_SELECTOR, "input.btn.btn-primary").click()
self.assertFalse(self.is_error_message_present())
@on_exception_html_source_logger
def test_list_webhooks_page_loads(self):
driver = self.driver
driver.get(self.base_url + "notifications/webhooks")
self.assertTrue(
self.is_text_present_on_page(text="Notification Webhook")
or self.is_text_present_on_page(text="Webhook"),
)
@on_exception_html_source_logger
def test_add_notification_webhook(self):
driver = self.driver
driver.get(self.base_url + "notifications/webhooks/add")
driver.find_element(By.ID, "id_name").clear()
driver.find_element(By.ID, "id_name").send_keys("Test Webhook")
driver.find_element(By.ID, "id_url").clear()
driver.find_element(By.ID, "id_url").send_keys("https://httpbin.org/post")
driver.find_element(By.CSS_SELECTOR, "input.btn.btn-primary").click()
self.assertTrue(
self.is_text_present_on_page(text="Test Webhook")
or self.is_text_present_on_page(text="Webhook"),
)
@on_exception_html_source_logger
def test_edit_notification_webhook(self):
driver = self.driver
driver.get(self.base_url + "notifications/webhooks")
# Click Edit link from the webhooks list (link text is "Edit / activate / deactivate")
edit_links = driver.find_elements(By.CSS_SELECTOR, "a.btn.btn-warning")
if len(edit_links) > 0:
edit_links[0].click()
driver.find_element(By.ID, "id_name").clear()
driver.find_element(By.ID, "id_name").send_keys("Edited Test Webhook")
driver.find_element(By.CSS_SELECTOR, "input.btn.btn-primary").click()
self.assertTrue(
self.is_text_present_on_page(text="Edited Test Webhook")
or self.is_text_present_on_page(text="Webhook"),
)
else:
self.fail("No Edit link found for webhook")
@on_exception_html_source_logger
def test_delete_notification_webhook(self):
driver = self.driver
driver.get(self.base_url + "notifications/webhooks")
# Click Delete link from the webhooks list
delete_links = driver.find_elements(By.CSS_SELECTOR, "a.btn.btn-danger")
if len(delete_links) > 0:
delete_links[0].click()
driver.find_element(By.CSS_SELECTOR, "input.btn.btn-danger").click()
self.assertTrue(
self.is_text_present_on_page(text="Webhook")
or not self.is_error_message_present(),
)
else:
self.fail("No Delete link found for webhook")
@on_exception_html_source_logger
def test_disable_webhook_notifications(self):
"""Disable webhook notifications to reset system settings."""
driver = self.driver
driver.get(self.base_url + "system_settings")
webhook_checkbox = driver.find_element(By.ID, "id_enable_webhooks_notifications")
if webhook_checkbox.is_selected():
webhook_checkbox.click()
driver.find_element(By.CSS_SELECTOR, "input.btn.btn-primary").click()
self.assertFalse(self.is_error_message_present())
def suite():
suite = unittest.TestSuite()
suite.addTest(BaseTestCase("test_login"))
suite.addTest(NotificationWebhookTest("test_enable_webhook_notifications"))
suite.addTest(NotificationWebhookTest("test_list_webhooks_page_loads"))
suite.addTest(NotificationWebhookTest("test_add_notification_webhook"))
suite.addTest(NotificationWebhookTest("test_edit_notification_webhook"))
suite.addTest(NotificationWebhookTest("test_delete_notification_webhook"))
suite.addTest(NotificationWebhookTest("test_disable_webhook_notifications"))
return suite
if __name__ == "__main__":
runner = unittest.TextTestRunner(descriptions=True, failfast=True, verbosity=2)
ret = not runner.run(suite()).wasSuccessful()
BaseTestCase.tearDownDriver()
sys.exit(ret)