示例#1
0
 def test_sell_ticket_duplicate_name(self):
     """
     Duplicate name | user=<user in DB> name="Not Unique" quantity=1 price=10.00 expiryDate=date(2030, 1, 1) | Error: "A ticket with that name already exists."
     """
     # The most straightforward way to have a ticket with a duplicate name
     # is to just insert the same ticket into the DB twice.
     # Prepare DB
     new_user = User()
     new_user.name = TEST_USER.name
     new_user.email = TEST_USER.email
     new_user.password = TEST_USER.password
     new_user.balance = TEST_USER.balance
     db.session.add(new_user)
     db.session.commit()
     # Set up parameters
     user = new_user
     name = "Not Unique"
     quantity = 1
     price = 10.00
     expiryDate = date(2030, 1, 1)
     # Call function
     ret_value = sell_ticket(user, name, quantity, price, expiryDate)
     # Check return value
     assert ret_value == False
     # Call function
     ret_value = sell_ticket(user, name, quantity, price, expiryDate)
     # Check return value
     assert ret_value == "A ticket with that name already exists."
示例#2
0
 def test_sell_ticket_user_not_in_db(self):
     """
     User object that doesn't exist in database | user=<user not in DB> name="Unique" quantity=1 price=10.00 expiryDate=date(2030, 1, 1) | Internal Error: user does not exist in database
     """
     # Prepare DB
     new_user = User()
     new_user.name = TEST_USER.name
     new_user.email = TEST_USER.email
     new_user.password = TEST_USER.password
     new_user.balance = TEST_USER.balance
     # Skip adding new_user to DB
     # Set up parameters
     user = new_user
     name = "Unique"
     quantity = 1
     price = 10.00
     expiryDate = date(2030, 1, 1)
     # Call function
     ret_value = sell_ticket(user, name, quantity, price, expiryDate)
     # Check return value
     assert ret_value == "Internal Error: user does not exist in database"
示例#3
0
 def test_sell_ticket_user_bad_type(self):
     """
     Non-User type user parameter | user=None name="Unique" quantity=1 price=10.00 expiryDate=date(2030, 1, 1) | Internal Error: 'user' must be of type 'User'
     """
     # Prepare DB
     new_user = User()
     new_user.name = TEST_USER.name
     new_user.email = TEST_USER.email
     new_user.password = TEST_USER.password
     new_user.balance = TEST_USER.balance
     db.session.add(new_user)
     db.session.commit()
     # Set up parameters
     user = None
     name = "Unique"
     quantity = 1
     price = 10.00
     expiryDate = date(2030, 1, 1)
     # Call function
     ret_value = sell_ticket(user, name, quantity, price, expiryDate)
     # Check return value
     assert ret_value == "Internal Error: 'user' must be of type 'User'"
示例#4
0
 def test_sell_ticket_valid_with_fraction(self):
     """
     All inputs valid, price with fractional part | user=<user in DB> name="Unique" quantity=1 price=12.34 expiryDate=date(2030, 1, 1) | No error
     """
     # Prepare DB
     new_user = User()
     new_user.name = TEST_USER.name
     new_user.email = TEST_USER.email
     new_user.password = TEST_USER.password
     new_user.balance = TEST_USER.balance
     db.session.add(new_user)
     db.session.commit()
     # Set up parameters
     user = new_user
     name = "Unique"
     quantity = 1
     price = 12.34
     expiryDate = date(2030, 1, 1)
     # Call function
     ret_value = sell_ticket(user, name, quantity, price, expiryDate)
     # Check return value
     assert ret_value == False
示例#5
0
 def test_sell_ticket_expiryDate_bad_type(self):
     """
     Non-date type expiryDate parameter | user=<user in DB> name="Unique" quantity=1 price=10.00 expiryDate=None | Internal Error: 'expiryDate' must be of type 'date'
     """
     # Prepare DB
     new_user = User()
     new_user.name = TEST_USER.name
     new_user.email = TEST_USER.email
     new_user.password = TEST_USER.password
     new_user.balance = TEST_USER.balance
     db.session.add(new_user)
     db.session.commit()
     # Set up parameters
     user = new_user
     name = "Unique"
     quantity = 1
     price = 10.00
     expiryDate = None
     # Call function
     ret_value = sell_ticket(user, name, quantity, price, expiryDate)
     # Check return value
     assert ret_value == "Internal Error: 'expiryDate' must be of type 'date'"
示例#6
0
qa327_test/common.py:
A shared space for any common testing code/data.
"""
from datetime import date
from unittest.mock import patch
from werkzeug.security import generate_password_hash

from qa327_test.conftest import base_url
from qa327.models import User, Ticket

# Mock a sample user
TEST_USER = User(email='*****@*****.**',
                 name='Test Frontend',
                 balance=2000)
TEST_USER.raw_password = '******'
TEST_USER.password = generate_password_hash(TEST_USER.raw_password)

# Mock a sample ticket
TEST_TICKET = Ticket(
    name="t1",
    quantity=90,
    price=100,
    expiry=date(2030, 1, 1),
    owner_id="test_owener_id",
    owner=TEST_USER,
)
TEST_TICKET.raw_expiry = "20301001"


def auto_login(user):
    """