~homeworkprod/byceps

9f9259fddd5949b49660987aa61723002128de46 — Jochen Kupperschmidt 1 year, 16 days ago 4cd21be
Use admin-specific client fixtures in admin blueprint tests
25 files changed, 196 insertions(+), 283 deletions(-)

M tests/integration/blueprints/admin/authorization/conftest.py
M tests/integration/blueprints/admin/authorization/test_views.py
M tests/integration/blueprints/admin/board/conftest.py
M tests/integration/blueprints/admin/board/test_board_views.py
M tests/integration/blueprints/admin/board/test_category_views.py
M tests/integration/blueprints/admin/brand/conftest.py
M tests/integration/blueprints/admin/brand/test_views.py
M tests/integration/blueprints/admin/consent/conftest.py
M tests/integration/blueprints/admin/consent/test_views.py
M tests/integration/blueprints/admin/email/conftest.py
M tests/integration/blueprints/admin/email/test_create_config.py
M tests/integration/blueprints/admin/email/test_delete_config.py
M tests/integration/blueprints/admin/email/test_views.py
M tests/integration/blueprints/admin/newsletter/test_views.py
M tests/integration/blueprints/admin/party/conftest.py
M tests/integration/blueprints/admin/party/test_views.py
M tests/integration/blueprints/admin/shop/order/test_order_export.py
M tests/integration/blueprints/admin/shop/order/test_views.py
M tests/integration/blueprints/admin/shop/shop/test_create_shop.py
M tests/integration/blueprints/admin/site/conftest.py
M tests/integration/blueprints/admin/site/test_views.py
M tests/integration/blueprints/admin/ticketing/conftest.py
M tests/integration/blueprints/admin/ticketing/test_views.py
M tests/integration/blueprints/admin/user_badges/conftest.py
M tests/integration/blueprints/admin/user_badges/test_views.py
M tests/integration/blueprints/admin/authorization/conftest.py => tests/integration/blueprints/admin/authorization/conftest.py +6 -1
@@ 10,7 10,7 @@ import byceps.services.authorization.service as authz_service
from tests.helpers import login_user


@pytest.fixture(scope='module')
@pytest.fixture(scope='package')
def role_admin(make_admin):
    permission_ids = {
        'admin.access',


@@ 22,6 22,11 @@ def role_admin(make_admin):
    return admin


@pytest.fixture(scope='package')
def role_admin_client(make_client, admin_app, role_admin):
    return make_client(admin_app, user_id=role_admin.id)


@pytest.fixture(scope='module')
def permission():
    permission_id = 'spin_around'

M tests/integration/blueprints/admin/authorization/test_views.py => tests/integration/blueprints/admin/authorization/test_views.py +6 -16
@@ 3,30 3,20 @@
:License: Modified BSD, see LICENSE for details.
"""

from tests.helpers import http_client


def test_permission_index(admin_app, role_admin, permission):
def test_permission_index(role_admin_client, permission):
    url = '/admin/authorization/permissions'
    response = get_resource(admin_app, role_admin, url)
    response = role_admin_client.get(url)
    assert response.status_code == 200


def test_role_index(admin_app, role_admin, role):
def test_role_index(role_admin_client, role):
    url = '/admin/authorization/roles'
    response = get_resource(admin_app, role_admin, url)
    response = role_admin_client.get(url)
    assert response.status_code == 200


def test_role_view(admin_app, role_admin, role):
def test_role_view(role_admin_client, role):
    url = f'/admin/authorization/roles/{role.id}'
    response = get_resource(admin_app, role_admin, url)
    response = role_admin_client.get(url)
    assert response.status_code == 200


# helpers


def get_resource(app, user, url):
    with http_client(app, user_id=user.id) as client:
        return client.get(url)

M tests/integration/blueprints/admin/board/conftest.py => tests/integration/blueprints/admin/board/conftest.py +5 -0
@@ 25,6 25,11 @@ def board_admin(make_admin):
    return admin


@pytest.fixture(scope='package')
def board_admin_client(make_client, admin_app, board_admin):
    return make_client(admin_app, user_id=board_admin.id)


@pytest.fixture(scope='module')
def category(board):
    slug = 'beauty-tips'

M tests/integration/blueprints/admin/board/test_board_views.py => tests/integration/blueprints/admin/board/test_board_views.py +8 -23
@@ 5,28 5,26 @@

from byceps.services.board import board_service

from tests.helpers import http_client


def test_index_for_brand(admin_app, board_admin, brand, board):
def test_index_for_brand(board_admin_client, brand, board):
    url = f'/admin/boards/brands/{brand.id}'
    response = get_resource(admin_app, board_admin, url)
    response = board_admin_client.get(url)
    assert response.status_code == 200


def test_view(admin_app, board_admin, board):
def test_view(board_admin_client, board):
    url = f'/admin/boards/boards/{board.id}'
    response = get_resource(admin_app, board_admin, url)
    response = board_admin_client.get(url)
    assert response.status_code == 200


def test_create_form(admin_app, board_admin, brand):
def test_create_form(board_admin_client, brand):
    url = f'/admin/boards/for_brand/{brand.id}/boards/create'
    response = get_resource(admin_app, board_admin, url)
    response = board_admin_client.get(url)
    assert response.status_code == 200


def test_create(admin_app, board_admin, brand):
def test_create(board_admin_client, brand):
    board_id = 'intranet-board-2018'

    assert board_service.find_board(board_id) is None


@@ 35,7 33,7 @@ def test_create(admin_app, board_admin, brand):
    form_data = {
        'board_id': board_id,
    }
    response = post_resource(admin_app, board_admin, url, form_data)
    response = board_admin_client.post(url, data=form_data)

    board = board_service.find_board(board_id)
    assert board is not None


@@ 44,16 42,3 @@ def test_create(admin_app, board_admin, brand):

    # Clean up.
    board_service.delete_board(board_id)


# helpers


def get_resource(app, user, url):
    with http_client(app, user_id=user.id) as client:
        return client.get(url)


def post_resource(app, user, url, data):
    with http_client(app, user_id=user.id) as client:
        return client.post(url, data=data)

M tests/integration/blueprints/admin/board/test_category_views.py => tests/integration/blueprints/admin/board/test_category_views.py +6 -21
@@ 8,16 8,14 @@ from byceps.services.board import (
    category_query_service,
)

from tests.helpers import http_client


def test_create_form(admin_app, board_admin, board):
def test_create_form(board_admin_client, board):
    url = f'/admin/boards/categories/for_board/{board.id}/create'
    response = get_resource(admin_app, board_admin, url)
    response = board_admin_client.get(url)
    assert response.status_code == 200


def test_create(admin_app, board_admin, board):
def test_create(board_admin_client, board):
    slug = 'off-topic'
    title = 'Off-Topic'
    description = 'Random stuff'


@@ 30,7 28,7 @@ def test_create(admin_app, board_admin, board):
        'title': title,
        'description': description,
    }
    response = post_resource(admin_app, board_admin, url, form_data)
    response = board_admin_client.post(url, data=form_data)

    category = category_query_service.find_category_by_slug(board.id, slug)
    assert category is not None


@@ 43,20 41,7 @@ def test_create(admin_app, board_admin, board):
    category_command_service.delete_category(category.id)


def test_update_form(admin_app, board_admin, category):
def test_update_form(board_admin_client, category):
    url = f'/admin/boards/categories/{category.id}/update'
    response = get_resource(admin_app, board_admin, url)
    response = board_admin_client.get(url)
    assert response.status_code == 200


# helpers


def get_resource(app, user, url):
    with http_client(app, user_id=user.id) as client:
        return client.get(url)


def post_resource(app, user, url, data):
    with http_client(app, user_id=user.id) as client:
        return client.post(url, data=data)

M tests/integration/blueprints/admin/brand/conftest.py => tests/integration/blueprints/admin/brand/conftest.py +6 -1
@@ 8,7 8,7 @@ import pytest
from tests.helpers import login_user


@pytest.fixture(scope='module')
@pytest.fixture(scope='package')
def brand_admin(make_admin):
    permission_ids = {
        'admin.access',


@@ 19,3 19,8 @@ def brand_admin(make_admin):
    admin = make_admin('BrandAdmin', permission_ids)
    login_user(admin.id)
    return admin


@pytest.fixture(scope='package')
def brand_admin_client(make_client, admin_app, brand_admin):
    return make_client(admin_app, user_id=brand_admin.id)

M tests/integration/blueprints/admin/brand/test_views.py => tests/integration/blueprints/admin/brand/test_views.py +10 -25
@@ 5,28 5,26 @@

import byceps.services.brand.service as brand_service

from tests.helpers import http_client


def test_index(admin_app, brand_admin, brand):
def test_index(brand_admin_client, brand):
    url = '/admin/brands/'
    response = get_resource(admin_app, brand_admin, url)
    response = brand_admin_client.get(url)
    assert response.status_code == 200


def test_view(admin_app, brand_admin, brand):
def test_view(brand_admin_client, brand):
    url = f'/admin/brands/brands/{brand.id}'
    response = get_resource(admin_app, brand_admin, url)
    response = brand_admin_client.get(url)
    assert response.status_code == 200


def test_create_form(admin_app, brand_admin):
def test_create_form(brand_admin_client):
    url = '/admin/brands/create'
    response = get_resource(admin_app, brand_admin, url)
    response = brand_admin_client.get(url)
    assert response.status_code == 200


def test_create(admin_app, brand_admin):
def test_create(brand_admin_client):
    brand_id = 'galant'
    title = 'gaLANt'



@@ 37,7 35,7 @@ def test_create(admin_app, brand_admin):
        'id': brand_id,
        'title': title,
    }
    response = post_resource(admin_app, brand_admin, url, form_data)
    response = brand_admin_client.post(url, data=form_data)

    brand = brand_service.find_brand(brand_id)
    assert brand is not None


@@ 48,20 46,7 @@ def test_create(admin_app, brand_admin):
    brand_service.delete_brand(brand_id)


def test_update_form(admin_app, brand_admin, brand):
def test_update_form(brand_admin_client, brand):
    url = f'/admin/brands/brands/{brand.id}/update'
    response = get_resource(admin_app, brand_admin, url)
    response = brand_admin_client.get(url)
    assert response.status_code == 200


# helpers


def get_resource(app, user, url):
    with http_client(app, user_id=user.id) as client:
        return client.get(url)


def post_resource(app, user, url, data):
    with http_client(app, user_id=user.id) as client:
        return client.post(url, data=data)

M tests/integration/blueprints/admin/consent/conftest.py => tests/integration/blueprints/admin/consent/conftest.py +6 -1
@@ 8,7 8,7 @@ import pytest
from tests.helpers import login_user


@pytest.fixture(scope='module')
@pytest.fixture(scope='package')
def consent_admin(make_admin):
    permission_ids = {
        'admin.access',


@@ 17,3 17,8 @@ def consent_admin(make_admin):
    admin = make_admin('ConsentAdmin', permission_ids)
    login_user(admin.id)
    return admin


@pytest.fixture(scope='package')
def consent_admin_client(make_client, admin_app, consent_admin):
    return make_client(admin_app, user_id=consent_admin.id)

M tests/integration/blueprints/admin/consent/test_views.py => tests/integration/blueprints/admin/consent/test_views.py +2 -12
@@ 3,18 3,8 @@
:License: Modified BSD, see LICENSE for details.
"""

from tests.helpers import http_client


def test_index(admin_app, consent_admin):
def test_index(consent_admin_client):
    url = '/admin/consent/'
    response = get_resource(admin_app, consent_admin, url)
    response = consent_admin_client.get(url)
    assert response.status_code == 200


# helpers


def get_resource(app, user, url):
    with http_client(app, user_id=user.id) as client:
        return client.get(url)

M tests/integration/blueprints/admin/email/conftest.py => tests/integration/blueprints/admin/email/conftest.py +5 -0
@@ 20,3 20,8 @@ def email_admin(make_admin):
    admin = make_admin('EmailAdmin', permission_ids)
    login_user(admin.id)
    return admin


@pytest.fixture(scope='package')
def email_admin_client(make_client, admin_app, email_admin):
    return make_client(admin_app, user_id=email_admin.id)

M tests/integration/blueprints/admin/email/test_create_config.py => tests/integration/blueprints/admin/email/test_create_config.py +4 -8
@@ 5,10 5,8 @@

import byceps.services.email.service as email_service

from tests.helpers import http_client


def test_create_minimal_config(admin_app, email_admin):
def test_create_minimal_config(email_admin_client):
    config_id = 'acme-minimal'
    assert email_service.find_config(config_id) is None



@@ 17,8 15,7 @@ def test_create_minimal_config(admin_app, email_admin):
        'config_id': config_id,
        'sender_address': 'noreply@acme.example',
    }
    with http_client(admin_app, user_id=email_admin.id) as client:
        response = client.post(url, data=form_data)
    response = email_admin_client.post(url, data=form_data)

    config = email_service.find_config(config_id)
    assert config is not None


@@ 32,7 29,7 @@ def test_create_minimal_config(admin_app, email_admin):
    email_service.delete_config(config_id)


def test_create_full_config(admin_app, email_admin):
def test_create_full_config(email_admin_client):
    config_id = 'acme-full'
    assert email_service.find_config(config_id) is None



@@ 43,8 40,7 @@ def test_create_full_config(admin_app, email_admin):
        'sender_name': 'ACME Corp.',
        'contact_address': 'info@acme.example',
    }
    with http_client(admin_app, user_id=email_admin.id) as client:
        response = client.post(url, data=form_data)
    response = email_admin_client.post(url, data=form_data)

    config = email_service.find_config(config_id)
    assert config is not None

M tests/integration/blueprints/admin/email/test_delete_config.py => tests/integration/blueprints/admin/email/test_delete_config.py +2 -5
@@ 5,17 5,14 @@

import byceps.services.email.service as email_service

from tests.helpers import http_client


def test_delete_config(admin_app, email_admin):
def test_delete_config(email_admin_client):
    config_id = 'kann-weg'

    assert email_service.create_config(config_id, 'noreply@acme.example')
    assert email_service.find_config(config_id) is not None

    url = f'/admin/email/configs/{config_id}'
    with http_client(admin_app, user_id=email_admin.id) as client:
        response = client.delete(url)
    response = email_admin_client.delete(url)

    assert email_service.find_config(config_id) is None

M tests/integration/blueprints/admin/email/test_views.py => tests/integration/blueprints/admin/email/test_views.py +6 -16
@@ 5,30 5,20 @@

import byceps.services.email.service as email_service

from tests.helpers import http_client


def test_index(admin_app, email_admin, site):
def test_index(email_admin_client, site):
    url = '/admin/email/configs'
    response = get_resource(admin_app, email_admin, url)
    response = email_admin_client.get(url)
    assert response.status_code == 200


def test_create_form(admin_app, email_admin):
def test_create_form(email_admin_client):
    url = '/admin/email/configs/create'
    response = get_resource(admin_app, email_admin, url)
    response = email_admin_client.get(url)
    assert response.status_code == 200


def test_update_form(admin_app, email_admin, email_config):
def test_update_form(email_admin_client, email_config):
    url = f'/admin/email/configs/{email_config.id}/update'
    response = get_resource(admin_app, email_admin, url)
    response = email_admin_client.get(url)
    assert response.status_code == 200


# helpers


def get_resource(app, user, url):
    with http_client(app, user_id=user.id) as client:
        return client.get(url)

M tests/integration/blueprints/admin/newsletter/test_views.py => tests/integration/blueprints/admin/newsletter/test_views.py +5 -7
@@ 15,7 15,7 @@ from byceps.services.newsletter import command_service
from byceps.services.newsletter.types import SubscriptionState
from byceps.services.user import command_service as user_command_service

from tests.helpers import http_client, login_user
from tests.helpers import login_user


def test_export_subscribers(newsletter_list, subscribers, client):


@@ 95,7 95,7 @@ def test_export_subscriber_email_addresses(newsletter_list, subscribers, client)
    assert response.get_data() == expected_data


@pytest.fixture(scope='module')
@pytest.fixture(scope='package')
def newsletter_admin(make_admin):
    permission_ids = {'admin.access', 'newsletter.export_subscribers'}
    admin = make_admin('NewsletterAdmin', permission_ids)


@@ 160,8 160,6 @@ def add_subscriptions(user_id, list_id, states):
    db.session.commit()


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

M tests/integration/blueprints/admin/party/conftest.py => tests/integration/blueprints/admin/party/conftest.py +6 -1
@@ 8,7 8,7 @@ import pytest
from tests.helpers import login_user


@pytest.fixture(scope='module')
@pytest.fixture(scope='package')
def party_admin(make_admin):
    permission_ids = {
        'admin.access',


@@ 19,3 19,8 @@ def party_admin(make_admin):
    admin = make_admin('PartyAdmin', permission_ids)
    login_user(admin.id)
    return admin


@pytest.fixture(scope='package')
def party_admin_client(make_client, admin_app, party_admin):
    return make_client(admin_app, user_id=party_admin.id)

M tests/integration/blueprints/admin/party/test_views.py => tests/integration/blueprints/admin/party/test_views.py +12 -27
@@ 7,34 7,32 @@ from datetime import datetime

import byceps.services.party.service as party_service

from tests.helpers import http_client


def test_index(admin_app, party_admin, party):
def test_index(party_admin_client, party):
    url = '/admin/parties/'
    response = get_resource(admin_app, party_admin, url)
    response = party_admin_client.get(url)
    assert response.status_code == 200


def test_index_for_brand(admin_app, party_admin, brand, party):
def test_index_for_brand(party_admin_client, brand, party):
    url = f'/admin/parties/brands/{brand.id}'
    response = get_resource(admin_app, party_admin, url)
    response = party_admin_client.get(url)
    assert response.status_code == 200


def test_view(admin_app, party_admin, party):
def test_view(party_admin_client, party):
    url = f'/admin/parties/parties/{party.id}'
    response = get_resource(admin_app, party_admin, url)
    response = party_admin_client.get(url)
    assert response.status_code == 200


def test_create_form(admin_app, party_admin, brand):
def test_create_form(party_admin_client, brand):
    url = f'/admin/parties/for_brand/{brand.id}/create'
    response = get_resource(admin_app, party_admin, url)
    response = party_admin_client.get(url)
    assert response.status_code == 200


def test_create(admin_app, party_admin, brand):
def test_create(party_admin_client, brand):
    party_id = 'galant-2020'
    title = 'gaLANt 2020'
    max_ticket_quantity = 126


@@ 49,7 47,7 @@ def test_create(admin_app, party_admin, brand):
        'ends_at': '20.09.2020 13:00',  # UTC+02:00
        'max_ticket_quantity': str(max_ticket_quantity),
    }
    response = post_resource(admin_app, party_admin, url, form_data)
    response = party_admin_client.post(url, data=form_data)

    party = party_service.find_party(party_id)
    assert party is not None


@@ 62,20 60,7 @@ def test_create(admin_app, party_admin, brand):
    party_service.delete_party(party_id)


def test_update_form(admin_app, party_admin, party):
def test_update_form(party_admin_client, party):
    url = f'/admin/parties/parties/{party.id}/update'
    response = get_resource(admin_app, party_admin, url)
    response = party_admin_client.get(url)
    assert response.status_code == 200


# helpers


def get_resource(app, user, url):
    with http_client(app, user_id=user.id) as client:
        return client.get(url)


def post_resource(app, user, url, data):
    with http_client(app, user_id=user.id) as client:
        return client.post(url, data=data)

M tests/integration/blueprints/admin/shop/order/test_order_export.py => tests/integration/blueprints/admin/shop/order/test_order_export.py +12 -9
@@ 18,20 18,25 @@ from byceps.services.shop.order import (
)
from byceps.services.shop.storefront import service as storefront_service

from tests.helpers import http_client, login_user
from tests.helpers import login_user
from tests.integration.services.shop.helpers import (
    create_article as _create_article,
)


@pytest.fixture(scope='module')
def admin_user(make_admin):
@pytest.fixture(scope='package')
def shop_order_admin(make_admin):
    permission_ids = {'admin.access', 'shop_order.view'}
    admin = make_admin('ShopOrderExportAdmin', permission_ids)
    login_user(admin.id)
    return admin


@pytest.fixture(scope='package')
def shop_order_admin_client(make_client, admin_app, shop_order_admin):
    return make_client(admin_app, user_id=shop_order_admin.id)


@pytest.fixture
def article_bungalow(shop):
    article = create_article(


@@ 145,13 150,12 @@ def order(storefront, cart, orderer):


@freeze_time('2015-04-15 07:54:18')  # UTC
def test_serialize_existing_order(request, admin_app, order, admin_user):
def test_serialize_existing_order(request, order, shop_order_admin_client):
    filename = request.fspath.dirpath('order_export.xml')
    expected = filename.read_text('iso-8859-1').rstrip()

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

    assert response.status_code == 200
    assert response.content_type == 'application/xml; charset=iso-8859-1'


@@ 161,12 165,11 @@ def test_serialize_existing_order(request, admin_app, order, admin_user):


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

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

    assert response.status_code == 404


M tests/integration/blueprints/admin/shop/order/test_views.py => tests/integration/blueprints/admin/shop/order/test_views.py +32 -32
@@ 18,14 18,14 @@ from byceps.services.shop.order.transfer.models import (
)
from testfixtures.shop_order import create_orderer

from tests.helpers import http_client, login_user
from tests.helpers import login_user
from tests.integration.services.shop.helpers import (
    create_article as _create_article,
)


@pytest.fixture(scope='module')
def admin(make_admin):
@pytest.fixture(scope='package')
def shop_order_admin(make_admin):
    permission_ids = {
        'admin.access',
        'shop_order.cancel',


@@ 36,6 36,11 @@ def admin(make_admin):
    return admin


@pytest.fixture(scope='package')
def shop_order_admin_client(make_client, admin_app, shop_order_admin):
    return make_client(admin_app, user_id=shop_order_admin.id)


@pytest.fixture
def article1(shop):
    article = create_article(shop.id, 'item-001', 8)


@@ 75,12 80,12 @@ def orderer(orderer_user):
def test_cancel_before_paid(
    order_email_service_mock,
    order_canceled_signal_send_mock,
    admin_app,
    storefront,
    article1,
    admin,
    shop_order_admin,
    orderer_user,
    orderer,
    shop_order_admin_client,
):
    article = article1



@@ 99,13 104,12 @@ def test_cancel_before_paid(
        'reason': 'Dein Vorname ist albern!',
        'send_email': 'y',
    }
    with http_client(admin_app, user_id=admin.id) as client:
        response = client.post(url, data=form_data)
    response = shop_order_admin_client.post(url, data=form_data)

    order_afterwards = get_order(order_before.id)
    assert response.status_code == 302
    assert_payment(
        order_afterwards, None, PaymentState.canceled_before_paid, admin.id
        order_afterwards, None, PaymentState.canceled_before_paid, shop_order_admin.id
    )

    assert get_article_quantity(article.id) == 8


@@ 116,8 120,8 @@ def test_cancel_before_paid(

    event = ShopOrderCanceled(
        occurred_at=order_afterwards.payment_state_updated_at,
        initiator_id=admin.id,
        initiator_screen_name=admin.screen_name,
        initiator_id=shop_order_admin.id,
        initiator_screen_name=shop_order_admin.screen_name,
        order_id=placed_order.id,
        order_number=placed_order.order_number,
        orderer_id=orderer_user.id,


@@ 133,12 137,12 @@ def test_cancel_before_paid(
def test_cancel_before_paid_without_sending_email(
    order_email_service_mock,
    order_canceled_signal_send_mock,
    admin_app,
    storefront,
    article2,
    admin,
    shop_order_admin,
    orderer_user,
    orderer,
    shop_order_admin_client,
):
    article = article2



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

    order_afterwards = get_order(placed_order.id)
    assert response.status_code == 302


@@ 163,8 166,8 @@ def test_cancel_before_paid_without_sending_email(

    event = ShopOrderCanceled(
        occurred_at=order_afterwards.payment_state_updated_at,
        initiator_id=admin.id,
        initiator_screen_name=admin.screen_name,
        initiator_id=shop_order_admin.id,
        initiator_screen_name=shop_order_admin.screen_name,
        order_id=placed_order.id,
        order_number=placed_order.order_number,
        orderer_id=orderer_user.id,


@@ 180,11 183,11 @@ def test_cancel_before_paid_without_sending_email(
def test_mark_order_as_paid(
    order_email_service_mock,
    order_paid_signal_send_mock,
    admin_app,
    storefront,
    admin,
    shop_order_admin,
    orderer_user,
    orderer,
    shop_order_admin_client,
):
    placed_order = place_order(storefront.id, orderer, [])
    order_before = get_order(placed_order.id)


@@ 193,8 196,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(admin_app, user_id=admin.id) as client:
        response = client.post(url, data=form_data)
    response = shop_order_admin_client.post(url, data=form_data)

    order_afterwards = get_order(order_before.id)
    assert response.status_code == 302


@@ 202,7 204,7 @@ def test_mark_order_as_paid(
        order_afterwards,
        PaymentMethod.direct_debit,
        PaymentState.paid,
        admin.id,
        shop_order_admin.id,
    )

    order_email_service_mock.send_email_for_paid_order_to_orderer.assert_called_once_with(


@@ 211,8 213,8 @@ def test_mark_order_as_paid(

    event = ShopOrderPaid(
        occurred_at=order_afterwards.payment_state_updated_at,
        initiator_id=admin.id,
        initiator_screen_name=admin.screen_name,
        initiator_id=shop_order_admin.id,
        initiator_screen_name=shop_order_admin.screen_name,
        order_id=placed_order.id,
        order_number=placed_order.order_number,
        orderer_id=orderer_user.id,


@@ 231,12 233,12 @@ def test_cancel_after_paid(
    order_email_service_mock,
    order_paid_signal_send_mock,
    order_canceled_signal_send_mock,
    admin_app,
    storefront,
    article3,
    admin,
    shop_order_admin,
    orderer_user,
    orderer,
    shop_order_admin_client,
):
    article = article3



@@ 252,16 254,14 @@ 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(admin_app, user_id=admin.id) as client:
        response = client.post(url, data=form_data)
    response = shop_order_admin_client.post(url, data=form_data)

    url = f'/admin/shop/orders/{order_before.id}/cancel'
    form_data = {
        'reason': 'Dein Vorname ist albern!',
        'send_email': 'n',
    }
    with http_client(admin_app, user_id=admin.id) as client:
        response = client.post(url, data=form_data)
    response = shop_order_admin_client.post(url, data=form_data)

    order_afterwards = get_order(order_before.id)
    assert response.status_code == 302


@@ 269,7 269,7 @@ def test_cancel_after_paid(
        order_afterwards,
        PaymentMethod.bank_transfer,
        PaymentState.canceled_after_paid,
        admin.id,
        shop_order_admin.id,
    )

    assert get_article_quantity(article.id) == 8


@@ 280,8 280,8 @@ def test_cancel_after_paid(

    event = ShopOrderCanceled(
        occurred_at=order_afterwards.payment_state_updated_at,
        initiator_id=admin.id,
        initiator_screen_name=admin.screen_name,
        initiator_id=shop_order_admin.id,
        initiator_screen_name=shop_order_admin.screen_name,
        order_id=placed_order.id,
        order_number=placed_order.order_number,
        orderer_id=orderer_user.id,

M tests/integration/blueprints/admin/shop/shop/test_create_shop.py => tests/integration/blueprints/admin/shop/shop/test_create_shop.py +10 -6
@@ 7,11 7,11 @@ import pytest

import byceps.services.shop.shop.service as shop_service

from tests.helpers import http_client, login_user
from tests.helpers import login_user


@pytest.fixture(scope='module')
def admin(make_admin):
@pytest.fixture(scope='package')
def shop_admin(make_admin):
    permission_ids = {
        'admin.access',
        'shop.create',


@@ 21,7 21,12 @@ def admin(make_admin):
    return admin


def test_create_shop(email_config, admin_app, admin):
@pytest.fixture(scope='package')
def shop_admin_client(make_client, admin_app, shop_admin):
    return make_client(admin_app, user_id=shop_admin.id)


def test_create_shop(email_config, shop_admin_client):
    shop_id = 'acme'
    assert shop_service.find_shop(shop_id) is None



@@ 31,8 36,7 @@ def test_create_shop(email_config, admin_app, admin):
        'title': 'ACME',
        'email_config_id': email_config.id,
    }
    with http_client(admin_app, user_id=admin.id) as client:
        response = client.post(url, data=form_data)
    response = shop_admin_client.post(url, data=form_data)

    shop = shop_service.find_shop(shop_id)
    assert shop is not None

M tests/integration/blueprints/admin/site/conftest.py => tests/integration/blueprints/admin/site/conftest.py +6 -1
@@ 8,7 8,7 @@ import pytest
from tests.helpers import login_user


@pytest.fixture(scope='module')
@pytest.fixture(scope='package')
def site_admin(make_admin):
    permission_ids = {
        'admin.access',


@@ 19,3 19,8 @@ def site_admin(make_admin):
    admin = make_admin('SiteAdmin', permission_ids)
    login_user(admin.id)
    return admin


@pytest.fixture(scope='package')
def site_admin_client(make_client, admin_app, site_admin):
    return make_client(admin_app, user_id=site_admin.id)

M tests/integration/blueprints/admin/site/test_views.py => tests/integration/blueprints/admin/site/test_views.py +10 -25
@@ 5,28 5,26 @@

import byceps.services.site.service as site_service

from tests.helpers import http_client


def test_index(admin_app, site_admin, site):
def test_index(site_admin_client, site):
    url = '/admin/sites/'
    response = get_resource(admin_app, site_admin, url)
    response = site_admin_client.get(url)
    assert response.status_code == 200


def test_view(admin_app, site_admin, site):
def test_view(site_admin_client, site):
    url = f'/admin/sites/sites/{site.id}'
    response = get_resource(admin_app, site_admin, url)
    response = site_admin_client.get(url)
    assert response.status_code == 200


def test_create_form(admin_app, site_admin, brand):
def test_create_form(site_admin_client, brand):
    url = f'/admin/sites/sites/create/for_brand/{brand.id}'
    response = get_resource(admin_app, site_admin, url)
    response = site_admin_client.get(url)
    assert response.status_code == 200


def test_create(admin_app, site_admin, brand, email_config):
def test_create(site_admin_client, brand, email_config):
    site_id = 'partysite-99'
    title = 'Party 99'
    server_name = 'www.party99.example'


@@ 43,7 41,7 @@ def test_create(admin_app, site_admin, brand, email_config):
        'board_id': '',
        'storefront_id': '',
    }
    response = post_resource(admin_app, site_admin, url, form_data)
    response = site_admin_client.post(url, data=form_data)

    site = site_service.find_site(site_id)
    assert site is not None


@@ 59,20 57,7 @@ def test_create(admin_app, site_admin, brand, email_config):
    site_service.delete_site(site_id)


def test_update_form(admin_app, site_admin, site):
def test_update_form(site_admin_client, site):
    url = f'/admin/sites/sites/{site.id}/update'
    response = get_resource(admin_app, site_admin, url)
    response = site_admin_client.get(url)
    assert response.status_code == 200


# helpers


def get_resource(app, user, url):
    with http_client(app, user_id=user.id) as client:
        return client.get(url)


def post_resource(app, user, url, data):
    with http_client(app, user_id=user.id) as client:
        return client.post(url, data=data)

M tests/integration/blueprints/admin/ticketing/conftest.py => tests/integration/blueprints/admin/ticketing/conftest.py +5 -0
@@ 29,6 29,11 @@ def ticketing_admin(make_admin):


@pytest.fixture(scope='package')
def ticketing_admin_client(make_client, admin_app, ticketing_admin):
    return make_client(admin_app, user_id=ticketing_admin.id)


@pytest.fixture(scope='package')
def ticket_owner(make_user):
    return make_user('Ticket_Owner')


M tests/integration/blueprints/admin/ticketing/test_views.py => tests/integration/blueprints/admin/ticketing/test_views.py +10 -20
@@ 3,42 3,32 @@
:License: Modified BSD, see LICENSE for details.
"""

from tests.helpers import http_client


def test_ticket_index(admin_app, party, ticketing_admin, ticket):
def test_ticket_index(party, ticketing_admin_client, ticket):
    url = f'/admin/ticketing/tickets/for_party/{party.id}'
    response = get_resource(admin_app, ticketing_admin, url)
    response = ticketing_admin_client.get(url)
    assert response.status_code == 200


def test_ticket_view(admin_app, ticketing_admin, ticket):
def test_ticket_view(ticketing_admin_client, ticket):
    url = f'/admin/ticketing/tickets/{ticket.id}'
    response = get_resource(admin_app, ticketing_admin, url)
    response = ticketing_admin_client.get(url)
    assert response.status_code == 200


def test_appoint_user_form(admin_app, ticketing_admin, ticket):
def test_appoint_user_form(ticketing_admin_client, ticket):
    url = f'/admin/ticketing/tickets/{ticket.id}/appoint_user'
    response = get_resource(admin_app, ticketing_admin, url)
    response = ticketing_admin_client.get(url)
    assert response.status_code == 200


def test_bundle_index(admin_app, party, ticketing_admin, bundle):
def test_bundle_index(party, ticketing_admin_client, bundle):
    url = f'/admin/ticketing/bundles/for_party/{party.id}'
    response = get_resource(admin_app, ticketing_admin, url)
    response = ticketing_admin_client.get(url)
    assert response.status_code == 200


def test_bundle_view(admin_app, ticketing_admin, bundle):
def test_bundle_view(ticketing_admin_client, bundle):
    url = f'/admin/ticketing/bundles/{bundle.id}'
    response = get_resource(admin_app, ticketing_admin, url)
    response = ticketing_admin_client.get(url)
    assert response.status_code == 200


# helpers


def get_resource(app, user, url):
    with http_client(app, user_id=user.id) as client:
        return client.get(url)

M tests/integration/blueprints/admin/user_badges/conftest.py => tests/integration/blueprints/admin/user_badges/conftest.py +6 -1
@@ 10,7 10,7 @@ from byceps.services.user_badge import badge_service
from tests.helpers import login_user


@pytest.fixture(scope='module')
@pytest.fixture(scope='package')
def user_badge_admin(make_admin):
    permission_ids = {
        'admin.access',


@@ 24,6 24,11 @@ def user_badge_admin(make_admin):
    return admin


@pytest.fixture(scope='package')
def user_badge_admin_client(make_client, admin_app, user_badge_admin):
    return make_client(admin_app, user_id=user_badge_admin.id)


@pytest.fixture(scope='module')
def badge():
    slug = 'badge-of-beauty'

M tests/integration/blueprints/admin/user_badges/test_views.py => tests/integration/blueprints/admin/user_badges/test_views.py +10 -25
@@ 5,28 5,26 @@

from byceps.services.user_badge import badge_service

from tests.helpers import http_client


def test_index(admin_app, user_badge_admin):
def test_index(user_badge_admin_client):
    url = '/admin/user_badges/badges'
    response = get_resource(admin_app, user_badge_admin, url)
    response = user_badge_admin_client.get(url)
    assert response.status_code == 200


def test_view(admin_app, user_badge_admin, badge):
def test_view(user_badge_admin_client, badge):
    url = f'/admin/user_badges/badges/{badge.id}'
    response = get_resource(admin_app, user_badge_admin, url)
    response = user_badge_admin_client.get(url)
    assert response.status_code == 200


def test_create_form(admin_app, user_badge_admin):
def test_create_form(user_badge_admin_client):
    url = '/admin/user_badges/create'
    response = get_resource(admin_app, user_badge_admin, url)
    response = user_badge_admin_client.get(url)
    assert response.status_code == 200


def test_create(admin_app, user_badge_admin, brand):
def test_create(user_badge_admin_client, brand):
    slug = 'seal-of-resilience'
    label = 'Seal of Resilience'
    image_filename = 'seal-of-resilience.svg'


@@ 43,7 41,7 @@ def test_create(admin_app, user_badge_admin, brand):
        'brand_id': brand.id,
        'featured': 'Y',
    }
    response = post_resource(admin_app, user_badge_admin, url, form_data)
    response = user_badge_admin_client.post(url, data=form_data)

    badge = badge_service.find_badge_by_slug(slug)
    assert badge is not None


@@ 59,20 57,7 @@ def test_create(admin_app, user_badge_admin, brand):
    badge_service.delete_badge(badge.id)


def test_update_form(admin_app, user_badge_admin, badge):
def test_update_form(user_badge_admin_client, badge):
    url = f'/admin/user_badges/badges/{badge.id}/update'
    response = get_resource(admin_app, user_badge_admin, url)
    response = user_badge_admin_client.get(url)
    assert response.status_code == 200


# helpers


def get_resource(app, user, url):
    with http_client(app, user_id=user.id) as client:
        return client.get(url)


def post_resource(app, user, url, data):
    with http_client(app, user_id=user.id) as client:
        return client.post(url, data=data)