64 lines
2.2 KiB
Python
64 lines
2.2 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_telegram.py) contains the functional tests for the `telegram` blueprint.
|
|
"""
|
|
import json
|
|
from tests.functional.helper_functions import get_token
|
|
|
|
|
|
def test_add_telegram_not_logged_in(test_client, init_database):
|
|
"""
|
|
Test POST '/api/telegram'
|
|
|
|
User is not logged in
|
|
"""
|
|
response = test_client.post('/api/telegram')
|
|
assert response.status_code == 401
|
|
assert b'Unauthorized' in response.data
|
|
|
|
|
|
def test_add_telegram_user1_logged_in(test_client, init_database):
|
|
"""
|
|
Test POST '/api/telegram'
|
|
|
|
User1 is logged in
|
|
"""
|
|
response = test_client.post('/api/telegram', data=json.dumps(dict(telegram_user_id="12345678")),
|
|
headers={"Authorization": "Bearer {}".format(get_token(test_client, "user1@example.com", "password"))},
|
|
content_type='application/json')
|
|
assert response.status_code == 200
|
|
assert b'Successfully connected telegram user' in response.data
|
|
|
|
|
|
def test_add_telegram_user1_logged_in_user_data_missing(test_client, init_database):
|
|
"""
|
|
Test POST '/api/telegram'
|
|
|
|
User1 is logged in
|
|
telegram_user_id is missing
|
|
"""
|
|
response = test_client.post('/api/telegram', data=json.dumps(dict()),
|
|
headers={"Authorization": "Bearer {}".format(get_token(test_client, "user1@example.com", "password"))},
|
|
content_type='application/json')
|
|
assert response.status_code == 400
|
|
assert b'missing' in response.data
|
|
|
|
|
|
def test_add_telegram_user1_logged_in_user_data_empty(test_client, init_database):
|
|
"""
|
|
Test POST '/api/telegram'
|
|
|
|
User1 is logged in
|
|
telegram_user_id is empty
|
|
"""
|
|
response = test_client.post('/api/telegram', data=json.dumps(dict(telegram_user_id="")),
|
|
headers={"Authorization": "Bearer {}".format(get_token(test_client, "user1@example.com", "password"))},
|
|
content_type='application/json')
|
|
assert response.status_code == 400
|
|
assert b'missing' in response.data
|