From d084008f85d93a39c0b5c46567b45fa89f3f19e7 Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Fri, 25 Jan 2019 15:17:15 +0100 Subject: [PATCH] tests: move fixtures in conftest (#30105) --- tests/conftest.py | 39 ++++++++++++++++++++++++++++++++++++++- tests/test_api.py | 33 --------------------------------- 2 files changed, 38 insertions(+), 34 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index f33e86f..f243ad5 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -3,11 +3,16 @@ import copy import pytest import django_webtest from collections import namedtuple +import pathlib2 from django.core.management import call_command +from django.contrib.auth import get_user_model + from django_rbac.utils import get_ou_model +User = get_user_model() OU = get_ou_model() +TEST_DIR = pathlib2.Path(__file__).parent @pytest.fixture @@ -25,7 +30,6 @@ def partner_ou(db): return OU.objects.create(name='partner', slug='ou') - @pytest.fixture def glc(app, partner_ou, db): from authentic2_idp_oidc.models import OIDCClient @@ -78,3 +82,36 @@ def hooks(settings): yield hook hook.clear() del settings.A2_HOOKS['__all__'] + + +@pytest.fixture +def admin(db): + user = User( + username='admin', + email='admin@example.net', + is_superuser=True, + is_staff=True) + user.ou = OU.objects.get(slug='territoire') + user.set_password('admin') + user.save() + return user + + +@pytest.fixture +def jpeg_file(): + with (TEST_DIR / 'minimal.jpg').open('rb') as fd: + yield fd.read() + + +@pytest.fixture +def png_file(): + with (TEST_DIR / 'minimal.png').open('rb') as fd: + yield fd.read() + + +@pytest.fixture +def pdf_file(): + with (TEST_DIR / 'minimal.pdf').open('rb') as fd: + yield fd.read() + + diff --git a/tests/test_api.py b/tests/test_api.py index 1e87f5a..440a574 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -3,7 +3,6 @@ import base64 import uuid import pytest -import pathlib2 from django.contrib.auth import get_user_model from authentic2_cut import models @@ -16,20 +15,6 @@ JOHN = u'Jôhn' DOE = u'Dôe' EMAIL = 'john.doe@example.com' -TEST_DIR = pathlib2.Path(__file__).parent - - -@pytest.fixture -def admin(db): - user = User( - username='admin', - email='admin@example.net', - is_superuser=True, - is_staff=True) - user.set_password('admin') - user.save() - return user - @pytest.fixture def john(glc_app): @@ -63,24 +48,6 @@ def test_create_user(john): assert john -@pytest.fixture -def jpeg_file(): - with (TEST_DIR / 'minimal.jpg').open('rb') as fd: - yield fd.read() - - -@pytest.fixture -def png_file(): - with (TEST_DIR / 'minimal.png').open('rb') as fd: - yield fd.read() - - -@pytest.fixture -def pdf_file(): - with (TEST_DIR / 'minimal.pdf').open('rb') as fd: - yield fd.read() - - def helper_test_validation_image(glc_app, john, image_file, extension): external_id = uuid.uuid4().hex response = glc_app.post_json('/api/users/%s/validate/' % john._oidc_sub, params={