~homeworkprod/byceps

8b27569610130a6f87a4e81851c01c484f169e18 — Jochen Kupperschmidt 1 year, 5 months ago 098e099
Use single admin app fixture with database
D tests/blueprints/admin/conftest.py => tests/blueprints/admin/conftest.py +0 -18
@@ 1,18 0,0 @@
"""
:Copyright: 2006-2020 Jochen Kupperschmidt
:License: Modified BSD, see LICENSE for details.

Fixtures specific to admin blueprints
"""

import pytest

from tests.conftest import database_recreated


@pytest.fixture(scope='module')
def app(admin_app, db):
    app = admin_app
    with app.app_context():
        with database_recreated(db):
            yield app

M tests/blueprints/admin/newsletter/test_views.py => tests/blueprints/admin/newsletter/test_views.py +3 -3
@@ 110,7 110,7 @@ def newsletter_admin():


@pytest.fixture(scope='module')
def newsletter_list(app):
def newsletter_list(admin_app_with_db):
    return command_service.create_list('example', 'Example')




@@ 159,7 159,7 @@ def add_subscriptions(db, user_id, list_id, states):


@pytest.fixture(scope='module')
def client(app, newsletter_admin):
def client(admin_app_with_db, newsletter_admin):
    """Provide a test HTTP client against the API."""
    with http_client(app, user_id=newsletter_admin.id) as client:
    with http_client(admin_app_with_db, user_id=newsletter_admin.id) as client:
        yield client

M tests/blueprints/admin/shop/order/test_order_export.py => tests/blueprints/admin/shop/order/test_order_export.py +5 -5
@@ 28,7 28,7 @@ from tests.services.shop.helpers import create_article as _create_article


@pytest.fixture(scope='module')
def admin_user(app):
def admin_user(admin_app_with_db):
    admin = create_user('ShopOrderAdmin')

    permission_ids = {'admin.access', 'shop_order.view'}


@@ 139,13 139,13 @@ def order(shop, order_number_sequence, cart, orderer):


@freeze_time('2015-04-15 07:54:18')  # UTC
def test_serialize_existing_order(app, shop, order, admin_user):
def test_serialize_existing_order(admin_app_with_db, shop, order, admin_user):
    filename = 'testfixtures/shop/order_export.xml'
    with codecs.open(filename, encoding='iso-8859-1') as f:
        expected = f.read().rstrip()

    url = f'/admin/shop/orders/{order.id}/export'
    with http_client(app, user_id=admin_user.id) as client:
    with http_client(admin_app_with_db, user_id=admin_user.id) as client:
        response = client.get(url)

    assert response.status_code == 200


@@ 156,11 156,11 @@ def test_serialize_existing_order(app, shop, order, admin_user):


@freeze_time('2015-04-15 07:54:18')  # UTC
def test_serialize_unknown_order(app, shop, admin_user):
def test_serialize_unknown_order(admin_app_with_db, shop, admin_user):
    unknown_order_id = '00000000-0000-0000-0000-000000000000'

    url = f'/admin/shop/orders/{unknown_order_id}/export'
    with http_client(app, user_id=admin_user.id) as client:
    with http_client(admin_app_with_db, user_id=admin_user.id) as client:
        response = client.get(url)

    assert response.status_code == 404

M tests/blueprints/admin/shop/order/test_views.py => tests/blueprints/admin/shop/order/test_views.py +9 -9
@@ 96,7 96,7 @@ def orderer():
def test_cancel_before_paid(
    order_email_service_mock,
    order_canceled_signal_send_mock,
    app,
    admin_app_with_db,
    shop,
    article1,
    order_number_sequence,


@@ 118,7 118,7 @@ def test_cancel_before_paid(
        'reason': 'Dein Vorname ist albern!',
        'send_email': 'y',
    }
    with http_client(app, user_id=admin.id) as client:
    with http_client(admin_app_with_db, user_id=admin.id) as client:
        response = client.post(url, data=form_data)

    order_afterwards = get_order(order_before.id)


@@ 149,7 149,7 @@ def test_cancel_before_paid(
def test_cancel_before_paid_without_sending_email(
    order_email_service_mock,
    order_canceled_signal_send_mock,
    app,
    admin_app_with_db,
    shop,
    article2,
    order_number_sequence,


@@ 166,7 166,7 @@ def test_cancel_before_paid_without_sending_email(
        'reason': 'Dein Vorname ist albern!',
        # Sending e-mail is not requested.
    }
    with http_client(app, user_id=admin.id) as client:
    with http_client(admin_app_with_db, user_id=admin.id) as client:
        response = client.post(url, data=form_data)

    order_afterwards = get_order(placed_order.id)


@@ 190,7 190,7 @@ def test_cancel_before_paid_without_sending_email(
def test_mark_order_as_paid(
    order_email_service_mock,
    order_paid_signal_send_mock,
    app,
    admin_app_with_db,
    shop,
    order_number_sequence,
    admin,


@@ 203,7 203,7 @@ def test_mark_order_as_paid(

    url = f'/admin/shop/orders/{order_before.id}/mark_as_paid'
    form_data = {'payment_method': 'direct_debit'}
    with http_client(app, user_id=admin.id) as client:
    with http_client(admin_app_with_db, user_id=admin.id) as client:
        response = client.post(url, data=form_data)

    order_afterwards = get_order(order_before.id)


@@ 236,7 236,7 @@ def test_cancel_after_paid(
    order_email_service_mock,
    order_paid_signal_send_mock,
    order_canceled_signal_send_mock,
    app,
    admin_app_with_db,
    shop,
    article3,
    order_number_sequence,


@@ 255,7 255,7 @@ def test_cancel_after_paid(

    url = f'/admin/shop/orders/{order_before.id}/mark_as_paid'
    form_data = {'payment_method': 'bank_transfer'}
    with http_client(app, user_id=admin.id) as client:
    with http_client(admin_app_with_db, user_id=admin.id) as client:
        response = client.post(url, data=form_data)

    url = f'/admin/shop/orders/{order_before.id}/cancel'


@@ 263,7 263,7 @@ def test_cancel_after_paid(
        'reason': 'Dein Vorname ist albern!',
        'send_email': 'n',
    }
    with http_client(app, user_id=admin.id) as client:
    with http_client(admin_app_with_db, user_id=admin.id) as client:
        response = client.post(url, data=form_data)

    order_afterwards = get_order(order_before.id)

M tests/conftest.py => tests/conftest.py +1 -1
@@ 55,7 55,7 @@ def admin_app(make_admin_app):
    yield make_admin_app()


@pytest.fixture
@pytest.fixture(scope='module')
def admin_app_with_db(admin_app, db):
    with admin_app.app_context():
        with database_recreated(db):