TelegramAktienBot/api/tests/functional/test_portfolio.py
2022-04-12 09:50:24 +02:00

57 lines
2.1 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_portfolio.py) contains the functional tests for the `portfolio` blueprint.
"""
import json
from tests.functional.helper_functions import get_token
def test_get_portfolio_not_logged_in_empty_response(test_client, init_database):
"""
Test GET '/api/portfolio'
User is not logged in
"""
response = test_client.get('/api/portfolio')
assert response.status_code == 401
assert b'Unauthorized' in response.data
def test_get_portfolio_user1_logged_in_empty_response(test_client, init_database):
"""
Test GET '/api/portfolio'
User1 is logged in
Empty response
"""
response = test_client.get('/api/portfolio',
headers={"Authorization": "Bearer {}".format(get_token(test_client, "user1@example.com", "password"))},
content_type='application/json')
assert response.status_code == 200
assert b'"data":[]' in response.data
assert b'Successfully loaded symbols' in response.data
def test_get_portfolio_user1_logged_in_response_data(test_client, init_database):
"""
Test GET '/api/portfolio'
User1 is logged in
Create transaction data
"""
test_client.post('/api/transaction', data=json.dumps(dict(count=5, price=9.99, symbol="DTEGY", time="2022-03-29T10:00:00.000Z")),
headers={"Authorization": "Bearer {}".format(get_token(test_client, "user1@example.com", "password"))},
content_type='application/json')
response = test_client.get('/api/portfolio',
headers={"Authorization": "Bearer {}".format(get_token(test_client, "user1@example.com", "password"))},
content_type='application/json')
assert response.status_code == 200
assert b'"data":[]' not in response.data
assert b'"data":[' in response.data