forked from DefectDojo/django-DefectDojo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuser_profile_test.py
More file actions
91 lines (78 loc) · 3.19 KB
/
user_profile_test.py
File metadata and controls
91 lines (78 loc) · 3.19 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
import sys
import time
import unittest
from base_test_class import BaseTestCase, on_exception_html_source_logger, set_suite_settings
from selenium.webdriver.common.by import By
class UserProfileTest(BaseTestCase):
@on_exception_html_source_logger
def test_view_profile_page_loads(self):
driver = self.driver
driver.get(self.base_url + "profile")
self.assertTrue(
self.is_text_present_on_page(text="User Profile")
or self.is_text_present_on_page(text="profile"),
)
@on_exception_html_source_logger
def test_edit_profile(self):
driver = self.driver
driver.get(self.base_url + "profile")
time.sleep(1)
# Edit first name
first_name = driver.find_element(By.ID, "id_first_name")
first_name.clear()
first_name.send_keys("Admin")
last_name = driver.find_element(By.ID, "id_last_name")
last_name.clear()
last_name.send_keys("User")
driver.find_element(By.CSS_SELECTOR, "input.btn.btn-primary").click()
self.assertTrue(
self.is_success_message_present(text="Profile updated successfully")
or self.is_text_present_on_page(text="User Profile"),
)
@on_exception_html_source_logger
def test_change_password_page_loads(self):
driver = self.driver
driver.get(self.base_url + "change_password")
self.assertTrue(
self.is_text_present_on_page(text="Change Password")
or self.is_text_present_on_page(text="password"),
)
@on_exception_html_source_logger
def test_api_key_page_loads(self):
driver = self.driver
driver.get(self.base_url + "api/key-v2")
self.assertTrue(
self.is_text_present_on_page(text="API")
or self.is_text_present_on_page(text="Key"),
)
@on_exception_html_source_logger
def test_generate_api_key(self):
driver = self.driver
driver.get(self.base_url + "api/key-v2")
time.sleep(1)
# Submit form to generate new key
submit_btns = driver.find_elements(By.CSS_SELECTOR, "input.btn.btn-primary")
if len(submit_btns) > 0:
submit_btns[0].click()
time.sleep(1)
self.assertTrue(
self.is_success_message_present(text="API Key generated successfully")
or self.is_text_present_on_page(text="API"),
)
else:
self.assertTrue(self.is_text_present_on_page(text="API"))
def suite():
suite = unittest.TestSuite()
suite.addTest(BaseTestCase("test_login"))
set_suite_settings(suite, jira=False, github=False, block_execution=False)
suite.addTest(UserProfileTest("test_view_profile_page_loads"))
suite.addTest(UserProfileTest("test_edit_profile"))
suite.addTest(UserProfileTest("test_change_password_page_loads"))
suite.addTest(UserProfileTest("test_api_key_page_loads"))
suite.addTest(UserProfileTest("test_generate_api_key"))
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)