From 11431c1e3633adc397d54bdb9e47efd47ef0132b Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Fri, 8 Mar 2019 02:51:39 +0100 Subject: [PATCH 6/9] tests: coding style (#29240) --- tests/test_manager.py | 51 ++++++++++++++++++++++++++++--------------- 1 file changed, 34 insertions(+), 17 deletions(-) diff --git a/tests/test_manager.py b/tests/test_manager.py index c1e3c32..b42e99a 100644 --- a/tests/test_manager.py +++ b/tests/test_manager.py @@ -1,25 +1,36 @@ -import base64 -import os -import StringIO +# hobo - portal to configure and deploy applications +# Copyright (C) 2015-2019 Entr'ouvert +# +# This program is free software: you can redistribute it and/or modify it +# under the terms of the GNU Affero General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + -from django.conf import settings from django.contrib.auth.models import User import pytest -from webtest import TestApp from hobo.profile import models from hobo.wsgi import application -pytestmark = pytest.mark.django_db @pytest.fixture -def admin_user(): +def admin_user(db): try: user = User.objects.get(username='admin') except User.DoesNotExist: user = User.objects.create_superuser('admin', email=None, password='admin') return user + def login(app, username='admin', password='admin'): login_page = app.get('/login/') login_form = login_page.forms[0] @@ -29,27 +40,33 @@ def login(app, username='admin', password='admin'): assert resp.status_int == 302 return app -def test_unlogged_access(): + +@pytest.fixture +def logged_app(app, admin_user): + return login(app) + + +def test_unlogged_access(app): # connect while not being logged in - app = TestApp(application) assert app.get('/', status=302).location.endswith('/login/?next=/') -def test_access(admin_user): - app = login(TestApp(application)) - resp = app.get('/', status=200) + +def test_access(logged_app): + resp = logged_app.get('/', status=200) assert 'User Profile' in resp.body assert 'Services' in resp.body assert 'Variables' in resp.body -def test_logout(admin_user): - app = login(TestApp(application)) + +def test_logout(logged_app): + app = logged_app app.get('/logout/') assert app.get('/', status=302).location.endswith('/login/?next=/') @pytest.mark.parametrize('kind', ['boolean', 'string']) -def test_add_attribute(admin_user, kind): - app = login(TestApp(application)) +def test_add_attribute(logged_app, admin_user, kind): + app = logged_app assert models.AttributeDefinition.objects.filter(kind=kind).filter(name='test').count() == 0 page = app.get('/profile/add-attribute', status=200) page.form['label'] = 'test' @@ -65,5 +82,5 @@ def test_add_attribute(admin_user, kind): assert models.AttributeDefinition.objects.filter(kind=kind).filter(name='test').count() == 1 -def test_attribute_kind_not_restricted_at_model_level(): +def test_attribute_kind_not_restricted_at_model_level(db): assert models.AttributeDefinition.objects.create(label='test', kind='somestring') -- 2.20.1