
import pytest

from byceps.services.email import service as email_service
from byceps.services.shop.cart.models import Cart
from byceps.services.shop.sequence import service as sequence_service
from byceps.services.shop.shop import service as shop_service

from testfixtures.shop_order import create_orderer

from tests.helpers import create_user_with_detail


@pytest.fixture
def email_config():
    config_id = 'email-config-01'
    sender_address = 'info@shop.example'

    email_service.set_config(config_id, sender_address)

    return email_service.get_config(config_id)


@pytest.fixture
def shop(email_config):
    return shop_service.create_shop('shop-01', 'Some Shop', email_config.id)


@pytest.fixture
def orderer(normal_user):
    user = create_user_with_detail('Besteller')
    return create_orderer(user)


@pytest.fixture
def empty_cart() -> Cart:
    return Cart()


@pytest.fixture
def order_number_sequence(shop) -> None:
    sequence_service.create_order_number_sequence(shop.id, 'order-')


import pytest

from byceps.services.email import service as email_service
from byceps.services.shop.cart.models import Cart
from byceps.services.shop.sequence import service as sequence_service
from byceps.services.shop.shop import service as shop_service

from testfixtures.shop_order import create_orderer

from tests.helpers import create_user_with_detail


@pytest.fixture(scope='session')
def make_email_config():

    def _wrapper():
        config_id = 'email-config-01'
        sender_address = 'info@shop.example'

        email_service.set_config(config_id, sender_address)

        return email_service.get_config(config_id)

    return _wrapper


@pytest.fixture
def email_config(make_email_config):
    return make_email_config()


@pytest.fixture
def shop(email_config):
    return shop_service.create_shop('shop-01', 'Some Shop', email_config.id)


@pytest.fixture
def orderer(normal_user):
    user = create_user_with_detail('Besteller')
    return create_orderer(user)


@pytest.fixture
def empty_cart() -> Cart:
    return Cart()


@pytest.fixture
def order_number_sequence(shop) -> None:
    sequence_service.create_order_number_sequence(shop.id, 'order-')

Introduce factory for email config fixture
Introduce factory for email config fixture

This allows to create local fixtures that use email config with a
broader scope than 'function'.

  
  import pytest
  
  from byceps.services.email import service as email_service
  from byceps.services.shop.cart.models import Cart
  from byceps.services.shop.sequence import service as sequence_service
  from byceps.services.shop.shop import service as shop_service
  
  from testfixtures.shop_order import create_orderer
  
  from tests.helpers import create_user_with_detail
  
  
+ @pytest.fixture(scope='session')
+ def make_email_config():
+ 
+     def _wrapper():
+         config_id = 'email-config-01'
+         sender_address = 'info@shop.example'
+ 
+         email_service.set_config(config_id, sender_address)
+ 
+         return email_service.get_config(config_id)
+ 
+     return _wrapper
+ 
+ 
  @pytest.fixture
+ def email_config(make_email_config):
+     return make_email_config()
- def email_config():
-     config_id = 'email-config-01'
-     sender_address = 'info@shop.example'
- 
-     email_service.set_config(config_id, sender_address)
- 
-     return email_service.get_config(config_id)
  
  
  @pytest.fixture
  def shop(email_config):
      return shop_service.create_shop('shop-01', 'Some Shop', email_config.id)
  
  
  @pytest.fixture
  def orderer(normal_user):
      user = create_user_with_detail('Besteller')
      return create_orderer(user)
  
  
  @pytest.fixture
  def empty_cart() -> Cart:
      return Cart()
  
  
  @pytest.fixture
  def order_number_sequence(shop) -> None:
      sequence_service.create_order_number_sequence(shop.id, 'order-')
  
Introduce factory for email config fixture
## Code Before:

import pytest

from byceps.services.email import service as email_service
from byceps.services.shop.cart.models import Cart
from byceps.services.shop.sequence import service as sequence_service
from byceps.services.shop.shop import service as shop_service

from testfixtures.shop_order import create_orderer

from tests.helpers import create_user_with_detail


@pytest.fixture
def email_config():
    config_id = 'email-config-01'
    sender_address = 'info@shop.example'

    email_service.set_config(config_id, sender_address)

    return email_service.get_config(config_id)


@pytest.fixture
def shop(email_config):
    return shop_service.create_shop('shop-01', 'Some Shop', email_config.id)


@pytest.fixture
def orderer(normal_user):
    user = create_user_with_detail('Besteller')
    return create_orderer(user)


@pytest.fixture
def empty_cart() -> Cart:
    return Cart()


@pytest.fixture
def order_number_sequence(shop) -> None:
    sequence_service.create_order_number_sequence(shop.id, 'order-')

## Instruction:
Introduce factory for email config fixture
## Code After:

import pytest

from byceps.services.email import service as email_service
from byceps.services.shop.cart.models import Cart
from byceps.services.shop.sequence import service as sequence_service
from byceps.services.shop.shop import service as shop_service

from testfixtures.shop_order import create_orderer

from tests.helpers import create_user_with_detail


@pytest.fixture(scope='session')
def make_email_config():

    def _wrapper():
        config_id = 'email-config-01'
        sender_address = 'info@shop.example'

        email_service.set_config(config_id, sender_address)

        return email_service.get_config(config_id)

    return _wrapper


@pytest.fixture
def email_config(make_email_config):
    return make_email_config()


@pytest.fixture
def shop(email_config):
    return shop_service.create_shop('shop-01', 'Some Shop', email_config.id)


@pytest.fixture
def orderer(normal_user):
    user = create_user_with_detail('Besteller')
    return create_orderer(user)


@pytest.fixture
def empty_cart() -> Cart:
    return Cart()


@pytest.fixture
def order_number_sequence(shop) -> None:
    sequence_service.create_order_number_sequence(shop.id, 'order-')
