Skip to content
This repository has been archived by the owner on Jan 26, 2021. It is now read-only.

Commit

Permalink
Add docstrings to home tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Monal5031 committed Jul 21, 2018
1 parent f9a5ed6 commit 1265e14
Showing 1 changed file with 76 additions and 4 deletions.
80 changes: 76 additions & 4 deletions vms/home/tests/test_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ class CheckURLAccess(LiveServerTestCase):

@classmethod
def setUpClass(cls):
"""Method to initiate class level objects.
This method initiates Firefox WebDriver, WebDriverWait and
the corresponding POM objects for this Test Class
"""
cls.driver = webdriver.Firefox()
cls.driver.implicitly_wait(5)
cls.driver.maximize_window()
Expand All @@ -35,18 +40,36 @@ def setUpClass(cls):
super(CheckURLAccess, cls).setUpClass()

def setUp(self):
"""
Method consists of statements to be executed before
start of each test.
"""
create_admin()
create_volunteer()

def tearDown(self):
"""
Method consists of statements to be executed at
end of each test.
"""
pass

@classmethod
def tearDownClass(cls):
"""
Class method to quit the Firefox WebDriver session after
execution of all tests in class.
"""
cls.driver.quit()
super(CheckURLAccess, cls).tearDownClass()

def verify_admin_page_error(self, admin_url):
"""
Utility function to verify errors raised on the
pages when user tries to admin pages provided as
admin_url in param.
:param admin_url: URL of admin page to check errors on.
"""
home_page = self.home_page
home_page.get_page(self.live_server_url, admin_url)
heading = home_page.get_no_admin_right()
Expand All @@ -57,6 +80,12 @@ def verify_admin_page_error(self, admin_url):
self.assertEqual(body.text, 'You don\'t have administrator rights')

def verify_volunteer_page_error(self, volunteer_url):
"""
Utility function to verify errors raised on the
pages when user tries to volunteer pages provided as
volunteer_url in param.
:param volunteer_url: URL of volunteer page to check errors on.
"""
home_page = self.home_page
home_page.get_page(self.live_server_url, volunteer_url)
head = home_page.get_no_volunteer_right()
Expand All @@ -67,12 +96,20 @@ def verify_volunteer_page_error(self, volunteer_url):
self.assertEqual(body.text, 'You don\'t have the required rights')

def login(self, username, password):
"""
Utility function to login with credentials received as parameters.
:param username: Username of the user
:param password: Password of the user
"""
self.authentication_page.login({
'username': username,
'password': password
})

def wait_for_home_page(self):
"""
Utility function to perform a explicit wait for home page.
"""
self.wait.until(
EC.presence_of_element_located(
(By.XPATH,
Expand All @@ -82,8 +119,8 @@ def wait_for_home_page(self):

def test_admin_cannot_access_volunteer_urls(self):
"""
Method will login as admin user and tries to surf volunteer pages through url.
The volunteer views should return a no rights page.
Test admin will be shown errors when they try to access
volunteers URLs.
"""

authentication_page = self.authentication_page
Expand All @@ -98,8 +135,8 @@ def test_admin_cannot_access_volunteer_urls(self):

def test_volunteer_cannot_access_admin_urls(self):
"""
Method will login as volunteer and tries to surf admin page views through url.
The admin views should return a no admin rights page.
Test volunteer will be shown errors when they try to access
admin URLs.
"""
authentication_page = self.authentication_page
authentication_page.server_url = self.live_server_url
Expand Down Expand Up @@ -144,6 +181,11 @@ class CheckContentAndRedirection(LiveServerTestCase):

@classmethod
def setUpClass(cls):
"""Method to initiate class level objects.
This method initiates Firefox WebDriver, WebDriverWait and
the corresponding POM objects for this Test Class
"""
cls.driver = webdriver.Firefox()
cls.driver.implicitly_wait(5)
cls.driver.maximize_window()
Expand All @@ -153,25 +195,45 @@ def setUpClass(cls):
super(CheckContentAndRedirection, cls).setUpClass()

def setUp(self):
"""
Method consists of statements to be executed before
start of each test.
"""
self.admin = create_admin()
self.volunteer = create_volunteer()
self.volunteer_id = str(self.volunteer.id)

def tearDown(self):
"""
Method consists of statements to be executed at
end of each test.
"""
pass

@classmethod
def tearDownClass(cls):
"""
Class method to quit the Firefox WebDriver session after
execution of all tests in class.
"""
cls.driver.quit()
super(CheckContentAndRedirection, cls).tearDownClass()

def login(self, username, password):
"""
Utility function to login with credentials received as parameters.
:param username: Username of the user
:param password: Password of the user
"""
self.authentication_page.login({
'username': username,
'password': password
})

def wait_for_home_page(self):
"""
Utility function to perform a explicit wait for home page.
"""
self.wait.until(
EC.presence_of_element_located(
(By.XPATH,
Expand Down Expand Up @@ -232,6 +294,11 @@ def test_check_volunteer_page_content(self):
self.assertNotEqual(home_page.get_logout_link(), None)

def test_admin_page_redirection(self):
"""
Test admin is redirected corrected to home page after
successful authorization by checking different elements
on home page.
"""
home_page = self.home_page
authentication_page = self.authentication_page
authentication_page.server_url = self.live_server_url
Expand Down Expand Up @@ -269,6 +336,11 @@ def test_admin_page_redirection(self):
self.live_server_url + PageUrls.logout_page)

def test_volunteer_page_redirection(self):
"""
Test volunteer is redirected corrected to home page after
successful authorization by checking different elements
on home page.
"""
home_page = self.home_page
authentication_page = self.authentication_page
authentication_page.server_url = self.live_server_url
Expand Down

0 comments on commit 1265e14

Please sign in to comment.