Added cron field to database
This commit is contained in:
@@ -8,4 +8,4 @@ def get_token(test_client, email, password):
|
||||
if "token" in json.loads(response.data)["data"]:
|
||||
return json.loads(response.data)["data"]["token"]
|
||||
|
||||
return ""
|
||||
return ""
|
||||
|
@@ -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
|
||||
|
||||
|
||||
@@ -35,7 +36,7 @@ def test_login_user_not_exist(test_client, init_database):
|
||||
"""
|
||||
response = test_client.post('/api/user/login', data=json.dumps(dict(email="notexistinguser@example.com", password="password")), content_type='application/json')
|
||||
assert response.status_code == 500
|
||||
assert b'Unable to login' in response.data
|
||||
assert b'Can\'t find user' in response.data
|
||||
|
||||
|
||||
def test_login_email_missing(test_client, init_database):
|
||||
@@ -407,7 +408,7 @@ def test_set_admin_admin1_logged_in_user_not_exist(test_client, init_database):
|
||||
headers={"Authorization": "Bearer {}".format(get_token(test_client, "admin1@example.com", "admin1"))},
|
||||
content_type='application/json')
|
||||
assert response.status_code == 500
|
||||
assert b'Unable to update user' in response.data
|
||||
assert b'Can\'t find user' in response.data
|
||||
|
||||
|
||||
def test_set_admin_admin1_logged_in_email_missing(test_client, init_database):
|
||||
@@ -466,6 +467,94 @@ def test_set_admin_admin1_logged_in_admin_empty(test_client, init_database):
|
||||
assert b'Field may not be null' in response.data
|
||||
|
||||
|
||||
def test_set_cron_user_not_logged_in(test_client, init_database):
|
||||
"""
|
||||
Test PUT '/api/user/setCron'
|
||||
|
||||
User is not logged in
|
||||
"""
|
||||
response = test_client.put('/api/user/setCron')
|
||||
assert response.status_code == 401
|
||||
assert b'Unauthorized' in response.data
|
||||
|
||||
|
||||
def test_set_cron_user1_logged_in(test_client, init_database):
|
||||
"""
|
||||
Test PUT '/api/user/setCron'
|
||||
|
||||
User1 is logged in
|
||||
"""
|
||||
response = test_client.put('/api/user/setCron', data=json.dumps(dict(cron="* * * * *")),
|
||||
headers={"Authorization": "Bearer {}".format(get_token(test_client, "user1@example.com", "password"))},
|
||||
content_type='application/json')
|
||||
assert response.status_code == 200
|
||||
assert b'Successfully updated users cron' in response.data
|
||||
|
||||
|
||||
def test_set_empty_cron_user1_logged_in(test_client, init_database):
|
||||
"""
|
||||
Test PUT '/api/user/setCron'
|
||||
|
||||
User1 is logged in
|
||||
Interval is empty
|
||||
"""
|
||||
response = test_client.put('/api/user/setCron', data=json.dumps(dict(cron="")),
|
||||
headers={"Authorization": "Bearer {}".format(get_token(test_client, "user1@example.com", "password"))},
|
||||
content_type='application/json')
|
||||
assert response.status_code == 400
|
||||
|
||||
|
||||
def test_set_cron_bot_logged_in_user_exists(test_client, init_database):
|
||||
"""
|
||||
Test PUT '/api/user/setCron'
|
||||
|
||||
Bot1 is logged in and requests user 12345678
|
||||
"""
|
||||
response = test_client.put('/api/user/setCron', data=json.dumps(dict(cron="* * * * *")),
|
||||
headers={"Authorization": "Bearer {}".format(get_token(test_client, "bot1@example.com", "bot1") + ":12345678")},
|
||||
content_type='application/json')
|
||||
assert response.status_code == 200
|
||||
assert b'Successfully updated users cron' in response.data
|
||||
|
||||
|
||||
def test_set_cron_bot_logged_in_user_not_exists(test_client, init_database):
|
||||
"""
|
||||
Test PUT '/api/user/setCron'
|
||||
|
||||
Bot1 is logged in and requests user 1234 (not existing)
|
||||
"""
|
||||
response = test_client.put('/api/user/setCron', data=json.dumps(dict(cron="* * * * *")),
|
||||
headers={"Authorization": "Bearer {}".format(get_token(test_client, "bot1@example.com", "bot1") + ":1234")},
|
||||
content_type='application/json')
|
||||
assert response.status_code == 401
|
||||
assert b'Unable to login' in response.data
|
||||
|
||||
|
||||
def test_set_cron_user1_logged_in_but_no_bot(test_client, init_database):
|
||||
"""
|
||||
Test PUT '/api/user/setCron'
|
||||
|
||||
User1 is logged in and requests user 1234 (not existing)
|
||||
Fails because user1 is not a bot
|
||||
"""
|
||||
response = test_client.put('/api/user/setCron', data=json.dumps(dict(cron="* * * * *")),
|
||||
headers={"Authorization": "Bearer {}".format(get_token(test_client, "user1@example.com", "password") + ":12345678")},
|
||||
content_type='application/json')
|
||||
assert response.status_code == 401
|
||||
assert b'Unable to login' in response.data
|
||||
|
||||
|
||||
def test_set_cron_invalid_token(test_client, init_database):
|
||||
"""
|
||||
Test PUT '/api/user/setCron'
|
||||
|
||||
Invalid Bearer token
|
||||
"""
|
||||
response = test_client.put('/api/user/setCron', headers={"Authorization": "Bearer {}".format("invalidtoken:12345678")})
|
||||
assert response.status_code == 401
|
||||
assert b'Unauthorized' in response.data
|
||||
|
||||
|
||||
def test_get_users_not_logged_in(test_client, init_database):
|
||||
"""
|
||||
Test GET '/api/users'
|
||||
|
Reference in New Issue
Block a user