forked from DefectDojo/django-DefectDojo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
engagement_test.py
119 lines (97 loc) · 5.76 KB
/
engagement_test.py
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
108
109
110
111
112
113
114
115
116
117
118
119
import sys
import unittest
from base_test_class import BaseTestCase
from product_test import ProductTest
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import Select
class EngagementTest(BaseTestCase):
def test_list_active_engagements_found(self):
driver = self.driver
self.goto_active_engagements_overview(driver)
self.assertIn("edited test engagement</a>", driver.page_source)
def test_list_active_engagements_empty(self):
driver = self.driver
self.goto_active_engagements_overview(driver)
self.assertNotIn("edited test engagement</a>", driver.page_source)
def test_list_all_engagements_by_product(self):
driver = self.driver
self.goto_all_engagements_by_product_overview(driver)
self.assertIn("edited test engagement</a>", driver.page_source)
def test_add_new_engagement(self):
driver = self.driver
self.goto_product_overview(driver)
driver.find_element(By.CSS_SELECTOR, ".dropdown-toggle.pull-left").click()
driver.find_element(By.PARTIAL_LINK_TEXT, "Add New Engagement").click()
driver.find_element(By.ID, "id_name").send_keys("test engagement")
driver.find_element(By.ID, "id_name").send_keys("\tthis is engagement test.")
driver.find_element(By.ID, "id_test_strategy").clear()
driver.find_element(By.ID, "id_test_strategy").send_keys("http://localhost:5000")
Select(driver.find_element(By.ID, "id_status")).select_by_visible_text("In Progress")
driver.find_element(By.CSS_SELECTOR, "input[value='Done']").click()
self.assertTrue(self.is_success_message_present(text="Engagement added successfully."))
def test_edit_created_new_engagement(self):
driver = self.driver
self.goto_product_overview(driver)
driver.find_element(By.CSS_SELECTOR, ".dropdown-toggle.pull-left").click()
driver.find_element(By.LINK_TEXT, "View Engagements").click()
driver.find_element(By.LINK_TEXT, "test engagement").click()
driver.find_element(By.ID, "dropdownMenu1").click()
driver.find_element(By.LINK_TEXT, "Edit Engagement").click()
driver.find_element(By.ID, "id_name").clear()
driver.find_element(By.ID, "id_name").send_keys("edited test engagement")
Select(driver.find_element(By.ID, "id_status")).select_by_visible_text("In Progress")
driver.find_element(By.CSS_SELECTOR, "input[value='Done']").click()
self.assertTrue(self.is_success_message_present(text="Engagement updated successfully."))
def test_close_new_engagement(self):
driver = self.driver
self.goto_product_overview(driver)
driver.find_element(By.CSS_SELECTOR, ".dropdown-toggle.pull-left").click()
driver.find_element(By.LINK_TEXT, "View Engagements").click()
driver.find_element(By.LINK_TEXT, "edited test engagement").click()
driver.find_element(By.ID, "dropdownMenu1").click()
driver.find_element(By.LINK_TEXT, "Close Engagement").click()
self.assertTrue(self.is_success_message_present(text="Engagement closed successfully."))
def test_delete_new_closed_engagement(self):
driver = self.driver
self.goto_product_overview(driver)
driver.find_element(By.CSS_SELECTOR, ".dropdown-toggle.pull-left").click()
driver.find_element(By.LINK_TEXT, "View Engagements").click()
self.wait_for_datatable_if_content("no_active_engagements", "open_wrapper")
driver.find_element(By.LINK_TEXT, "edited test engagement").click()
driver.find_element(By.ID, "dropdownMenu1").click()
driver.find_element(By.LINK_TEXT, "Delete Engagement").click()
driver.find_element(By.NAME, "delete_name").click()
self.assertTrue(self.is_success_message_present(text="Engagement and relationships removed."))
def test_new_ci_cd_engagement(self):
driver = self.driver
self.goto_product_overview(driver)
# wait for product_wrapper div as datatables javascript modifies the DOM on page load.
driver.find_element(By.ID, "products_wrapper")
driver.find_element(By.LINK_TEXT, "QA Test").click()
driver.find_element(By.XPATH, "//a[@class='dropdown-toggle active']//span[@class='hidden-xs']").click()
driver.find_element(By.LINK_TEXT, "Add New CI/CD Engagement").click()
driver.find_element(By.ID, "id_name").send_keys("test new ci/cd engagement")
driver.find_element(By.ID, "id_name").send_keys("\ttest new ci/cd engagement")
driver.find_element(By.ID, "id_deduplication_on_engagement").get_attribute("checked")
driver.find_element(By.CSS_SELECTOR, "input[value='Done']").click()
self.assertTrue(self.is_success_message_present(text="Engagement added successfully."))
def suite():
suite = unittest.TestSuite()
suite.addTest(BaseTestCase("test_login"))
suite.addTest(BaseTestCase("disable_block_execution"))
suite.addTest(ProductTest("test_create_product"))
suite.addTest(EngagementTest("test_add_new_engagement"))
suite.addTest(EngagementTest("test_edit_created_new_engagement"))
suite.addTest(EngagementTest("test_list_active_engagements_found"))
suite.addTest(EngagementTest("test_close_new_engagement"))
suite.addTest(EngagementTest("test_list_active_engagements_empty"))
suite.addTest(EngagementTest("test_list_all_engagements_by_product"))
suite.addTest(EngagementTest("test_delete_new_closed_engagement"))
suite.addTest(EngagementTest("test_new_ci_cd_engagement"))
suite.addTest(ProductTest("test_delete_product"))
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)