forked from DefectDojo/django-DefectDojo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproduct_type_test.py
More file actions
98 lines (80 loc) · 4.56 KB
/
product_type_test.py
File metadata and controls
98 lines (80 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
import unittest
import sys
from base_test_class import BaseTestCase, on_exception_html_source_logger
from selenium.webdriver.common.by import By
class ProductTypeTest(BaseTestCase):
@on_exception_html_source_logger
def test_create_product_type(self):
print("\n\nDebug Print Log: testing 'create product type' \n")
driver = self.driver
driver.get(self.base_url + "product/type")
driver.find_element(By.ID, "dropdownMenu1").click()
driver.find_element(By.LINK_TEXT, "Add Product Type").click()
driver.find_element(By.ID, "id_name").clear()
driver.find_element(By.ID, "id_name").send_keys("Product test type")
driver.find_element(By.ID, "id_critical_product").click()
driver.find_element(By.CSS_SELECTOR, "input.btn.btn-primary").click()
self.assertTrue(self.is_success_message_present(text='Product type added successfully.'))
self.assertFalse(self.is_error_message_present())
@on_exception_html_source_logger
def test_create_product_for_product_type(self):
# make sure no left overs from previous runs are left behind
self.delete_product_if_exists("QA Test PT")
driver = self.driver
# Navigate to the product page
self.goto_product_type_overview(driver)
driver.find_element(By.ID, "dropdownMenuProductType").click()
driver.find_element(By.PARTIAL_LINK_TEXT, "Add Product").click()
# Fill in th product name
driver.find_element(By.ID, "id_name").clear()
driver.find_element(By.ID, "id_name").send_keys("QA Test PT")
# Tab into the description area to fill some text
# Couldnt find a way to get into the box with selenium
driver.find_element(By.ID, "id_name").send_keys("\tThis is just a test. Be very afraid.")
driver.find_element(By.CSS_SELECTOR, "input.btn.btn-primary").click()
# Assert ot the query to dtermine status of failure
# Also confirm success even if Product is returned as already exists for test sake
self.assertTrue(self.is_success_message_present(text='Product added successfully'))
self.assertFalse(self.is_error_message_present())
def test_view_product_type(self):
print("\n\nDebug Print Log: testing 'view product type' \n")
driver = self.driver
driver.get(self.base_url + "product/type")
driver.find_element(By.ID, "dropdownMenuProductType").click()
driver.find_element(By.PARTIAL_LINK_TEXT, "View").click()
product_type_text = driver.find_element(By.ID, "id_heading").text
self.assertEqual('Product Type Product test type', product_type_text)
def test_edit_product_type(self):
print("\n\nDebug Print Log: testing 'edit product type' \n")
driver = self.driver
driver.get(self.base_url + "product/type")
driver.find_element(By.ID, "dropdownMenuProductType").click()
driver.find_element(By.PARTIAL_LINK_TEXT, "Edit").click()
driver.find_element(By.ID, "id_name").clear()
driver.find_element(By.ID, "id_name").send_keys("Edited product test type")
driver.find_element(By.CSS_SELECTOR, "input.btn.btn-primary").click()
self.assertTrue(self.is_success_message_present(text='Product type updated successfully.'))
def test_delete_product_type(self):
print("\n\nDebug Print Log: testing 'delete product type' \n")
driver = self.driver
driver.get(self.base_url + "product/type")
# TODO this assumes the first product_type in the list is the one that we just created (and can safely be deleted)
driver.find_element(By.ID, "dropdownMenuProductType").click()
driver.find_element(By.PARTIAL_LINK_TEXT, "Delete").click()
driver.find_element(By.CSS_SELECTOR, "button.btn.btn-danger").click()
self.assertTrue(self.is_success_message_present(text='Product Type and relationships removed.'))
def suite():
suite = unittest.TestSuite()
suite.addTest(BaseTestCase('test_login'))
suite.addTest(BaseTestCase('disable_block_execution'))
suite.addTest(ProductTypeTest('test_create_product_type'))
suite.addTest(ProductTypeTest('test_view_product_type'))
suite.addTest(ProductTypeTest('test_create_product_for_product_type'))
suite.addTest(ProductTypeTest('test_edit_product_type'))
suite.addTest(ProductTypeTest('test_delete_product_type'))
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)