diff --git a/tests/conftest.py b/tests/conftest.py index 23573d81..8e5c52d1 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -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 diff --git a/tests/test_basic.py b/tests/test_basic.py index 3d7a0ad8..b75cc6e6 100644 --- a/tests/test_basic.py +++ b/tests/test_basic.py @@ -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'] == { diff --git a/tests/test_render_2_0.py b/tests/test_render_2_0.py index 40c87687..9d344b38 100644 --- a/tests/test_render_2_0.py +++ b/tests/test_render_2_0.py @@ -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