Refactoring

This commit is contained in:
2022-03-30 11:10:48 +02:00
parent 4b7dfa8afd
commit 1f2487f1c1
10 changed files with 17 additions and 113 deletions

View File

@@ -0,0 +1,11 @@
import json
def get_token(test_client, email, password):
response = test_client.post('/api/user/login', data=json.dumps(dict(email=email, password=password)), content_type='application/json')
if "data" in json.loads(response.data):
if "token" in json.loads(response.data)["data"]:
return json.loads(response.data)["data"]["token"]
return ""

View File

@@ -2,6 +2,7 @@
This file (test_keyword.py) contains the functional tests for the `keyword` blueprint.
"""
import json
from tests.functional.helper_functions import get_token
def test_add_keyword_not_logged_in(test_client, init_database):
@@ -179,13 +180,3 @@ def test_delete_keyword_user1_logged_in_keyword_not_exists(test_client, init_dat
content_type='application/json')
assert response.status_code == 500
assert b'Keyword doesn\'t exist for this user' in response.data
def get_token(test_client, email, password):
response = test_client.post('/api/user/login', data=json.dumps(dict(email=email, password=password)), content_type='application/json')
if "data" in json.loads(response.data):
if "token" in json.loads(response.data)["data"]:
return json.loads(response.data)["data"]["token"]
return ""

View File

@@ -2,6 +2,7 @@
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):
@@ -47,13 +48,3 @@ def test_get_portfolio_user1_logged_in_response_data(test_client, init_database)
assert response.status_code == 200
assert b'"data":[]' not in response.data
assert b'"data":[' in response.data
def get_token(test_client, email, password):
response = test_client.post('/api/user/login', data=json.dumps(dict(email=email, password=password)), content_type='application/json')
if "data" in json.loads(response.data):
if "token" in json.loads(response.data)["data"]:
return json.loads(response.data)["data"]["token"]
return ""

View File

@@ -2,6 +2,7 @@
This file (test_share.py) contains the functional tests for the `share` blueprint.
"""
import json
from tests.functional.helper_functions import get_token
def test_add_share_not_logged_in(test_client, init_database):
@@ -179,13 +180,3 @@ def test_delete_share_user1_logged_in_symbol_not_exists(test_client, init_databa
content_type='application/json')
assert response.status_code == 500
assert b'Symbol doesn\'t exist for this user' in response.data
def get_token(test_client, email, password):
response = test_client.post('/api/user/login', data=json.dumps(dict(email=email, password=password)), content_type='application/json')
if "data" in json.loads(response.data):
if "token" in json.loads(response.data)["data"]:
return json.loads(response.data)["data"]["token"]
return ""

View File

@@ -2,6 +2,7 @@
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):
@@ -54,13 +55,3 @@ def test_add_telegram_user1_logged_in_user_data_empty(test_client, init_database
content_type='application/json')
assert response.status_code == 400
assert b'missing' in response.data
def get_token(test_client, email, password):
response = test_client.post('/api/user/login', data=json.dumps(dict(email=email, password=password)), content_type='application/json')
if "data" in json.loads(response.data):
if "token" in json.loads(response.data)["data"]:
return json.loads(response.data)["data"]["token"]
return ""

View File

@@ -2,6 +2,7 @@
This file (test_transaction.py) contains the functional tests for the `transaction` blueprint.
"""
import json
from tests.functional.helper_functions import get_token
def test_add_transaction_not_logged_in(test_client, init_database):
@@ -91,13 +92,3 @@ def test_get_transaction_user1_logged_in_response_data(test_client, init_databas
content_type='application/json')
assert response.status_code == 200
assert b'Successfully loaded transactions' in response.data
def get_token(test_client, email, password):
response = test_client.post('/api/user/login', data=json.dumps(dict(email=email, password=password)), content_type='application/json')
if "data" in json.loads(response.data):
if "token" in json.loads(response.data)["data"]:
return json.loads(response.data)["data"]["token"]
return ""

View File

@@ -2,6 +2,7 @@
This file (test_user.py) contains the functional tests for the `users` blueprint.
"""
import json
from tests.functional.helper_functions import get_token
def test_login_with_valid_data(test_client, init_database):
@@ -501,13 +502,3 @@ def test_get_users_admin1_logged_in(test_client, init_database):
content_type='application/json')
assert response.status_code == 200
assert b'Successfully received all users' in response.data
def get_token(test_client, email, password):
response = test_client.post('/api/user/login', data=json.dumps(dict(email=email, password=password)), content_type='application/json')
if "data" in json.loads(response.data):
if "token" in json.loads(response.data)["data"]:
return json.loads(response.data)["data"]["token"]
return ""