add tests

This commit is contained in:
Cayo Puigdefabregas 2022-10-20 15:59:17 +02:00
parent 469ce1c6e0
commit 61bd4e0642
3 changed files with 34 additions and 1 deletions

View file

@ -21,6 +21,7 @@ from ereuse_devicehub.db import db
from ereuse_devicehub.devicehub import Devicehub
from ereuse_devicehub.inventory.views import devices
from ereuse_devicehub.labels.views import labels
from ereuse_devicehub.mail.flask_mail import Mail
from ereuse_devicehub.resources.agent.models import Person
from ereuse_devicehub.resources.enums import SessionType
from ereuse_devicehub.resources.tag import Tag
@ -46,6 +47,7 @@ class TestConfig(DevicehubConfig):
EMAIL_ADMIN = 'foo@foo.com'
PATH_DOCUMENTS_STORAGE = '/tmp/trade_documents'
JWT_PASS = config('JWT_PASS', '')
MAIL_SUPPRESS_SEND = True
@pytest.fixture(scope='session')
@ -66,6 +68,8 @@ def _app(config: TestConfig) -> Devicehub:
app.config["SQLALCHEMY_RECORD_QUERIES"] = True
app.config['PROFILE'] = True
# app.wsgi_app = ProfilerMiddleware(app.wsgi_app, restrictions=[30])
mail = Mail(app)
app.mail = mail
return app

View file

@ -106,6 +106,8 @@ def test_api_docs(client: Client):
'/versions/',
'/workbench/',
'/workbench/erasure_host/{id}/',
'/new_register/',
'/validate_user/{token}',
}
assert docs['info'] == {'title': 'Devicehub', 'version': '0.2'}
assert docs['components']['securitySchemes']['bearerAuth'] == {

View file

@ -15,7 +15,7 @@ from ereuse_devicehub.devicehub import Devicehub
from ereuse_devicehub.resources.action.models import Snapshot
from ereuse_devicehub.resources.device.models import Device, Placeholder
from ereuse_devicehub.resources.lot.models import Lot
from ereuse_devicehub.resources.user.models import User
from ereuse_devicehub.resources.user.models import User, UserValidation
from tests import conftest
@ -2578,3 +2578,30 @@ def test_snapshot_is_server_erase(user3: UserClientFlask):
assert snapshot2.is_server_erase
assert snapshot in snapshot.device.actions
assert snapshot2 in snapshot.device.actions
@pytest.mark.mvp
@pytest.mark.usefixtures(conftest.app_context.__name__)
def test_new_register(user3: UserClientFlask, app: Devicehub):
uri = '/new_register/'
user3.get(uri)
data = {
'csrf_token': generate_csrf(),
'email': "foo@bar.cxm",
'password': "1234",
'password2': "1234",
'name': "booBar",
'telephone': "555555555",
}
body, status = user3.post(uri, data=data)
assert status == '200 OK'
assert "Please check your email." in body
user_valid = UserValidation.query.one()
assert user_valid.user.active is False
uri = '/validate_user/' + str(user_valid.token)
body, status = user3.get(uri)
assert status == '200 OK'
assert "Your new user is activate" in body
assert user_valid.user.active