forked from DefectDojo/django-DefectDojo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
report_builder_test.py
198 lines (153 loc) · 8.25 KB
/
report_builder_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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
import os
import sys
import unittest
from base_test_class import BaseTestCase
from product_test import ProductTest
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import Select, WebDriverWait
dir_path = os.path.dirname(os.path.realpath(__file__))
class ReportBuilderTest(BaseTestCase):
# Move the report blocks from Available Widgets to Report Format
def move_blocks(self, driver):
in_use = driver.find_element(By.ID, "sortable2")
available_widgets = driver.find_element(By.ID, "sortable1").find_elements(By.TAG_NAME, "li")
for widget in available_widgets:
ActionChains(driver).drag_and_drop(widget, in_use).perform()
# Fill in the boxes
def enter_values(self, driver):
in_use = driver.find_element(By.ID, "sortable2").find_elements(By.TAG_NAME, "li")
for widget in in_use:
class_names = widget.get_attribute("class")
if "cover-page" in class_names:
inputs = widget.find_elements(By.TAG_NAME, "input")
for field in inputs:
field.send_keys("cover words")
if "wysiwyg-content" in class_names:
widget.find_element(By.CLASS_NAME, "editor").send_keys("wysiwyg")
def generate_HTML_report(self):
driver = self.driver
driver.get(self.base_url + "reports/builder")
self.move_blocks(driver)
self.enter_values(driver)
Select(driver.find_element(By.ID, "id_report_type")).select_by_visible_text("HTML")
driver.find_element(By.ID, "id_report_name").send_keys("Test Report")
driver.find_element(By.CLASS_NAME, "run_report").click()
self.assertEqual(driver.current_url, self.base_url + "reports/custom")
def test_product_type_report(self):
driver = self.driver
driver.get(self.base_url + "product/type")
driver.find_element(By.ID, "dropdownMenuProductType").click()
driver.find_element(By.PARTIAL_LINK_TEXT, "Report").click()
my_select = Select(driver.find_element(By.ID, "id_include_finding_notes"))
my_select.select_by_index(1)
my_select = Select(driver.find_element(By.ID, "id_include_executive_summary"))
my_select.select_by_index(1)
my_select = Select(driver.find_element(By.ID, "id_include_executive_summary"))
my_select.select_by_index(1)
my_select = Select(driver.find_element(By.ID, "id_include_table_of_contents"))
my_select.select_by_index(1)
driver.find_element(By.NAME, "_generate").click()
def test_product_report(self):
driver = self.driver
self.goto_product_overview(driver)
driver.find_element(By.LINK_TEXT, "QA Test").click()
driver.find_element(By.ID, "dropdownMenu1").click()
driver.find_element(By.PARTIAL_LINK_TEXT, "Product Report").click()
my_select = Select(driver.find_element(By.ID, "id_include_finding_notes"))
my_select.select_by_index(1)
my_select = Select(driver.find_element(By.ID, "id_include_executive_summary"))
my_select.select_by_index(1)
my_select = Select(driver.find_element(By.ID, "id_include_table_of_contents"))
my_select.select_by_index(1)
driver.find_element(By.NAME, "_generate").click()
def test_engagement_report(self):
driver = self.driver
self.goto_product_overview(driver)
driver.find_element(By.LINK_TEXT, "QA Test").click()
driver.find_element(By.PARTIAL_LINK_TEXT, "Engagements").click()
driver.find_element(By.LINK_TEXT, "View Engagements").click()
driver.find_element(By.LINK_TEXT, "Ad Hoc Engagement").click()
driver.find_element(By.ID, "dropdownMenu1").click()
driver.find_element(By.PARTIAL_LINK_TEXT, "Report").click()
my_select = Select(driver.find_element(By.ID, "id_include_finding_notes"))
my_select.select_by_index(1)
my_select = Select(driver.find_element(By.ID, "id_include_executive_summary"))
my_select.select_by_index(1)
my_select = Select(driver.find_element(By.ID, "id_include_table_of_contents"))
my_select.select_by_index(1)
driver.find_element(By.NAME, "_generate").click()
def test_test_report(self):
driver = self.driver
self.goto_product_overview(driver)
driver.find_element(By.LINK_TEXT, "QA Test").click()
driver.find_element(By.PARTIAL_LINK_TEXT, "Engagements").click()
driver.find_element(By.LINK_TEXT, "View Engagements").click()
driver.find_element(By.LINK_TEXT, "Ad Hoc Engagement").click()
driver.find_element(By.LINK_TEXT, "Pen Test").click()
driver.find_element(By.ID, "dropdownMenu1").click()
driver.find_element(By.PARTIAL_LINK_TEXT, "Report").click()
my_select = Select(driver.find_element(By.ID, "id_include_finding_notes"))
my_select.select_by_index(1)
my_select = Select(driver.find_element(By.ID, "id_include_executive_summary"))
my_select.select_by_index(1)
my_select = Select(driver.find_element(By.ID, "id_include_table_of_contents"))
my_select.select_by_index(1)
driver.find_element(By.NAME, "_generate").click()
def test_product_endpoint_report(self):
driver = self.driver
self.goto_product_overview(driver)
driver.find_element(By.LINK_TEXT, "QA Test").click()
driver.find_element(By.PARTIAL_LINK_TEXT, "Endpoints").click()
driver.find_element(By.LINK_TEXT, "Endpoint Report").click()
# extra dropdown click
dropdown = WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.ID, "show-filters")))
dropdown = driver.find_element(By.ID, "show-filters")
dropdown.click()
my_select = WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, "//label[@for='id_include_finding_notes']")))
my_select = Select(driver.find_element(By.ID, "id_include_finding_notes"))
my_select.select_by_index(1)
my_select = Select(driver.find_element(By.ID, "id_include_executive_summary"))
my_select.select_by_index(1)
my_select = Select(driver.find_element(By.ID, "id_include_table_of_contents"))
my_select.select_by_index(1)
driver.find_element(By.NAME, "_generate").click()
def test_product_list_report(self):
driver = self.driver
self.goto_product_overview(driver)
driver.find_element(By.ID, "dropdownMenu1").click()
driver.find_element(By.LINK_TEXT, "Findings Report").click()
my_select = Select(driver.find_element(By.ID, "id_include_finding_notes"))
my_select.select_by_index(1)
my_select = Select(driver.find_element(By.ID, "id_include_executive_summary"))
my_select.select_by_index(1)
my_select = Select(driver.find_element(By.ID, "id_include_table_of_contents"))
my_select.select_by_index(1)
driver.find_element(By.NAME, "_generate").click()
def add_report_tests_to_suite(suite):
# Add each test the the suite to be run
# success and failure is output by the test
suite.addTest(BaseTestCase("test_login"))
suite.addTest(BaseTestCase("disable_block_execution"))
suite.addTest(ProductTest("test_create_product"))
suite.addTest(ProductTest("test_add_product_finding"))
suite.addTest(ProductTest("test_add_product_endpoints"))
suite.addTest(ReportBuilderTest("generate_HTML_report"))
# we add reports here as we now have a product that triggers some logic inside reports
suite.addTest(ReportBuilderTest("test_product_type_report"))
suite.addTest(ReportBuilderTest("test_product_report"))
suite.addTest(ReportBuilderTest("test_engagement_report"))
suite.addTest(ReportBuilderTest("test_test_report"))
suite.addTest(ReportBuilderTest("test_product_endpoint_report"))
suite.addTest(ProductTest("test_delete_product"))
return suite
def suite():
suite = unittest.TestSuite()
add_report_tests_to_suite(suite)
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)