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='####')

workspace_key class-attribute instance-attribute

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

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')

workspace_key class-attribute instance-attribute

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

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("Provided external ID"):
        CardHolderFactory.create(
            workspace_key="WORKSPACE_KEY",
            external_id="123",
            first_name="John",
            last_name="Doe",
        )

    with subtests.test("Missing external ID"):
        CardHolderFactory.create(
            workspace_key="WORKSPACE_KEY",
            first_name="John",
            last_name="Doe",
        )

    with subtests.test("Duplicate external ID"):
        with pytest.raises(IntegrityError):
            CardHolderFactory.create(
                workspace_key="WORKSPACE_KEY",
                external_id="123",
                first_name="John",
                last_name="Doe",
            )

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