Esempio n. 1
0
class RecipientFactory(DjangoModelFactory):
    name = LazyAttribute(lambda o: faker.name())
    email_address = LazyAttribute(lambda o: unicodedata.normalize(
        'NFD', faker.safe_email()).encode('ascii', 'ignore'))

    class Meta:
        model = Recipient
Esempio n. 2
0
class SocialMediaFactory(DjangoModelFactory):
    name = LazyAttribute(lambda o: random.choice(social_media.keys()))  # Only currently supported social media
    username = LazyAttribute(lambda o: unicodedata.normalize('NFD', faker.user_name()).encode('ascii', 'ignore'))
    profile_url = LazyAttribute(lambda o: social_media[o.name] % o.username)

    class Meta:
        model = SocialMedia
Esempio n. 3
0
class AccountFactory(DjangoModelFactory):
    tenant = SubFactory(TenantFactory)
    name = LazyAttribute(lambda o: faker.company())
    description = LazyAttribute(lambda o: faker.bs())
    status = SubFactory(AccountStatusFactory, tenant=SelfAttribute('..tenant'))

    @factory.post_generation
    def phone_numbers(self, create, extracted, **kwargs):
        phone_str = faker.phone_number()
        if create:
            phone_number = PhoneNumberFactory(tenant=self.tenant,
                                              number=phone_str)
            self.phone_numbers.add(phone_number)

    @factory.post_generation
    def websites(self, create, extracted, **kwargs):

        if not create:
            return

        size = extracted.get('size', 1) if extracted else 1
        WebsiteFactory.create_batch(size=size,
                                    account=self,
                                    tenant=self.tenant)

    class Meta:
        model = Account
Esempio n. 4
0
class ContactFactory(DjangoModelFactory):
    tenant = SubFactory(TenantFactory)
    first_name = LazyAttribute(lambda o: faker.first_name())
    last_name = LazyAttribute(lambda o: faker.last_name())

    class Meta:
        model = Contact
Esempio n. 5
0
class DealFactory(DjangoModelFactory):
    tenant = SubFactory(TenantFactory)
    account = SubFactory(AccountFactory, tenant=SelfAttribute('..tenant'))
    contact = SubFactory(ContactFactory, tenant=SelfAttribute('..tenant'))
    amount_once = FuzzyDecimal(42.7)
    amount_recurring = FuzzyDecimal(42.7)
    assigned_to = SubFactory(LilyUserFactory, tenant=SelfAttribute('..tenant'))
    card_sent = FuzzyChoice([True, False])
    contacted_by = SubFactory(DealContactedByFactory,
                              tenant=SelfAttribute('..tenant'))
    currency = FuzzyChoice(dict(CURRENCIES).keys())
    found_through = SubFactory(DealFoundThroughFactory,
                               tenant=SelfAttribute('..tenant'))
    is_checked = FuzzyChoice([True, False])
    name = LazyAttribute(lambda o: faker.word())
    new_business = FuzzyChoice([True, False])
    next_step = SubFactory(DealNextStepFactory,
                           tenant=SelfAttribute('..tenant'))
    next_step_date = FuzzyDate(past_date, future_date)
    status = SubFactory(DealStatusFactory, tenant=SelfAttribute('..tenant'))
    twitter_checked = FuzzyChoice([True, False])
    why_customer = SubFactory(DealWhyCustomerFactory,
                              tenant=SelfAttribute('..tenant'))
    why_lost = SubFactory(DealWhyLostFactory, tenant=SelfAttribute('..tenant'))
    closed_date = LazyAttribute(
        lambda o: faker.date_time_between_dates(past_date, current_date, utc)
        if o.status.is_won or o.status.is_lost else None)

    class Meta:
        model = Deal
Esempio n. 6
0
class EmailMessageFactory(DjangoModelFactory):
    subject = LazyAttribute(lambda o: faker.word())
    sender = SubFactory(RecipientFactory)
    body_text = LazyAttribute(lambda o: faker.text())
    sent_date = LazyAttribute(
        lambda o: faker.date_time_between_dates(past_date, current_date, utc))
    account = SubFactory(EmailAccountFactory)
    message_id = FuzzyText()

    @post_generation
    def received_by(self, create, extracted, **kwargs):
        if not create:
            # Simple build, do nothing.
            return

        if extracted:
            if isinstance(extracted, Recipient):
                # A single team was passed in, use that.
                self.received_by.add(extracted)
            else:
                # A list of teams were passed in, use them.
                for recipient in extracted:
                    self.received_by.add(recipient)

    class Meta:
        model = EmailMessage
Esempio n. 7
0
class LilyUserFactory(DjangoModelFactory):
    tenant = SubFactory(TenantFactory)
    password = make_password('admin')

    first_name = LazyAttribute(lambda o: faker.first_name())
    last_name = LazyAttribute(lambda o: faker.last_name())
    email = LazyAttribute(lambda o: unicodedata.normalize(
        'NFD', faker.safe_email()).encode('ascii', 'ignore'))
    is_active = LazyAttribute(lambda o: bool(randint(0, 1)))

    phone_number = LazyAttribute(lambda o: faker.phone_number())

    language = FuzzyChoice(dict(LANGUAGES).keys())
    timezone = FuzzyChoice(dict(TimeZoneField.CHOICES).values())

    @post_generation
    def teams(self, create, extracted, **kwargs):
        if not create:
            # Simple build, do nothing.
            return

        if extracted:
            if isinstance(extracted, Team):
                # A single team was passed in, use that.
                self.teams.add(extracted)
            else:
                # A list of teams were passed in, use them.
                for team in extracted:
                    self.teams.add(team)

    class Meta:
        model = LilyUser
Esempio n. 8
0
class CallParticipantFactory(DjangoModelFactory):
    tenant = SubFactory(TenantFactory)
    number = LazyAttribute(lambda o: faker.phone_number())
    name = LazyAttribute(lambda o: faker.name())
    internal_number = FuzzyInteger(200, 999)

    class Meta:
        model = CallParticipant
Esempio n. 9
0
class SocialMediaFactory(DjangoModelFactory):
    name = LazyAttribute(
        lambda o: random.choice(SocialMedia.SOCIAL_NAME_CHOICES)[0])
    username = LazyAttribute(lambda o: faker.user_name())
    profile_url = LazyAttribute(lambda o: faker.uri())

    class Meta:
        model = SocialMedia
Esempio n. 10
0
class AddressFactory(DjangoModelFactory):
    address = LazyAttribute(lambda o: faker.street_address())
    postal_code = LazyAttribute(lambda o: faker.postcode())
    city = LazyAttribute(lambda o: faker.city())
    state_province = LazyAttribute(lambda o: faker.province())
    country = FuzzyChoice(dict(COUNTRIES).keys())
    type = FuzzyChoice(dict(Address.ADDRESS_TYPE_CHOICES).keys())

    class Meta:
        model = Address
Esempio n. 11
0
class CallFactory(DjangoModelFactory):
    unique_id = FuzzyText()
    called_number = LazyAttribute(lambda o: faker.phone_number())
    caller_number = LazyAttribute(lambda o: faker.phone_number())
    internal_number = FuzzyInteger(200, 999)
    status = FuzzyChoice(dict(Call.CALL_STATUS_CHOICES).keys())
    type = FuzzyChoice(dict(Call.CALL_TYPE_CHOICES).keys())

    class Meta:
        model = Call
Esempio n. 12
0
class ContactFactory(DjangoModelFactory):
    tenant = SubFactory(TenantFactory)
    first_name = LazyAttribute(lambda o: faker.first_name())
    last_name = LazyAttribute(lambda o: faker.last_name())
    gender = FuzzyChoice(dict(Contact.CONTACT_GENDER_CHOICES).keys())
    title = LazyAttribute(lambda o: faker.word())
    description = LazyAttribute(lambda o: faker.text())
    salutation = FuzzyChoice(dict(Contact.SALUTATION_CHOICES).keys())

    class Meta:
        model = Contact
Esempio n. 13
0
class EmailAccountFactory(DjangoModelFactory):
    tenant = SubFactory(TenantFactory)
    owner = SubFactory(LilyUserFactory, tenant=SelfAttribute('..tenant'))
    email_address = email_address
    from_name = LazyAttribute(lambda o: faker.name())
    label = LazyAttribute(lambda o: faker.word())
    is_authorized = True
    privacy = FuzzyChoice(dict(EmailAccount.PRIVACY_CHOICES).keys())

    class Meta:
        model = EmailAccount
Esempio n. 14
0
class EmailAccountFactory(DjangoModelFactory):
    tenant = SubFactory(TenantFactory)
    owner = SubFactory(LilyUserFactory)
    email_address = LazyAttribute(lambda o: unicodedata.normalize(
        'NFD', faker.safe_email()).encode('ascii', 'ignore'))
    from_name = LazyAttribute(lambda o: faker.name())
    label = LazyAttribute(lambda o: faker.word())
    is_authorized = True
    privacy = FuzzyChoice(dict(EmailAccount.PRIVACY_CHOICES).keys())

    class Meta:
        model = EmailAccount
Esempio n. 15
0
class BeneficiaryGrant18Factory(BaseFactory):
    class Meta:
        model = pcapi.core.users.models.User

    email = factory.Sequence("jeanne.doux{}@example.com".format)
    address = factory.Sequence("{} rue des machines".format)
    city = "Paris"
    dateCreated = LazyAttribute(lambda _: datetime.utcnow())
    dateOfBirth = LazyAttribute(  # LazyAttribute to allow freez_time overrides
        lambda _: datetime.combine(date.today(), time(0, 0)) - relativedelta(
            years=users_constants.ELIGIBILITY_AGE_18, months=1))
    departementCode = "75"
    firstName = "Jeanne"
    lastName = "Doux"
    isEmailValidated = True
    isAdmin = False
    roles = [pcapi.core.users.models.UserRole.BENEFICIARY]
    hasSeenProTutorials = True

    @classmethod
    def _create(cls, model_class, *args, **kwargs):
        password = kwargs.get("password", DEFAULT_PASSWORD)
        kwargs["password"] = crypto.hash_password(password)
        if "publicName" not in kwargs and kwargs["firstName"] and kwargs[
                "lastName"]:
            kwargs["publicName"] = "%s %s" % (kwargs["firstName"],
                                              kwargs["lastName"])
        instance = super()._create(model_class, *args, **kwargs)
        instance.clearTextPassword = DEFAULT_PASSWORD
        return instance

    @classmethod
    def _build(cls, model_class, *args, **kwargs):
        password = kwargs.get("password", DEFAULT_PASSWORD)
        kwargs["password"] = crypto.hash_password(password)
        if "publicName" not in kwargs and kwargs["firstName"] and kwargs[
                "lastName"]:
            kwargs["publicName"] = "%s %s" % (kwargs["firstName"],
                                              kwargs["lastName"])
        instance = super()._build(model_class, *args, **kwargs)
        instance.clearTextPassword = DEFAULT_PASSWORD
        return instance

    @factory.post_generation
    def deposit(obj, create, extracted, **kwargs):  # pylint: disable=no-self-argument
        if not create:
            return None

        if "dateCreated" not in kwargs:
            kwargs["dateCreated"] = obj.dateCreated

        return DepositGrantFactory(user=obj, **kwargs)
Esempio n. 16
0
class ExamAttemptFactory(DjangoModelFactory):
	class Meta:
		model = ExamAttempt

	student = SubFactory(StudentFactory)
	quiz = SubFactory(ExamFactory)
	score = 0

	guess1 = LazyAttribute(lambda o: o.quiz.answer1)
	guess2 = LazyAttribute(lambda o: o.quiz.answer2)
	guess3 = LazyAttribute(lambda o: o.quiz.answer3)
	guess4 = LazyAttribute(lambda o: o.quiz.answer4)
	guess5 = LazyAttribute(lambda o: o.quiz.answer5)
Esempio n. 17
0
class NummeraanduidingFactory(DjangoModelFactory):
    class Meta:
        model = models.Nummeraanduiding

    id = fuzzy.FuzzyText(length=14, chars=string.digits)
    landelijk_id = fuzzy.FuzzyText(length=16, chars=string.digits)
    huisnummer = LazyAttribute(lambda o: int(faker_instance.building_number()))
    openbare_ruimte = SubFactory(OpenbareRuimteFactory)
    verblijfsobject = SubFactory(VerblijfsobjectFactory)
    type = '01'  # default verblijfsobject
    postcode = '1000AN'  # default postcode..

    _openbare_ruimte_naam = LazyAttribute(lambda o: o.openbare_ruimte.naam)
Esempio n. 18
0
class AccountFactory(DjangoModelFactory):
    tenant = factory.SubFactory(TenantFactory)
    name = LazyAttribute(lambda o: faker.company())
    description = LazyAttribute(lambda o: faker.bs())

    @factory.post_generation
    def phone_numbers(self, create, extracted, **kwargs):
        phone_str = faker.phone_number()
        if create:
            phone_number = PhoneNumberFactory(tenant=self.tenant, raw_input=phone_str)
            self.phone_numbers.add(phone_number)

    class Meta:
        model = Account
Esempio n. 19
0
class EmailDraftFactory(DjangoModelFactory):
    tenant = SubFactory(TenantFactory)
    send_from = SubFactory(EmailAccountFactory,
                           tenant=SelfAttribute('..tenant'))
    to = email_addresses
    cc = email_addresses
    bcc = email_addresses

    subject = LazyAttribute(lambda o: faker.word())
    body = LazyAttribute(lambda o: faker.text())

    mapped_attachments = FuzzyInteger(0, 5)

    class Meta:
        model = EmailDraft
Esempio n. 20
0
class CallRecordFactory(DjangoModelFactory):
    tenant = SubFactory(TenantFactory)
    call_id = FuzzyText(length=40)
    start = LazyAttribute(lambda o: faker.date_time(tzinfo=UTC))
    end = LazyAttribute(lambda o: faker.date_time_between(
        start_date="now", end_date="+15m", tzinfo=UTC))
    status = FuzzyChoice(dict(CallRecord.CALL_STATUS_CHOICES).keys())
    direction = FuzzyChoice(dict(CallRecord.CALL_DIRECTION_CHOICES).keys())
    caller = SubFactory(CallParticipantFactory,
                        tenant=SelfAttribute('..tenant'))
    destination = SubFactory(CallParticipantFactory,
                             tenant=SelfAttribute('..tenant'))

    class Meta:
        model = CallRecord
Esempio n. 21
0
class EmailAddressFactory(DjangoModelFactory):
    email_address = LazyAttribute(lambda o: unicodedata.normalize(
        'NFD', faker.safe_email()).encode('ascii', 'ignore'))
    status = EmailAddress.PRIMARY_STATUS

    class Meta:
        model = EmailAddress
Esempio n. 22
0
class CaseFactory(DjangoModelFactory):
    tenant = SubFactory(TenantFactory)
    status = SubFactory(CaseStatusFactory, tenant=SelfAttribute('..tenant'))
    priority = FuzzyChoice(dict(Case.PRIORITY_CHOICES).keys())
    subject = LazyAttribute(lambda o: faker.word())
    account = SubFactory(AccountFactory, tenant=SelfAttribute('..tenant'))
    expires = FuzzyDate(datetime.date(2015, 1, 1), datetime.date(2016, 1, 1))
    assigned_to = SubFactory(LilyUserFactory, tenant=SelfAttribute('..tenant'))
    type = SubFactory(CaseTypeFactory, tenant=SelfAttribute('..tenant'))
    created_by = SelfAttribute('.assigned_to')

    @factory.post_generation
    def teams(self, create, extracted, **kwargs):
        if not create:
            # Simple build, do nothing.
            return

        if extracted:
            if isinstance(extracted, Team):
                # A single team was passed in, use that.
                self.assigned_to_teams.add(extracted)
            else:
                # A list of teams were passed in, use them.
                for team in extracted:
                    self.assigned_to_teams.add(team)

    class Meta:
        model = Case
Esempio n. 23
0
class JouveContentFactory(factory.Factory):
    class Meta:
        model = models.JouveContent

    activity = random.choice(["Etudiant"])
    address = "25 rue du moulin vert"
    birthDateTxt = LazyAttribute(lambda _: (datetime.utcnow() - relativedelta(
        years=18)).strftime("%d/%m/%Y"))
    birthLocationCtrl = random.choice(JOUVE_CTRL_VALUES)
    bodyBirthDateCtrl = random.choice(JOUVE_CTRL_VALUES)
    bodyBirthDateLevel = factory.Faker("pyint", max_value=100)
    bodyFirstnameCtrl = random.choice(JOUVE_CTRL_VALUES)
    bodyFirstnameLevel = factory.Faker("pyint", max_value=100)
    bodyNameLevel = factory.Faker("pyint", max_value=100)
    bodyNameCtrl = random.choice(JOUVE_CTRL_VALUES)
    bodyPieceNumber = factory.Faker("pyint")
    bodyPieceNumberCtrl = random.choice(JOUVE_CTRL_VALUES)
    bodyPieceNumberLevel = factory.Faker("pyint", max_value=100)
    city = "Paris"
    creatorCtrl = random.choice(JOUVE_CTRL_VALUES)
    id = factory.Faker("pyint")
    email = factory.Sequence("jeanne.doux{}@example.com".format)
    firstName = factory.Sequence("Jeanne{}".format)
    gender = random.choice(["Male", "Female"])
    initialNumberCtrl = factory.Faker("pyint")
    initialSizeCtrl = random.choice(JOUVE_CTRL_VALUES)
    lastName = factory.Sequence("doux{}".format)
    phoneNumber = factory.Sequence("+3361212121{}".format)
    postalCode = "75008"
    posteCodeCtrl = "75"
    serviceCodeCtrl = factory.Faker("pystr")
Esempio n. 24
0
class GuessFactory(DjangoModelFactory):
    class Meta:
        model = Guess

    user = SubFactory(UserFactory)
    market = SubFactory(MarketFactory)
    value = FuzzyDecimal(1, 10000)
    score = LazyAttribute(lambda o: o.get_score())
Esempio n. 25
0
class WebsiteFactory(DjangoModelFactory):
    tenant = SubFactory(TenantFactory)
    account = SubFactory(AccountFactory, tenant=SelfAttribute('..tenant'))
    website = LazyAttribute(lambda o: faker.url())
    is_primary = FuzzyChoice([True, False])

    class Meta:
        model = Website
Esempio n. 26
0
class DealWhyLostFactory(DjangoModelFactory):
    position = Sequence(int)
    name = LazyAttribute(lambda o: faker.word())
    tenant = SubFactory(TenantFactory)

    class Meta:
        model = DealWhyLost
        django_get_or_create = ('tenant', 'name')
Esempio n. 27
0
class UploadedFileFactory(DjangoModelFactory):
	class Meta:
		model = UploadedFile

	benefactor = SubFactory(StudentFactory)
	owner = LazyAttribute(lambda o: o.benefactor.user)
	category = 'psets'
	content = FileField(filename='pset.txt')
	unit = SubFactory(UnitFactory)
Esempio n. 28
0
class CallTransferFactory(DjangoModelFactory):
    tenant = SubFactory(TenantFactory)
    timestamp = LazyAttribute(lambda o: faker.date_time_between(
        start_date="now", end_date="+1m", tzinfo=UTC))
    destination = SubFactory(CallParticipantFactory,
                             tenant=SelfAttribute('..tenant'))

    class Meta:
        model = CallTransfer
Esempio n. 29
0
class NoteFactory(DjangoModelFactory):
    content = LazyAttribute(lambda o: faker.text())
    author = SubFactory(LilyUserFactory, tenant=SelfAttribute('..tenant'))

    @factory.lazy_attribute
    def subject(self):
        SubjectFactory = random.choice([AccountFactory, ContactFactory])
        return SubjectFactory(tenant=self.tenant)

    class Meta:
        model = Note
Esempio n. 30
0
class PSetFactory(DjangoModelFactory):
	class Meta:
		model = PSet

	student = SubFactory(StudentFactory)
	unit = SubFactory(UnitFactory)
	upload = LazyAttribute(
		lambda o: UploadedFileFactory.create(benefactor=o.student, unit=o.unit)
	)
	next_unit_to_unlock = SubFactory(UnitFactory)
	approved = True