Skip to content

Commit

Permalink
R5 tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Kymed committed Dec 13, 2020
1 parent b6608e2 commit 2a804d4
Show file tree
Hide file tree
Showing 4 changed files with 282 additions and 32 deletions.
28 changes: 0 additions & 28 deletions Test Requirements/tests-amy.md
Original file line number Diff line number Diff line change
Expand Up @@ -244,31 +244,3 @@ Actions:
- click element input[type="submit"]
- check that the ticket is not added, and that the user is redirected to / with the correct message

### Test case 6001 - R5.6 - Check that the ticket id exists
Assumptions:
- ticket1 = ticket id that exists in the database
- ticket2 = ticket id that doesn't exist in the database

Mocking:
- mock backend.get_user to return a test_user instance
- mock backend.create_ticket to return True

Actions:
- open /logout (to invalidate any logged-in sessions that may exist)
- open /login
- enter test_user's email into element #email
- enter test_user's password into element #password
- click element input[type="submit"]
- open /
- enter " test_ticket_name " into #name for ticket1
- enter 5 into #quantity
- enter 15 into #price
- enter (today's date + 1 day) to #date
- click element input[type="submit"]
- check that the ticket is added, and that the user is redirected to /
- enter " test_ticket_name " into #name for ticket2
- enter 5 into #quantity
- enter 15 into #price
- enter (today's date + 1 day) to #date
- click element input[type="submit"]
- check that the ticket is not added, and that the user is redirected to / with the correct message
2 changes: 1 addition & 1 deletion qa327/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ <h2>Edit ticket</h2>
Price: <input id="update_price" type="number" name="price"/><br/>
Expiration Date (YYYMMDD): <input id="update_exp_date" type="text" name="date"/><br/>
<input type="hidden" value="{{ user.email }}" name="user"/>
<input type="submit" value="Save"/>
<input id="update_submit" type="submit" value="Save"/>
</form>

{% endblock %}
43 changes: 41 additions & 2 deletions qa327_test/frontend/sell/test_frontend_sell.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@
nextdayobj = datetime.now() + timedelta(days=1)
nextday = nextdayobj.strftime('%Y%m%d')

yesterdayobj = datetime.now() - timedelta(days=1)
yesterday = yesterdayobj.strftime('%Y%m%d')

class FrontEndSellTest(BaseCase):

@patch('qa327.backend.get_user', return_value=test_user)
Expand Down Expand Up @@ -170,7 +173,7 @@ def test_ticket_dateformat(self, *_):
self.click('input[type="submit"]')
self.open(base_url)

# test quantity too many
# test invalid date format
self.type("#sell_name", "name")
self.type("#sell_quantity", "5")
self.type("#sell_price", "15")
Expand All @@ -179,7 +182,43 @@ def test_ticket_dateformat(self, *_):
self.assert_element("#message")
self.assert_text("Ticket date is invalid.", "#message")


# test invalid date
self.type("#sell_name", "name")
self.type("#sell_quantity", "5")
self.type("#sell_price", "15")
self.type("#sell_exp_date", yesterday)
self.click('#sell_submit')
self.assert_element("#message")
self.assert_text("Ticket date is invalid.", "#message")

@patch('qa327.backend.get_user', return_value=test_user)
def test_ticket_price(self, *_):
# log in user
self.open(base_url + '/logout')
self.open(base_url + '/login')
self.type("#email", "test_frontend@test.com")
self.type("#password", "test_Frontend0!")
self.click('input[type="submit"]')
self.open(base_url)

# test price too little
self.type("#sell_name", "testticket")
self.type("#sell_quantity", "5")
self.type("#sell_price", "-1")
self.type("#sell_exp_date", nextday)
self.click('#sell_submit')
self.assert_element("#message")
self.assert_text("Ticket price is invalid.", "#message")

# test price too large
self.type("#sell_name", "testticket")
self.type("#sell_quantity", "5")
self.type("#sell_price", "125")
self.type("#sell_exp_date", nextday)
self.click('#sell_submit')
self.assert_element("#message")
self.assert_text("Ticket price is invalid.", "#message")




Expand Down
241 changes: 240 additions & 1 deletion qa327_test/frontend/update/test_frontend_update.py
Original file line number Diff line number Diff line change
@@ -1 +1,240 @@
# All tests for R5 - update go here
# All tests for R5 - update go here

import pytest
from seleniumbase import BaseCase
from datetime import datetime, timedelta

from qa327_test.conftest import base_url
from unittest.mock import patch
from qa327.models import db, User, Ticket
from werkzeug.security import generate_password_hash, check_password_hash

"""
File contains all unit tests for R5 Update
Frontend
"""

# Mock a sample ticket
test_ticket = Ticket(
id=5,
user=10,
name="Test Ticket",
price=5,
quantity=1
)

# Mock tickets
test_tickets = [
{
'id': 3,
'user': 10,
'name': 'Test Ticket 1',
'price': 5,
'quantity': 2
},
{
'id': 4,
'user': 10,
'name': 'Test Ticket 2',
'price': 10,
'quantity': 1
},
]

# Mock Users
test_user = User(
email='test_frontend@test.com',
name='test_frontend',
password=generate_password_hash('test_Frontend0!')
)

nextdayobj = datetime.now() + timedelta(days=1)
nextday = nextdayobj.strftime('%Y%m%d')

yesterdayobj = datetime.now() - timedelta(days=1)
yesterday = yesterdayobj.strftime('%Y%m%d')

@pytest.mark.focus
class FrontEndUpdateTest(BaseCase):

@patch('qa327.backend.get_user', return_value=test_user)
def test_ticketexists_alphanum_update(self, *_):
# log in user
self.open(base_url + '/logout')
self.open(base_url + '/login')
self.type("#email", "test_frontend@test.com")
self.type("#password", "test_Frontend0!")
self.click('input[type="submit"]')
self.open(base_url)

# create a ticket
self.type("#sell_name", "testticket")
self.type("#sell_quantity", "5")
self.type("#sell_price", "15")
self.type("#sell_exp_date", nextday)
self.click('#sell_submit')

# make sure ticket is on home page
self.assert_element("#ticket-testticket")

# update the ticket incorrectly
self.type("#update_name", "te^%&^**%st_ticket_name")
self.type("#update_quantity", "5")
self.type("#update_price", "15")
self.type("#update_exp_date", nextday)
self.click('#update_submit')
self.assert_element("#message")
self.assert_text("Ticket name is invalid.", "#message")

@patch('qa327.backend.get_user', return_value=test_user)
def test_ticket_update_namelength(self, *_):
# log in user
self.open(base_url + '/logout')
self.open(base_url + '/login')
self.type("#email", "test_frontend@test.com")
self.type("#password", "test_Frontend0!")
self.click('input[type="submit"]')
self.open(base_url)

# create a ticket
self.type("#sell_name", "testticket")
self.type("#sell_quantity", "5")
self.type("#sell_price", "15")
self.type("#sell_exp_date", nextday)
self.click('#sell_submit')

# make sure ticket is on home page
self.assert_element("#ticket-testticket")

# update ticket name too short
self.type("#update_name", "name")
self.type("#update_quantity", "5")
self.type("#update_price", "15")
self.type("#update_exp_date", nextday)
self.click('#update_submit')
self.assert_element("#message")
self.assert_text("Ticket name is invalid.", "#message")

# update ticket name too long
self.type("#update_name", "super_duper_unnecessarily_long_ticket_name4692387346912673498712648761984376218463")
self.type("#update_quantity", "5")
self.type("#update_price", "15")
self.type("#update_exp_date", nextday)
self.click('#update_submit')
self.assert_element("#message")
self.assert_text("Ticket name is invalid.", "#message")

@patch('qa327.backend.get_user', return_value=test_user)
def test_ticket_update_quantity(self, *_):
# log in user
self.open(base_url + '/logout')
self.open(base_url + '/login')
self.type("#email", "test_frontend@test.com")
self.type("#password", "test_Frontend0!")
self.click('input[type="submit"]')
self.open(base_url)

# create a ticket
self.type("#sell_name", "testticket")
self.type("#sell_quantity", "5")
self.type("#sell_price", "15")
self.type("#sell_exp_date", nextday)
self.click('#sell_submit')

# make sure ticket is on home page
self.assert_element("#ticket-testticket")

# test quantity too many
self.type("#update_name", "name")
self.type("#update_quantity", "125")
self.type("#update_price", "15")
self.type("#update_exp_date", nextday)
self.click('#update_submit')
self.assert_element("#message")
self.assert_text("Ticket quantity must be between 0 and 100.", "#message")

# test quantity too little
self.type("#update_name", "name")
self.type("#update_quantity", "0")
self.type("#update_price", "15")
self.type("#update_exp_date", nextday)
self.click('#update_submit')
self.assert_element("#message")
self.assert_text("Ticket quantity must be between 0 and 100.", "#message")

@patch('qa327.backend.get_user', return_value=test_user)
def test_ticket_update_price(self, *_):
# log in user
self.open(base_url + '/logout')
self.open(base_url + '/login')
self.type("#email", "test_frontend@test.com")
self.type("#password", "test_Frontend0!")
self.click('input[type="submit"]')
self.open(base_url)

# create a ticket
self.type("#sell_name", "testticket")
self.type("#sell_quantity", "5")
self.type("#sell_price", "15")
self.type("#sell_exp_date", nextday)
self.click('#sell_submit')

# make sure ticket is on home page
self.assert_element("#ticket-testticket")

# test price too little
self.type("#update_name", "name")
self.type("#update_quantity", "5")
self.type("#update_price", "-1")
self.type("#update_exp_date", nextday)
self.click('#update_submit')
self.assert_element("#message")
self.assert_text("Ticket price is invalid.", "#message")

# test price too large
self.type("#update_name", "name")
self.type("#update_quantity", "5")
self.type("#update_price", "125")
self.type("#update_exp_date", nextday)
self.click('#update_submit')
self.assert_element("#message")
self.assert_text("Ticket price is invalid.", "#message")

@patch('qa327.backend.get_user', return_value=test_user)
def test_ticket_update_date(self, *_):
# log in user
self.open(base_url + '/logout')
self.open(base_url + '/login')
self.type("#email", "test_frontend@test.com")
self.type("#password", "test_Frontend0!")
self.click('input[type="submit"]')
self.open(base_url)

# create a ticket
self.type("#sell_name", "testticket")
self.type("#sell_quantity", "5")
self.type("#sell_price", "15")
self.type("#sell_exp_date", nextday)
self.click('#sell_submit')

# make sure ticket is on home page
self.assert_element("#ticket-testticket")

# test invalid date format
self.type("#update_name", "testticket")
self.type("#update_quantity", "5")
self.type("#update_price", "15")
self.type("#update_exp_date", "1")
self.click('#update_submit')
self.assert_element("#message")
self.assert_text("Ticket data is invalid.", "#message")

# test invalid date
self.type("#update_name", "testticket")
self.type("#update_quantity", "5")
self.type("#update_price", "15")
self.type("#update_exp_date", yesterday)
self.click('#update_submit')
self.assert_element("#message")
self.assert_text("Ticket data is invalid.", "#message")

0 comments on commit 2a804d4

Please sign in to comment.