コード例 #1
0
class FinancialAidFactory(DjangoModelFactory):
    """
    Factory for FinancialAid
    """
    # user = SubFactory(UserFactory) is implied, since it is created in the cls.create() method
    tier_program = SubFactory(TierProgramFactory)
    status = FuzzyChoice(
        # the reset status is a special case, so removing it from the options
        [
            status for status in FinancialAidStatus.ALL_STATUSES
            if status != FinancialAidStatus.RESET
        ])
    income_usd = FuzzyFloat(low=0, high=12345)
    original_income = FuzzyFloat(low=0, high=12345)
    original_currency = Faker('currency_code')
    country_of_income = Faker('country_code')
    country_of_residence = Faker('country_code')
    date_exchange_rate = FuzzyDateTime(
        datetime.datetime(2000, 1, 1, tzinfo=UTC))
    date_documents_sent = FuzzyDate(datetime.date(2000, 1, 1))

    @classmethod
    def create(cls, **kwargs):
        """
        Overrides the default .create() method so that if no user is specified in kwargs, this factory
        will create a user with an associated profile without relying on signals.
        """
        if "user" not in kwargs:
            with mute_signals(post_save):
                profile = ProfileFactory.create()
            kwargs["user"] = profile.user
        return super().create(**kwargs)

    class Meta:
        model = FinancialAid
コード例 #2
0
ファイル: factories.py プロジェクト: Tiny-Hands/tinyhands
class LocationFactory(DjangoModelFactory):
    class Meta:
        model = Location

    name = factory.Sequence(lambda n: 'Location {0}'.format(n))
    latitude = FuzzyFloat(0, 20)
    longitude = FuzzyFloat(0, 20)
    border_station = factory.SubFactory(BorderStationFactory)
コード例 #3
0
ファイル: factories.py プロジェクト: vladimirdotk/backend
class VenueFactory(DjangoModelFactory):
    name = FuzzyText()
    address = FuzzyText()
    latitude = FuzzyFloat(low=-180.0, high=180.0)
    longitude = FuzzyFloat(low=-180.0, high=180.0)

    class Meta:
        model = 'events.Venue'
コード例 #4
0
ファイル: factories.py プロジェクト: jvastbinder/tinyhands
class CanonicalNameFactory(DjangoModelFactory):
    class Meta:
        model = Address2

    name = factory.Sequence(lambda n: 'Address2 cannon {0}'.format(n))
    latitude = FuzzyFloat(0, 20)
    longitude = FuzzyFloat(0, 20)
    address1 = factory.SubFactory(Address1Factory)
    canonical_name = None
    verified = FuzzyChoice([True, False])
コード例 #5
0
class ActivityTrackpointFactory(factory.DjangoModelFactory):
    class Meta:
        model = ActivityTrackpoint

    timepoint = factory.Sequence(lambda n: datetime(
        2014, 10, 10, floor(n / (60**2)), floor(n / 60), n % 60, tzinfo=utc))
    lat = FuzzyFloat(-180, 180)
    lon = FuzzyFloat(-180, 180)  # degrees
    sog = FuzzyFloat(0, 20)
    track = factory.SubFactory(ActivityTrackFactory)
コード例 #6
0
ファイル: test_helpers.py プロジェクト: Fingel/astrochallenge
class UserProfileFactory(factory.django.DjangoModelFactory):
    class Meta:
        model = UserProfile

    timezone = "UTC"
    location = "Santa Cruz"
    lat = FuzzyFloat(-90, 90)
    lng = FuzzyFloat(-180, 180)
    elevation = FuzzyInteger(0, 4000)
    profile_text = "Test user please ignore"
    recieve_notification_emails = True
    user = factory.SubFactory(
        'astrochallenge.accounts.test_helpers.UserFactory', userprofile=None)
コード例 #7
0
ファイル: test_helpers.py プロジェクト: Fingel/astrochallenge
class SolarSystemObjectFactory(factory.django.DjangoModelFactory):
    class Meta:
        model = SolarSystemObject

    name = FuzzyChoice(choices=['Juipter', 'Mars', 'Saturn'])
    type = FuzzyChoice(choices=settings.SOLAR_SYSTEM_OBJECT_TYPES)
    index = factory.Sequence(lambda n: n)
    description = FuzzyText(length=500)
    mass = FuzzyFloat(1, 10000)
    mass_unit = FuzzyChoice(choices=['s', 'e', 'j', 'kg'])
    points = FuzzyInteger(0, 100)
    image = None
    image_attribution = FuzzyText(length=50)
    magnitude = FuzzyFloat(-30, 90)
コード例 #8
0
class FinancialAidFactory(DjangoModelFactory):
    """
    Factory for FinancialAid
    """
    user = SubFactory(UserFactory)
    tier_program = SubFactory(TierProgramFactory)
    status = FuzzyChoice(FinancialAidStatus.ALL_STATUSES)
    income_usd = FuzzyFloat(low=0, high=12345)
    original_income = FuzzyFloat(low=0, high=12345)
    original_currency = FuzzyText(length=3)
    country_of_income = FuzzyText(length=2)
    date_exchange_rate = FuzzyDateTime(datetime.datetime(2000, 1, 1, tzinfo=UTC))

    class Meta:  # pylint: disable=missing-docstring
        model = FinancialAid
コード例 #9
0
ファイル: test_helpers.py プロジェクト: Fingel/astrochallenge
class ObservationFactory(factory.django.DjangoModelFactory):
    class Meta:
        model = Observation
        abstract = True

    date = FuzzyDate(start_date=datetime.date(2015, 1, 1))
    points_earned = FuzzyInteger(0, 100)
    lat = FuzzyFloat(-90, 90)
    lng = FuzzyFloat(-180, 180)
    seeing = FuzzyChoice(choices=['P', 'BA', 'A', 'AA', 'E'])
    light_pollution = FuzzyChoice(choices=['P', 'BA', 'A', 'AA', 'E'])
    description = FuzzyText(length=200)
    featured = FuzzyChoice(choices=[True, False])

    equipment = factory.SubFactory(EquipmentFactory)
    user_profile = factory.SubFactory(UserProfileFactory)
コード例 #10
0
class OrderItemFactory(Factory):
    class Meta:
        model = OrderItem

    product = SubFactory(factory=ProductFactory)
    price = FuzzyFloat(low=0.5, high=5000, precision=2)
    quantity = FuzzyInteger(low=1, high=50)
コード例 #11
0
class LocationFactory(DjangoModelFactory):
    class Meta:
        model = Location

    name = Sequence(lambda n: f"name{n}")
    location = FuzzyPoint()
    elevation = FuzzyFloat(0, 100)
コード例 #12
0
ファイル: factories.py プロジェクト: maccinza/tech-challenge
class TransactionFactory(DjangoModelFactory):
    company = SubFactory(CompanyFactory)
    client = FuzzyAttribute(cpf_with_punctuation)
    value = FuzzyFloat(MIN_VALUE, high=MAX_VALUE, precision=2)
    description = Faker("catch_phrase", locale="pt_BR")

    class Meta:
        model = Transaction
コード例 #13
0
class DealFactory(factory.django.DjangoModelFactory):
    customer = factory.SubFactory("users.tests.factories.UserFactory")
    rider = factory.SubFactory("users.tests.factories.UserFactory")
    junk_point = factory.SubFactory("junk.tests.factories.JunkPointFactory")
    price = FuzzyFloat(low=1, high=9999.99)

    class Meta:
        model = "junk.Deal"
コード例 #14
0
ファイル: test_helpers.py プロジェクト: Fingel/astrochallenge
class AstroObjectFactory(factory.django.DjangoModelFactory):
    class Meta:
        model = AstroObject

    type = FuzzyChoice(choices=[
        u'Asterism', u'Double Star', u'Galaxy', u'Globular Cluster', u'Nebula',
        u'Nebulosity in External Galaxy', u'Open Cluster', u'Planetary Nebula',
        u'Star', u'Supernova Remnant', u'Triple Star'
    ])
    index = factory.Sequence(lambda n: n)
    ra_hours = FuzzyFloat(0.0, 23.0)
    ra_minutes = FuzzyFloat(0.0, 59.0)
    ra_seconds = FuzzyFloat(0.0, 59.0)
    dec_sign = FuzzyChoice(choices=['+', '-'])
    dec_deg = FuzzyInteger(0, 89)
    dec_min = FuzzyFloat(0.0, 59.0)
    dec_seconds = FuzzyFloat(0.0, 59)
    magnitude = FuzzyFloat(-4.0, 14)
    size = FuzzyFloat(0.1, 10000.0)
    distance = FuzzyInteger(1, 1000000000)
    details = FuzzyText(length=40)
    description = FuzzyText(length=500)
    common_name = factory.Sequence(lambda n: "NGC{0}".format(n))
    points = FuzzyInteger(0, 100)
    image = None
    image_attribution = FuzzyText(length=50)
    discoverer = FuzzyText(length=20)
    discovery_date = FuzzyDate(start_date=datetime.date(1700, 1, 1))

    constellation = factory.SubFactory(ConstellationFactory)
コード例 #15
0
ファイル: test_helpers.py プロジェクト: Fingel/astrochallenge
class SupernovaMagnitudeFactory(factory.django.DjangoModelFactory):
    class Meta:
        model = SupernovaMagnitude

    magnitude = FuzzyFloat(-2.0, 4.0)
    time = FuzzyDateTime(start_dt=timezone.now() - datetime.timedelta(days=29),
                         end_dt=timezone.now())

    supernova = factory.SubFactory(SupernovaFactory)
コード例 #16
0
class PromotionFactory(factory.Factory):
    """ Creates fake promotions that you don't have to feed """
    class Meta:
        model = Promotion

    id = factory.Sequence(lambda n: n)
    productid = FuzzyInteger(0, 9999)
    category = FuzzyChoice(choices=['dollar', 'percentage', 'BOGO', 'BOHO'])
    available = FuzzyChoice(choices=[True, False])
    discount = FuzzyFloat(50)
コード例 #17
0
ファイル: profile.py プロジェクト: kerbez/beta_career
class ProfileFactory(factory.Factory):
    class Meta:
        model = Profile

    user = UserFactory()
    course = FuzzyInteger(1, 4).fuzz()
    gpa = FuzzyFloat(0.0, 4.0).fuzz()
    birth_date = FuzzyDate(datetime.date(1996, 1, 1),
                           datetime.date(2003, 1, 1)).fuzz()
    linked_in = factory.Sequence(lambda n: f"google.com/user_{n}")
コード例 #18
0
class FinalGradeFactory(DjangoModelFactory):
    """Factory for FinalGrade"""
    user = SubFactory(UserFactory)
    course_run = SubFactory(CourseRunFactory)
    grade = FuzzyFloat(low=0, high=1)
    passed = Faker('boolean')
    status = FinalGradeStatus.COMPLETE
    course_run_paid_on_edx = Faker('boolean')

    class Meta:  # pylint: disable=missing-docstring,no-init,too-few-public-methods,old-style-class
        model = FinalGrade
コード例 #19
0
class CartItemFactory(factory.Factory):
    """ Creates fake CartItems """

    class Meta:
        model = CartItem

    id = factory.Sequence(lambda n: n)
    shopcart_id = factory.Sequence(lambda n: n)
    item_name = FuzzyChoice(choices=["pants", "shirt", "shoes"])
    sku = FuzzyChoice(choices=["1A3B", "2A94", "4PT3", "4DW2", "00A2","0992", "112A", "APC1"])
    quantity = FuzzyInteger(0, 50, step=1)
    price = FuzzyFloat(0.5, 100.5)
コード例 #20
0
class CreditFactory(ProductFactory):
    residue = FuzzyInteger(1000, 100000)
    current_penalty = FuzzyInteger(100, 1000)
    next_payment_term = factory.sequence(lambda n: fake.date())
    duration = factory.sequence(lambda n: fake.pyint())
    start_date = factory.sequence(lambda n: fake.date())
    status = FuzzyChoice(dict(Credit.STATUS_CHOICES))
    fine_percentage = FuzzyFloat(100)
    method_of_ensuring = FuzzyChoice(dict(CreditTemplate.ENSURING_CHOICES))
    money_destination = FuzzyChoice(dict(Credit.MONEY_DESTINATION))
    template = factory.SubFactory('finance.factories.CreditTemplateFactory')

    class Meta:
        model = Credit
コード例 #21
0
class ProductFactory(factory.Factory):
    """ Creates fake products """
    class Meta:
        model = Product

    id = factory.Sequence(lambda n: n)
    name = factory.Faker("first_name")
    available = FuzzyChoice(choices=[True, False])
    price = FuzzyFloat(0.5, 100.5)
    stock = FuzzyInteger(0, 100)
    size = FuzzyChoice(choices=["L", "M", "S"])
    color = FuzzyChoice(choices=["blue", "yellow", "red"])
    category = FuzzyChoice(choices=["paper", "electronics", "food"])
    sku = "00000000"
    description = "test description"
コード例 #22
0
ファイル: tests.py プロジェクト: doanguyen/technical-test
class InvestmentFactory(DjangoModelFactory):
    codeuai = factory.Faker('bothify', text="??##??#?")
    longitude = factory.Faker('longitude')
    lycee = factory.Faker('company', locale="fr_FR")
    ville = factory.Faker('city', locale="fr_FR")
    ppi = factory.Faker('bothify', text="200#/201#")
    annee_d_individualisation = faker.random_int(min=1900, max=2020)
    titreoperation = factory.Faker('paragraph')
    enveloppe_prev_en_meu = FuzzyFloat(0.5, 24, precision=4)
    montant_des_ap_votes_en_meu = FuzzyFloat(0.2, 12, precision=4)
    mandataire = factory.Faker('sentence', nb_words=10)
    maitrise_d_oeuvre = factory.Faker('paragraph')
    notification_du_marche = FuzzyDate(datetime.date(2010, 1, 1),
                                       datetime.date(2021, 1, 1))
    entreprise = factory.Faker('city', locale="fr_FR")
    mode_de_devolution = factory.Faker('sentence', nb_words=10)
    nombre_de_lots = faker.random_int(min=0, max=20)
    cao_attribution = FuzzyDate(datetime.date(2010, 1, 1),
                                datetime.date(2021, 1, 1))
    etat_d_avancement = factory.Faker('sentence', nb_words=10)
    annee_de_livraison = faker.random_int(min=1900, max=2020)

    class Meta:
        model = Investment
コード例 #23
0
class ProctoredExamGradeFactory(DjangoModelFactory):
    """Factory for ProctoredExamGrade"""
    user = SubFactory(UserFactory)
    course = SubFactory(CourseFactory)
    exam_run = SubFactory(ExamRunFactory)
    exam_date = FuzzyDateTime(now_in_utc() - datetime.timedelta(weeks=4))
    # this assumes that the max score is 100
    passing_score = 60.0
    score = LazyAttribute(lambda x: x.percentage_grade * 100)
    grade = LazyAttribute(lambda x: EXAM_GRADE_PASS if x.passed else EXAM_GRADE_FAIL)
    client_authorization_id = FuzzyText()
    row_data = {"From factory": True}
    passed = Faker('boolean')
    percentage_grade = FuzzyFloat(low=0, high=1)

    class Meta:  # pylint: disable=missing-docstring,no-init,too-few-public-methods
        model = ProctoredExamGrade
コード例 #24
0
ファイル: order_factory.py プロジェクト: themp731/orders
class OrderItemFactory(factory.Factory):
    """ Creates fake order items to go with an order"""
    class Meta:
        model = OrderItem

    id = factory.Sequence(lambda n: n + 1)
    order_id = factory.SubFactory(OrderFactory)
    product_id = FuzzyInteger(1, len(PRODUCTS) - 1)
    name = factory.LazyAttribute(lambda o: get_product_name(o.product_id))
    quantity = FuzzyInteger(1, 3)
    price = FuzzyFloat(0.01, 99, precision=4)

    @factory.post_generation
    def order_id(self, create, extracted, **kwargs):
        if not create:
            return

        self.order_id = extracted
コード例 #25
0
ファイル: test_helpers.py プロジェクト: Fingel/astrochallenge
class SupernovaFactory(factory.django.DjangoModelFactory):
    class Meta:
        model = Supernova

    sntype = FuzzyChoice(choices=[u'Ia', u'II', u'IIb'])
    ra_hours = FuzzyFloat(0.0, 23.0)
    ra_minutes = FuzzyFloat(0.0, 59.0)
    ra_seconds = FuzzyFloat(0.0, 59.0)
    dec_sign = FuzzyChoice(choices=['+', '-'])
    dec_deg = FuzzyInteger(0, 89)
    dec_min = FuzzyFloat(0.0, 59.0)
    dec_seconds = FuzzyFloat(0.0, 59)
    z = FuzzyFloat(0, 0.5)
    name = factory.Sequence(lambda n: "SN/{0}".format(n))
    points = FuzzyInteger(0, 100)
    date_added = timezone.now()
    discovery_date = FuzzyDateTime(start_dt=timezone.now() -
                                   datetime.timedelta(days=29),
                                   end_dt=timezone.now())

    astro_object = factory.SubFactory(AstroObjectFactory)
コード例 #26
0
def get_puntje():
    lon = FuzzyFloat(BBOX[0], BBOX[2]).fuzz()
    lat = FuzzyFloat(BBOX[1], BBOX[3]).fuzz()
    return Point(float(lon), float(lat))
コード例 #27
0
class ProductFactory(Factory):
    class Meta:
        model = Product

    name = FuzzyText(prefix="product-", length=10)
    price = FuzzyFloat(low=0.5, high=5000, precision=2)
コード例 #28
0
 def test_trash_volume_validation(self):
     """Trash volume cannot be below 0"""
     low = FuzzyFloat(-10, -0.1)
     trash = TrashFactory(gallons=low)
     self.assertRaises(ValidationError, trash.clean_fields)