From 39dc4d86354793853924915276f41d0f0fe42229 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Tue, 15 Mar 2022 19:57:54 +0100 Subject: [PATCH] add one example that how use client validate --- tests/test_render_2_0.py | 43 +++++++++++++++++++++++++++++++--------- 1 file changed, 34 insertions(+), 9 deletions(-) diff --git a/tests/test_render_2_0.py b/tests/test_render_2_0.py index 45c79d30..0a3a19ad 100644 --- a/tests/test_render_2_0.py +++ b/tests/test_render_2_0.py @@ -1,28 +1,53 @@ -# import pytest +import pytest from flask.testing import FlaskClient +from flask_wtf.csrf import generate_csrf from ereuse_devicehub.client import UserClient from ereuse_devicehub.devicehub import Devicehub - -# from tests import conftest +from tests import conftest -# @pytest.mark.mvp +@pytest.mark.mvp # @pytest.mark.usefixtures() -# def test_create_application(client: FlaskClient, mocker): -# @pytest.mark.usefixtures(conftest.app_context.__name__) +@pytest.mark.usefixtures(conftest.app_context.__name__) def test_login(user: UserClient, app: Devicehub): """Checks a simple login""" - client = FlaskClient(app, use_cookies=True, response_wrapper=app.response_class) + client = FlaskClient(app, use_cookies=True) + body, status, headers = client.get('/login/') body = next(body).decode("utf-8") assert status == '200 OK' assert "Login to Your Account" in body - data = {'email': user.email, 'password': 'foo', "remember": False} - body, status, headers = client.post('/login/', data=data) + data = { + 'email': user.email, + 'password': 'foo', + 'remember': False, + 'csrf_token': generate_csrf(), + } + body, status, headers = client.post('/login/', data=data, follow_redirects=True) body = next(body).decode("utf-8") assert status == '200 OK' assert "Login to Your Account" not in body + + +@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