123 lines
3.8 KiB
Python
123 lines
3.8 KiB
Python
__author__ = "Florian Kaiser"
|
|
__copyright__ = "Copyright 2022, Project Aktienbot"
|
|
__credits__ = ["Florian Kaiser", "Florian Kellermann", "Linus Eickhof", "Kevin Pauer"]
|
|
__license__ = "GPL 3.0"
|
|
__version__ = "1.0.0"
|
|
|
|
"""
|
|
This file (test_models.py) contains the unit tests for the models.py file.
|
|
"""
|
|
from app.helper_functions import hash_password
|
|
from app.models import User, Transaction, Keyword, Share
|
|
|
|
|
|
def test_new_user():
|
|
"""
|
|
GIVEN a User model
|
|
WHEN a new User is created
|
|
THEN check the email, password, username, telegram_user_id and admin fields are defined correctly
|
|
"""
|
|
user = User(
|
|
email="user@example.com",
|
|
username="user",
|
|
password=hash_password("password"),
|
|
admin=False,
|
|
cron="0 8 * * *",
|
|
)
|
|
assert user.email == 'user@example.com'
|
|
assert user.password != 'password'
|
|
assert user.username == "user"
|
|
assert user.telegram_user_id is None
|
|
assert user.admin is False
|
|
assert user.as_dict() == {'cron': '0 8 * * *', 'email': 'user@example.com', 'username': 'user', 'telegram_user_id': None, 'admin': False}
|
|
|
|
|
|
def test_new_user_with_fixture(new_user):
|
|
"""
|
|
GIVEN a User model
|
|
WHEN a new User is created
|
|
THEN check the email and password_hashed fields are defined correctly
|
|
"""
|
|
assert new_user.email == 'user@example.com'
|
|
assert new_user.password != 'password'
|
|
|
|
|
|
def test_new_transaction():
|
|
"""
|
|
GIVEN a Transaction model
|
|
WHEN a new Transaction is created
|
|
THEN check the email, symbol, time count and price fields are defined correctly
|
|
"""
|
|
transaction = Transaction(
|
|
email="user@example.com",
|
|
symbol="DTEGY",
|
|
time="2022-03-29T10:00:00.000Z",
|
|
count=10,
|
|
price=9.99
|
|
)
|
|
assert transaction.email == 'user@example.com'
|
|
assert transaction.symbol == "DTEGY"
|
|
assert transaction.count == 10
|
|
assert transaction.price == 9.99
|
|
assert transaction.as_dict() == {'t_id': None, 'email': 'user@example.com', 'symbol': 'DTEGY', 'time': '2022-03-29T10:00:00.000Z', 'count': 10, 'price': 9.99}
|
|
|
|
|
|
def test_new_transaction_with_fixture(new_transaction):
|
|
"""
|
|
GIVEN a User model
|
|
WHEN a new User is created
|
|
THEN check the email and password_hashed fields are defined correctly
|
|
"""
|
|
assert new_transaction.email == 'user@example.com'
|
|
assert new_transaction.symbol == 'DTEGY'
|
|
|
|
|
|
def test_new_keyword():
|
|
"""
|
|
GIVEN a Transaction model
|
|
WHEN a new Transaction is created
|
|
THEN check the email, symbol, time count and price fields are defined correctly
|
|
"""
|
|
keyword = Keyword(
|
|
email="user@example.com",
|
|
keyword="Elon Musk"
|
|
)
|
|
assert keyword.email == 'user@example.com'
|
|
assert keyword.keyword == "Elon Musk"
|
|
assert keyword.as_dict() == {'s_id': None, 'email': 'user@example.com', 'keyword': 'Elon Musk'}
|
|
|
|
|
|
def test_new_keyword_with_fixture(new_keyword):
|
|
"""
|
|
GIVEN a User model
|
|
WHEN a new User is created
|
|
THEN check the email and password_hashed fields are defined correctly
|
|
"""
|
|
assert new_keyword.email == 'user@example.com'
|
|
assert new_keyword.keyword == 'Elon Musk'
|
|
|
|
|
|
def test_new_share():
|
|
"""
|
|
GIVEN a Transaction model
|
|
WHEN a new Transaction is created
|
|
THEN check the email, symbol, time count and price fields are defined correctly
|
|
"""
|
|
share = Share(
|
|
email="user@example.com",
|
|
symbol="DTEGY"
|
|
)
|
|
assert share.email == 'user@example.com'
|
|
assert share.symbol == "DTEGY"
|
|
assert share.as_dict() == {'a_id': None, 'email': 'user@example.com', 'symbol': 'DTEGY'}
|
|
|
|
|
|
def test_new_share_with_fixture(new_share):
|
|
"""
|
|
GIVEN a User model
|
|
WHEN a new User is created
|
|
THEN check the email and password_hashed fields are defined correctly
|
|
"""
|
|
assert new_share.email == 'user@example.com'
|
|
assert new_share.symbol == 'DTEGY'
|