2022-03-15 18:57:54 +00:00
|
|
|
import pytest
|
2022-03-15 10:17:05 +00:00
|
|
|
from flask.testing import FlaskClient
|
2022-03-15 18:57:54 +00:00
|
|
|
from flask_wtf.csrf import generate_csrf
|
2022-03-15 10:17:05 +00:00
|
|
|
|
|
|
|
from ereuse_devicehub.client import UserClient
|
|
|
|
from ereuse_devicehub.devicehub import Devicehub
|
2022-03-15 18:57:54 +00:00
|
|
|
from tests import conftest
|
2022-03-15 10:17:05 +00:00
|
|
|
|
|
|
|
|
2022-03-15 18:57:54 +00:00
|
|
|
@pytest.mark.mvp
|
2022-03-15 10:17:05 +00:00
|
|
|
# @pytest.mark.usefixtures()
|
2022-03-15 18:57:54 +00:00
|
|
|
@pytest.mark.usefixtures(conftest.app_context.__name__)
|
2022-03-15 10:17:05 +00:00
|
|
|
def test_login(user: UserClient, app: Devicehub):
|
|
|
|
"""Checks a simple login"""
|
|
|
|
|
2022-03-15 18:57:54 +00:00
|
|
|
client = FlaskClient(app, use_cookies=True)
|
|
|
|
|
2022-03-15 10:17:05 +00:00
|
|
|
body, status, headers = client.get('/login/')
|
|
|
|
body = next(body).decode("utf-8")
|
|
|
|
assert status == '200 OK'
|
|
|
|
assert "Login to Your Account" in body
|
|
|
|
|
2022-03-15 18:57:54 +00:00
|
|
|
data = {
|
|
|
|
'email': user.email,
|
|
|
|
'password': 'foo',
|
|
|
|
'remember': False,
|
|
|
|
'csrf_token': generate_csrf(),
|
|
|
|
}
|
|
|
|
body, status, headers = client.post('/login/', data=data, follow_redirects=True)
|
2022-03-15 10:17:05 +00:00
|
|
|
|
|
|
|
body = next(body).decode("utf-8")
|
|
|
|
assert status == '200 OK'
|
|
|
|
assert "Login to Your Account" not in body
|
2022-03-15 18:57:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.mvp
|
|
|
|
@pytest.mark.usefixtures(conftest.app_context.__name__)
|
|
|
|
def test_inventory(user: UserClient, app: Devicehub):
|
|
|
|
client = FlaskClient(app, use_cookies=True)
|
|
|
|
client.get('/login/')
|
|
|
|
data = {
|
|
|
|
'email': user.email,
|
|
|
|
'password': 'foo',
|
|
|
|
'remember': False,
|
|
|
|
'csrf_token': generate_csrf(),
|
|
|
|
}
|
|
|
|
body, status, headers = client.post('/login/', data=data, follow_redirects=True)
|
|
|
|
body, status, headers = client.get('/inventory/device/', headers=headers)
|
|
|
|
|
|
|
|
body = next(body).decode("utf-8")
|
|
|
|
assert status == '200 OK'
|
|
|
|
# import pdb; pdb.set_trace()
|
|
|
|
assert "Unassgined" in body
|