-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #39 from ted537/refractor
Refractor
- Loading branch information
Showing
9 changed files
with
107 additions
and
127 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
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
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
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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
from seleniumbase import BaseCase | ||
from werkzeug.security import generate_password_hash | ||
from qa327_test.conftest import base_url | ||
from qa327.models import User | ||
|
||
# Mock a sample user | ||
TEST_USER = User( | ||
email='[email protected]', | ||
name='test_frontend', | ||
password=generate_password_hash('test_frontend'), | ||
balance=140 | ||
) | ||
|
||
class GeekBaseCase(BaseCase): | ||
''' | ||
Selenium base case with some | ||
GeekSeek utilities | ||
''' | ||
|
||
def assert_flash(self, text): | ||
'''asserts that message exists in flashes''' | ||
for flash_dom in self.find_elements('.flash'): | ||
if flash_dom.text == text: | ||
return | ||
raise AssertionError(f'Flash not found for text "{text}"') | ||
|
||
def login_test_user(self, email=TEST_USER.email, password='test_frontend'): | ||
'''login our test user''' | ||
self.open(base_url+'/login') | ||
self.input('#email', email) | ||
self.input('#password', password) | ||
self.click('#btn-submit') |
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 |
---|---|---|
|
@@ -8,31 +8,16 @@ | |
|
||
from qa327_test.conftest import base_url | ||
from qa327.models import User | ||
|
||
# Mock a sample user | ||
TEST_USER = User( | ||
email='[email protected]', | ||
name='test_frontend', | ||
password=generate_password_hash('test_frontend'), | ||
balance=140 | ||
) | ||
from qa327_test.frontend.geek_base import GeekBaseCase, TEST_USER | ||
|
||
INVALID_EMAILS = ['test_frontendtest.com', '[email protected]', 'test\f[email protected]'] | ||
|
||
INVALID_PASSWORDS = ['Pass!', 'password123!', 'PASSWORD123!', 'Password123'] | ||
|
||
class R1Test(BaseCase): | ||
class R1Test(GeekBaseCase): | ||
''' | ||
Contains test cases specific to R1 | ||
''' | ||
|
||
def login_test_user(self): | ||
'''login our test user''' | ||
self.open(base_url+'/login') | ||
self.input('#email', TEST_USER.email) | ||
self.input('#password', 'test_frontend') | ||
self.click('#btn-submit') | ||
|
||
def test_login_redirects(self, *_): | ||
'''see r1.1''' | ||
self.open(base_url) | ||
|
@@ -71,7 +56,7 @@ def test_form_password_missing(self, *_): | |
self.open(base_url+'/login') | ||
self.input('#email', TEST_USER.email) | ||
self.click('#btn-submit') | ||
#leave password empty | ||
# leave password empty | ||
message = self.driver.find_element_by_id('password') | ||
assert message.get_attribute('validationMessage') == 'Please fill out this field.' | ||
|
||
|
@@ -81,7 +66,7 @@ def test_form_email_missing(self, *_): | |
self.open(base_url+'/login') | ||
self.input('#password', 'test_frontend') | ||
self.click('#btn-submit') | ||
#leave password empty | ||
# leave password empty | ||
message = self.driver.find_element_by_id('email') | ||
assert message.get_attribute('validationMessage') == 'Please fill out this field.' | ||
|
||
|
@@ -93,7 +78,7 @@ def test_email_rfc_specs(self, *_): | |
|
||
def test_invalid_email_rfc_specs(self, *_): | ||
'''see r1.7 (negative)''' | ||
#invalid email format | ||
# invalid email format | ||
for invalid_email in INVALID_EMAILS: | ||
self.open(base_url+'/login') | ||
self.input('#email', invalid_email) | ||
|
@@ -111,7 +96,7 @@ def test_password_complexity(self, *_): | |
|
||
def test_invalid_password_complexity(self, *_): | ||
'''see r1.8 (negative)''' | ||
#invalid password complexity | ||
# invalid password complexity | ||
for invalid_pass in INVALID_PASSWORDS: | ||
self.open(base_url+'/login') | ||
self.input('#email', TEST_USER.email) | ||
|
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 |
---|---|---|
|
@@ -4,54 +4,45 @@ | |
|
||
from unittest.mock import patch | ||
from werkzeug.security import generate_password_hash | ||
from seleniumbase import BaseCase | ||
from qa327_test.conftest import base_url | ||
|
||
import qa327.models | ||
|
||
# Defines user class to make testing more streamlined | ||
class User: | ||
def __init__(self, email=None, name=None, password=None): | ||
self.email = email | ||
self.name = name | ||
self.password = password | ||
|
||
from qa327.models import User | ||
from qa327_test.conftest import base_url | ||
from qa327_test.frontend.geek_base import GeekBaseCase | ||
|
||
# Defines test information | ||
TEST_USER_A = qa327.models.User( | ||
TEST_USER_A = User( | ||
email='[email protected]', | ||
name='test_frontend', | ||
password=generate_password_hash('Password123!', method='sha256'), | ||
balance=5000 | ||
) | ||
|
||
TEST_USER_B = qa327.models.User( | ||
email='[email protected]', | ||
name='test_frontend', | ||
password='Password123!' | ||
) | ||
|
||
|
||
VALID_USER = User( | ||
email='[email protected]', | ||
name='test_frontend', | ||
password='Password123!' | ||
) | ||
|
||
INVALID_USER_NAME_FORMATS = ['', 'test_frontend123!', ' test_frontend123', | ||
'test_frontend123 '] | ||
INVALID_USER_NAME_FORMATS = [ | ||
'', 'test_frontend123!', | ||
' test_frontend123', 'test_frontend123 ' | ||
] | ||
|
||
INVALID_USER_NAME_LENGTHS = ['te', 'test_frontend1234567890'] | ||
|
||
INVALID_USER_EMAILS = ['', 'test_frontendtest.com', 'test_frontend@testcom', | ||
'[email protected]'] | ||
INVALID_USER_EMAILS = [ | ||
'', 'test_frontendtest.com', | ||
'test_frontend@testcom', '[email protected]' | ||
] | ||
|
||
INVALID_USER_PASSWORDS = ['', 'Pass!', 'password123!', 'PASSWORD123!', | ||
'Password123'] | ||
INVALID_USER_PASSWORDS = [ | ||
'', 'Pass!', 'password123!', | ||
'PASSWORD123!','Password123' | ||
] | ||
|
||
MISMATCHED_PASSWORD2 = 'Password123! ' | ||
|
||
class R2Test(BaseCase): | ||
class R2Test(GeekBaseCase): | ||
''' | ||
Contains test cases specific to R2 | ||
''' | ||
|
@@ -71,27 +62,6 @@ def register_test_user(self, *_): | |
# Submits the inputted information | ||
self.click('#register-submit') | ||
|
||
|
||
def login_test_user(self): | ||
'''login our test user''' | ||
# Opens login page | ||
self.open(base_url+'/login') | ||
|
||
# Logins in with user information | ||
self.input('#email', TEST_USER_A.email) | ||
self.input('#password', VALID_USER.password) | ||
|
||
# Submits the inputted information | ||
self.click('#btn-submit') | ||
|
||
def assert_flash(self, text): | ||
'''asserts that message exists in flashes''' | ||
for flash_dom in self.find_elements('.flash'): | ||
if flash_dom.text == text: | ||
return | ||
raise AssertionError(f'Flash not found for text "{text}"') | ||
|
||
|
||
@patch('qa327.backend.get_user', return_value=TEST_USER_A) | ||
def test_r2_1(self, *_): | ||
''' | ||
|
@@ -100,7 +70,10 @@ def test_r2_1(self, *_): | |
''' | ||
|
||
# Logs in user to | ||
self.login_test_user() | ||
self.login_test_user( | ||
email=TEST_USER_A.email, | ||
password='Password123!' | ||
) | ||
|
||
# Opens the user profile page / | ||
self.open(base_url) | ||
|
@@ -354,7 +327,7 @@ def test_r2_9(self, *_): | |
assert self.get_current_url() == base_url+'/login' | ||
|
||
|
||
@patch('qa327.backend.get_user', return_value=TEST_USER_B) | ||
@patch('qa327.backend.get_user', return_value=VALID_USER) | ||
def test_r2_10(self, *_): | ||
''' | ||
10) Test Case R2.10 - If the email already exists, show message | ||
|
@@ -398,7 +371,10 @@ def test_r2_11(self, get_user_function, *_): | |
get_user_function.return_value = TEST_USER_A | ||
|
||
# Logs in user with newly registered user | ||
self.login_test_user() | ||
self.login_test_user( | ||
email=TEST_USER_A.email, | ||
password='Password123!' | ||
) | ||
|
||
# Opens the user profile page / | ||
self.open(base_url) | ||
|
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 |
---|---|---|
|
@@ -3,46 +3,21 @@ | |
''' | ||
|
||
from unittest.mock import patch | ||
from seleniumbase import BaseCase | ||
from werkzeug.security import generate_password_hash | ||
|
||
from qa327_test.conftest import base_url | ||
from qa327.models import User | ||
|
||
# Moch a sample user | ||
TEST_USER = User( | ||
email='[email protected]', | ||
name='test_frontend', | ||
password=generate_password_hash('test_frontend'), | ||
balance=140 | ||
) | ||
from qa327_test.frontend.geek_base import GeekBaseCase, TEST_USER | ||
|
||
# Moch some sample tickets | ||
TEST_TICKETS = [ | ||
{'name': 't1', 'price': '100', 'owner': 'god', 'count': 2}, | ||
{'name': 't2', 'price': '90', 'owner': 'geek', 'count': 3}, | ||
] | ||
|
||
|
||
class R3Test(BaseCase): | ||
class R3Test(GeekBaseCase): | ||
''' | ||
Contains test cases specific to R3 | ||
''' | ||
|
||
def login_test_user(self): | ||
'''login our test user''' | ||
self.open(base_url+'/login') | ||
self.input('#email', TEST_USER.email) | ||
self.input('#password', 'test_frontend') | ||
self.click('#btn-submit') | ||
|
||
def assert_flash(self, text): | ||
'''asserts that message exists in flashes''' | ||
for flash_dom in self.find_elements('.flash'): | ||
if flash_dom.text == text: | ||
return | ||
raise AssertionError(f'Flash not found for text "{text}"') | ||
|
||
def test_login_redirects(self, *_): | ||
'''see r3.1''' | ||
self.open(base_url) | ||
|
@@ -124,6 +99,7 @@ def test_update_form(self, *_): | |
self.assert_element('#update-ticket-expiration-date') | ||
|
||
@patch('qa327.backend.get_user', return_value=TEST_USER) | ||
@patch('qa327.backend.sell_ticket', return_value='ticket sold successfully') | ||
def test_sell_posts(self, *_): | ||
'''see r3.9''' | ||
self.login_test_user() | ||
|
@@ -136,6 +112,7 @@ def test_sell_posts(self, *_): | |
self.assert_flash('ticket sold successfully') | ||
|
||
@patch('qa327.backend.get_user', return_value=TEST_USER) | ||
@patch('qa327.backend.buy_ticket', return_value='ticket bought successfully') | ||
def test_buy_posts(self, *_): | ||
'''see r3.10''' | ||
self.login_test_user() | ||
|
@@ -146,6 +123,7 @@ def test_buy_posts(self, *_): | |
self.assert_flash('ticket bought successfully') | ||
|
||
@patch('qa327.backend.get_user', return_value=TEST_USER) | ||
@patch('qa327.backend.update_ticket', return_value='ticket updated successfully') | ||
def test_update_posts(self, *_): | ||
'''see r3.11''' | ||
self.login_test_user() | ||
|
@@ -155,4 +133,4 @@ def test_update_posts(self, *_): | |
self.input('#update-ticket-price', 'dont-care') | ||
self.input('#update-ticket-expiration-date', 'dont-care') | ||
self.click('#update-submit') | ||
self.assert_flash('ticket updated successfully') | ||
self.assert_flash('ticket updated successfully') |
Oops, something went wrong.