added tests for token log and registration
This commit is contained in:
parent
3caf17c861
commit
ec1e843f57
|
@ -1,3 +1,5 @@
|
||||||
|
import datetime
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
from flask_security.utils import find_user
|
from flask_security.utils import find_user
|
||||||
|
@ -275,3 +277,62 @@ def test_demote_user(temp_admin, client_authenticated):
|
||||||
assert f"Benutzer {temp_admin['username']} ist bereits kein Admin!"
|
assert f"Benutzer {temp_admin['username']} ist bereits kein Admin!"
|
||||||
assert not user.has_role('admin')
|
assert not user.has_role('admin')
|
||||||
|
|
||||||
|
|
||||||
|
def test_list_tokens(client_authenticated):
|
||||||
|
response = client_authenticated.get(f"/tokens", follow_redirects=True)
|
||||||
|
|
||||||
|
# make sure the names for the test tokens are displayed
|
||||||
|
assert all([user in response.data.decode()
|
||||||
|
for user in ['Gandalf', 'Bilbo', 'Gimli']])
|
||||||
|
|
||||||
|
|
||||||
|
def test_token_log(client_authenticated):
|
||||||
|
response = client_authenticated.get(f"/token-log", follow_redirects=True)
|
||||||
|
|
||||||
|
page_src = response.data.decode()
|
||||||
|
|
||||||
|
# perform some checks for displayed log data
|
||||||
|
assert all([msg in page_src for msg in
|
||||||
|
['INFO', 'DEBUG', 'ERROR']])
|
||||||
|
assert "Valid token 04538cfa186280 of Gandalf" in page_src
|
||||||
|
assert "2021-04-17 13:09:06,207" in page_src
|
||||||
|
|
||||||
|
|
||||||
|
def test_register_token(client_authenticated, mocker):
|
||||||
|
# test to make sure message is displayed when no tokens were recently scanned
|
||||||
|
response = client_authenticated.get(f"/register-token", follow_redirects=True)
|
||||||
|
page_src = response.data.decode()
|
||||||
|
assert 'Keine unregistrierten Tokens in MQTT Nachrichten.' in page_src
|
||||||
|
|
||||||
|
# mockup scanned token
|
||||||
|
mocker.patch('imaginaerraum_door_admin.door_handle.DoorHandle.get_most_recent_token',
|
||||||
|
lambda x: {'timestamp': datetime.datetime.now(),
|
||||||
|
'token': '042979fa181280'})
|
||||||
|
response = client_authenticated.get(f"/register-token", follow_redirects=True)
|
||||||
|
csrf_token = extract_csrf_token(response)
|
||||||
|
page_src = response.data.decode()
|
||||||
|
assert 'Unregistrierter Token gelesen' in page_src
|
||||||
|
assert '042979fa181280' in page_src
|
||||||
|
|
||||||
|
# try registering with incomplete data
|
||||||
|
response = client_authenticated.post(f"/register-token", data={},
|
||||||
|
follow_redirects=True)
|
||||||
|
page_src = response.data.decode()
|
||||||
|
assert 'Token konnte nicht registiert werden' in page_src
|
||||||
|
|
||||||
|
# register the mocked token
|
||||||
|
payload = {'name': 'Legolas',
|
||||||
|
'organization': 'Elves',
|
||||||
|
'email': 'legolas@mirkwood.me',
|
||||||
|
'dsgvo': True,
|
||||||
|
'csrf_token': csrf_token}
|
||||||
|
response = client_authenticated.post(f"/register-token", data=payload,
|
||||||
|
follow_redirects=True)
|
||||||
|
page_src = response.data.decode()
|
||||||
|
|
||||||
|
# make sure the user info for the new token is displayed
|
||||||
|
assert '042979fa181280' in page_src
|
||||||
|
assert 'Legolas' in page_src
|
||||||
|
assert 'Elves' in page_src
|
||||||
|
assert 'legolas@mirkwood.me' in page_src
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user