Skip to content

Test helpers

components.payment_gateway.subcomponents.cards.models.tests.factories

CardFactory

Bases: AlanBaseFactory[Card]

Meta

model class-attribute instance-attribute
model = Card

display_name class-attribute instance-attribute

display_name = Faker('name')

expiration_date class-attribute instance-attribute

expiration_date = Faker('future_date', end_date='+3y')

external_id class-attribute instance-attribute

external_id = Faker('random_string', length=16)

is_virtual class-attribute instance-attribute

is_virtual = Faker('boolean')

issued_at class-attribute instance-attribute

issued_at = LazyFunction(now)

last_four_digits class-attribute instance-attribute

last_four_digits = Faker('numerify', text='####')

provider class-attribute instance-attribute

provider = adyen

CardHolderFactory

Bases: AlanBaseFactory[CardHolder]

Meta

model class-attribute instance-attribute
model = CardHolder

first_name class-attribute instance-attribute

first_name = Faker('first_name')

last_name class-attribute instance-attribute

last_name = Faker('last_name')

provider class-attribute instance-attribute

provider = adyen

CardOrderFactory

Bases: AlanBaseFactory[CardOrder]

Meta

model class-attribute instance-attribute
model = CardOrder

card class-attribute instance-attribute

card = SubFactory(CardFactory)

delivery_status class-attribute instance-attribute

delivery_status = Faker(
    "random_element", elements=get_values()
)

shipping_method class-attribute instance-attribute

shipping_method = Faker(
    "random_element",
    elements=[
        "dhlGlobalMailTracked",
        "dhlInternationalExpressLetter",
    ],
)

components.payment_gateway.subcomponents.cards.models.tests.test_card_holder

test_card_holder_model_contraints

test_card_holder_model_contraints(subtests)
Source code in components/payment_gateway/subcomponents/cards/models/tests/test_card_holder.py
@pytest.mark.usefixtures("db")
def test_card_holder_model_contraints(subtests):
    with subtests.test("External id is forbidden for Adyen"):
        with pytest.raises(IntegrityError):
            CardHolderFactory.create(
                first_name="John",
                last_name="Doe",
                provider=PaymentServiceProvider.adyen,
                external_id="123",
            )

    with subtests.test("External id is enabled for Swan"):
        CardHolderFactory.create(
            first_name="John",
            last_name="Doe",
            provider=PaymentServiceProvider.swan,
            external_id="123",
        )

    with subtests.test("External should be unique for Swan"):
        with pytest.raises(IntegrityError):
            CardHolderFactory.create(
                first_name="John",
                last_name="Doe",
                provider=PaymentServiceProvider.swan,
                external_id="123",
            )

    with subtests.test("We can store several card holders without external id"):
        CardHolderFactory.create(
            first_name="John", last_name="Doe", provider=PaymentServiceProvider.adyen
        )
        CardHolderFactory.create(
            first_name="Jane", last_name="Doe", provider=PaymentServiceProvider.adyen
        )