diff --git a/Test Requirements/tests-amy.md b/Test Requirements/tests-amy.md index 911ab10..4929621 100644 --- a/Test Requirements/tests-amy.md +++ b/Test Requirements/tests-amy.md @@ -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 diff --git a/qa327/templates/index.html b/qa327/templates/index.html index 2cb16b1..51bb0d0 100644 --- a/qa327/templates/index.html +++ b/qa327/templates/index.html @@ -86,7 +86,7 @@

Edit ticket

Price:
Expiration Date (YYYMMDD):
- + {% endblock %} diff --git a/qa327_test/frontend/sell/test_frontend_sell.py b/qa327_test/frontend/sell/test_frontend_sell.py index 9d30d03..10399ec 100644 --- a/qa327_test/frontend/sell/test_frontend_sell.py +++ b/qa327_test/frontend/sell/test_frontend_sell.py @@ -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) @@ -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") @@ -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") + diff --git a/qa327_test/frontend/update/test_frontend_update.py b/qa327_test/frontend/update/test_frontend_update.py index f97be78..abccba3 100644 --- a/qa327_test/frontend/update/test_frontend_update.py +++ b/qa327_test/frontend/update/test_frontend_update.py @@ -1 +1,240 @@ -# All tests for R5 - update go here \ No newline at end of file +# 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") \ No newline at end of file