Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
2.2 kB
7
Indexable
Never
import datetime
import uuid

from typing import Type

import factory
import pytest

from app.adapter.db import model


@pytest.fixture
def quote_factory(db) -> Type["QuoteFactory"]:
    class QuoteFactory(factory.alchemy.SQLAlchemyModelFactory):
        class Meta:
            model = model.Quote
            sqlalchemy_session = db.session

        id = factory.LazyAttribute(lambda n: str(uuid.uuid4()))
        eclipse_reference = factory.Faker("name")
        underwriter_name = factory.Faker("name")
        insured_name = factory.Faker("name")
        reinsured_name = factory.Faker("name")
        broker_name = factory.Faker("name")
        product_code = factory.Faker("name")
        inception_date = datetime.datetime.now()
        expiry_date = datetime.datetime.now()
        cal_quake_included = True
        policy_term = 1
        status = "draft"
        year_of_account = 2022

    return QuoteFactory


@pytest.fixture
def country_factory(db) -> Type["CountryFactory"]:
    class CountryFactory(factory.alchemy.SQLAlchemyModelFactory):
        class Meta:
            model = model.Country
            sqlalchemy_session = db.session

        code = factory.Iterator(['US', 'CA', 'UK'])
        name = factory.Iterator(["United States", "Canada", "United Kingdom"]) 

    return CountryFactory


@pytest.fixture
def state_factory(db) -> Type["StateFactory"]:
    class StateFactory(factory.alchemy.SQLAlchemyModelFactory):
        class Meta:
            model = model.State
            sqlalchemy_session = db.session
            
        code = factory.Iterator(['AL', 'AK', 'AZ'])
        name = factory.Iterator(["Alabama", "Alaska", "Arizona"])
        country_id = factory.Iterator([1, 1, 1,])

    return StateFactory


@pytest.fixture
def county_factory(db) -> Type["CountyFactory"]:
    class CountyFactory(factory.alchemy.SQLAlchemyModelFactory):
        class Meta:
            model = model.County
            sqlalchemy_session = db.session
            
        code = factory.Iterator(['01001', '01003', '01005'])
        name = factory.Iterator(["Autauga County", "Baldwin County", "Barbour County"])
        state_id = factory.Iterator([1, 1, 1,])

    return CountyFactory