This repository has been archived by the owner on Jan 26, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Testing Authentication app * Add docstrings to tests
- Loading branch information
Showing
4 changed files
with
144 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +0,0 @@ | ||
# Django | ||
from django import forms | ||
|
||
|
||
class AuthenticationForm(forms.Form): | ||
username = forms.CharField(required=True) | ||
password = forms.CharField(widget=forms.PasswordInput(), required=True) | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,123 +1,206 @@ | ||
# third party | ||
from selenium import webdriver | ||
from selenium.common.exceptions import NoSuchElementException | ||
from selenium.webdriver.support.ui import WebDriverWait | ||
from selenium.webdriver.support import expected_conditions as EC | ||
from selenium.webdriver.common.by import By | ||
|
||
# Django | ||
from django.contrib.staticfiles.testing import LiveServerTestCase | ||
|
||
# local Django | ||
from pom.pages.authenticationPage import AuthenticationPage | ||
|
||
from pom.locators.authenticationPageLocators import AuthenticationPageLocators | ||
from shift.utils import (create_admin, create_volunteer) | ||
|
||
|
||
# Class contains failing test cases which have been documented | ||
# Test class commented out to prevent travis build failure | ||
""" | ||
class TestAccessControl(LiveServerTestCase): | ||
''' | ||
""" | ||
TestAccessControl class contains the functional tests to check Admin and | ||
Volunteer can access '/home' view of VMS. Following tests are included: | ||
Administrator: | ||
- Login admin with correct credentials | ||
- Login admin with incorrect credentials | ||
- Login admin with incorrect credentials | ||
Volunteer: | ||
- Login volunteer with correct credentials | ||
- Login volunteer with incorrect credentials | ||
''' | ||
- Login volunteer with incorrect credentials | ||
""" | ||
|
||
@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.maximize_window() | ||
cls.authentication_page = AuthenticationPage(cls.driver) | ||
cls.wait = WebDriverWait(cls.driver, 5) | ||
super(TestAccessControl, cls).setUpClass() | ||
|
||
def setUp(self): | ||
admin = create_admin() | ||
volunteer = create_volunteer() | ||
""" | ||
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(TestAccessControl, 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 test_correct_admin_credentials(self): | ||
''' | ||
Method to simulate logging in of a valid admin user and check if they | ||
redirected to '/home' and no errors are generated. | ||
''' | ||
""" | ||
Test user redirected to home page after logging in as | ||
admin with correct credentials. | ||
""" | ||
authentication_page = self.authentication_page | ||
self.authentication_page.server_url = self.live_server_url | ||
authentication_page.login({'username': 'admin', 'password': 'admin'}) | ||
self.assertEqual(self.driver.current_url, | ||
authentication_page.server_url = self.live_server_url | ||
authentication_page.go_to_authentication_page() | ||
username = password = 'admin' | ||
self.login(username, password) | ||
|
||
self.wait.until( | ||
EC.presence_of_element_located( | ||
(By.XPATH, | ||
"//h1[contains(text(), 'Volunteer Management System')]")) | ||
) | ||
|
||
self.assertEqual(authentication_page.remove_i18n(self.driver.current_url), | ||
self.live_server_url + authentication_page.homepage) | ||
|
||
with self.assertRaises(NoSuchElementException): | ||
authentication_page.get_incorrect_login_message() | ||
self.assertRaisesRegexp(NoSuchElementException, | ||
'Message: Unable to locate element: .alert-danger', | ||
authentication_page.get_incorrect_login_message) | ||
authentication_page.logout() | ||
|
||
def test_incorrect_admin_credentials(self): | ||
''' | ||
Method to simulate logging in of an Invalid admin user and check if | ||
they are displayed an error and redirected to login page again. | ||
''' | ||
""" | ||
Test correct error message displayed while logging as | ||
admin with incorrect credentials. | ||
""" | ||
authentication_page = self.authentication_page | ||
self.authentication_page.server_url = self.live_server_url | ||
authentication_page.login({ | ||
'username': 'admin', | ||
'password': 'wrong_password' | ||
}) | ||
self.assertNotEqual( | ||
self.driver.current_url, | ||
self.live_server_url + authentication_page.homepage) | ||
authentication_page.server_url = self.live_server_url | ||
authentication_page.go_to_authentication_page() | ||
username = 'admin' | ||
password = 'wrong_password' | ||
self.login(username, password) | ||
|
||
self.wait.until( | ||
EC.presence_of_element_located( | ||
(By.CSS_SELECTOR, '.' + AuthenticationPageLocators.INCORRECT_LOGIN_ERROR)) | ||
) | ||
|
||
self.assertEqual(self.driver.current_url, | ||
self.assertNotEqual(authentication_page.remove_i18n(self.driver.current_url), | ||
self.live_server_url + authentication_page.homepage) | ||
|
||
self.assertEqual(authentication_page.remove_i18n(self.driver.current_url), | ||
self.live_server_url + authentication_page.url) | ||
|
||
self.assertNotEqual(authentication_page.get_incorrect_login_message(), | ||
None) | ||
|
||
def test_correct_volunteer_credentials(self): | ||
''' | ||
Method to simulate logging in of a valid volunteer user and check if | ||
they are redirected to '/home' | ||
''' | ||
""" | ||
Test user redirected to home page after logging in as | ||
volunteer with correct credentials. | ||
""" | ||
authentication_page = self.authentication_page | ||
self.authentication_page.server_url = self.live_server_url | ||
authentication_page.login({ | ||
'username': 'volunteer', | ||
'password': 'volunteer' | ||
}) | ||
self.assertEqual(self.driver.current_url, | ||
authentication_page.server_url = self.live_server_url | ||
authentication_page.go_to_authentication_page() | ||
username = password = 'volunteer' | ||
self.login(username, password) | ||
|
||
self.wait.until( | ||
EC.presence_of_element_located( | ||
(By.XPATH, | ||
"//h1[contains(text(), 'Volunteer Management System')]")) | ||
) | ||
|
||
self.assertEqual(authentication_page.remove_i18n(self.driver.current_url), | ||
self.live_server_url + authentication_page.homepage) | ||
|
||
with self.assertRaises(NoSuchElementException): | ||
authentication_page.get_incorrect_login_message() | ||
self.assertRaisesRegexp(NoSuchElementException, | ||
'Message: Unable to locate element: .alert-danger', | ||
authentication_page.get_incorrect_login_message) | ||
authentication_page.logout() | ||
|
||
def test_incorrect_volunteer_credentials(self): | ||
''' | ||
Method to simulate logging in of a Invalid volunteer user and check if | ||
they are displayed an error and redirected to login page again. | ||
''' | ||
""" | ||
Test correct error message displayed while logging as | ||
volunteer with incorrect credentials. | ||
""" | ||
authentication_page = self.authentication_page | ||
self.authentication_page.server_url = self.live_server_url | ||
authentication_page.login({ | ||
'username': 'volunteer', | ||
'password': 'wrong_password' | ||
}) | ||
authentication_page.server_url = self.live_server_url | ||
authentication_page.go_to_authentication_page() | ||
username = 'volunteer' | ||
password = 'wrong_password' | ||
self.login(username, password) | ||
|
||
self.assertNotEqual( | ||
self.driver.current_url, | ||
self.live_server_url + authentication_page.homepage) | ||
self.wait.until( | ||
EC.presence_of_element_located( | ||
(By.CSS_SELECTOR, '.' + AuthenticationPageLocators.INCORRECT_LOGIN_ERROR)) | ||
) | ||
|
||
self.assertEqual(self.driver.current_url, | ||
self.live_server_url + authentication_page.url) | ||
self.assertNotEqual(authentication_page.remove_i18n(self.driver.current_url), | ||
self.live_server_url + authentication_page.homepage) | ||
|
||
<<<<<<< ec806c6d047fd408e0fd890e7c6845e2f54622e6 | ||
self.assertEqual(authentication_page.remove_i18n(self.driver.current_url), | ||
self.live_server_url + authentication_page.url) | ||
self.assertNotEqual(authentication_page.get_incorrect_login_message(), None) | ||
""" | ||
|
||
def test_login_page_after_authentication(self): | ||
""" | ||
Test user redirected to home page if they try to access login page | ||
after logging in. | ||
""" | ||
authentication_page = self.authentication_page | ||
authentication_page.server_url = self.live_server_url | ||
username = password = 'admin' | ||
self.login(username, password) | ||
|
||
self.wait.until( | ||
EC.presence_of_element_located( | ||
(By.XPATH, | ||
"//h1[contains(text(), 'Volunteer Management System')]")) | ||
) | ||
|
||
self.assertEqual(authentication_page.remove_i18n(self.driver.current_url), | ||
self.live_server_url + authentication_page.homepage) | ||
|
||
self.assertRaisesRegexp(NoSuchElementException, | ||
'Message: Unable to locate element: .alert-danger', | ||
authentication_page.get_incorrect_login_message) | ||
|
||
authentication_page.get_page(authentication_page.server_url, '/authentication/') | ||
|
||
self.assertEqual(authentication_page.remove_i18n(self.driver.current_url), | ||
self.live_server_url + authentication_page.homepage) | ||
|
||
authentication_page.logout() | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters