Beispiel #1
0
class TravelFactory(factory.DjangoModelFactory):
    traveler = factory.SubFactory(UserFactory)
    supervisor = factory.SubFactory(UserFactory)
    office = factory.SubFactory(OfficeFactory)
    sector = factory.SubFactory(SectorFactory)
    start_date = fuzzy.FuzzyDateTime(start_dt=_FUZZY_START_DATE,
                                     end_dt=timezone.now())
    end_date = fuzzy.FuzzyDateTime(start_dt=timezone.now(),
                                   end_dt=_FUZZY_END_DATE)
    purpose = factory.Sequence(lambda n: 'Purpose #{}'.format(n))
    international_travel = False
    ta_required = True
    reference_number = factory.Sequence(
        lambda n: models.make_travel_reference_number())
    currency = factory.SubFactory(PublicsCurrencyFactory)
    mode_of_travel = []

    itinerary = factory.RelatedFactory(ItineraryItemFactory, 'travel')
    expenses = factory.RelatedFactory(ExpenseFactory, 'travel')
    deductions = factory.RelatedFactory(DeductionFactory, 'travel')
    cost_assignments = factory.RelatedFactory(CostAssignmentFactory, 'travel')
    clearances = factory.RelatedFactory(ClearanceFactory, 'travel')
    action_points = factory.RelatedFactory(ActionPointFactory, 'travel')

    @factory.post_generation
    def populate_activities(self, create, extracted, **kwargs):
        ta = TravelActivityFactory(primary_traveler=self.traveler)
        ta.travels.add(self)

    class Meta:
        model = models.Travel
Beispiel #2
0
class StationFactory(factory.django.DjangoModelFactory):
    """Station model factory."""
    owner = factory.SubFactory(UserFactory)
    name = fuzzy.FuzzyText()
    image = factory.django.ImageField()
    alt = fuzzy.FuzzyInteger(0, 800)
    lat = fuzzy.FuzzyFloat(-20, 70)
    lng = fuzzy.FuzzyFloat(-180, 180)
    featured_date = fuzzy.FuzzyDateTime(now() - timedelta(days=10), now())
    active = fuzzy.FuzzyChoice(choices=[True, False])
    last_seen = fuzzy.FuzzyDateTime(now() - timedelta(days=3), now())
    horizon = fuzzy.FuzzyInteger(10, 20)
    rig = factory.SubFactory(RigFactory)

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

        if extracted:
            for antenna in extracted:
                if random.randint(0, 1):
                    self.antenna.add(antenna)

    class Meta:
        model = Station
Beispiel #3
0
class OrderFactory(DjangoModelFactory):
    class Meta:
        model = Order

    client = factory.SubFactory(UserFactory)
    service = factory.SubFactory(ServiceFactory)
    creation_date = fuzzy.FuzzyDateTime(timezone.now())
    execution_date = fuzzy.FuzzyDateTime(timezone.now())
Beispiel #4
0
class VideoCommentFactory(factory.django.DjangoModelFactory):
    video = factory.SubFactory(VideoFactory)
    published = fuzzy.FuzzyDateTime(
        datetime.datetime(2017, 1, 1, tzinfo=pytz.UTC))
    updated = fuzzy.FuzzyDateTime(
        datetime.datetime(2017, 1, 1, tzinfo=pytz.UTC))

    class Meta:
        model = VideoComment
Beispiel #5
0
class RegionalProjectFactory(factory.django.DjangoModelFactory):
    class Meta:
        model = models.RegionalProject

    name = fuzzy.FuzzyText(length=50, prefix='regional-project-')
    created_at = fuzzy.FuzzyDateTime(
        datetime.datetime(2008, 1, 1, tzinfo=pytz.utc))
    modified_at = fuzzy.FuzzyDateTime(
        datetime.datetime(2008, 1, 1, tzinfo=pytz.utc))
class QuarterlyRevalidationThresholdFactory(factory.Factory):
    class Meta:
        model = jobModels.QuarterlyRevalidationThreshold

    year = fuzzy.FuzzyInteger(2010, 3000)
    quarter = fuzzy.FuzzyChoice((1, 2, 3, 4))
    window_start = fuzzy.FuzzyDateTime(
        datetime(2010, 1, 1, tzinfo=timezone.utc))
    window_end = fuzzy.FuzzyDateTime(datetime(2010, 1, 1, tzinfo=timezone.utc))
Beispiel #7
0
class ContainerSlotFactory(factory.DjangoModelFactory):
    class Meta:
        model = EnevoContainerSlot

    id = factory.Sequence(lambda n: n)
    fill_level = fuzzy.FuzzyInteger(0, 100)
    date_when_full = fuzzy.FuzzyDateTime(start_dt=timezone.now())
    last_service_event = fuzzy.FuzzyDateTime(start_dt=timezone.now())
    last_modified = fuzzy.FuzzyDateTime(start_dt=timezone.now())
Beispiel #8
0
class EventFactory(factory.django.DjangoModelFactory):
    """Factory for Event model."""
    FACTORY_FOR = Event

    name = factory.Sequence(lambda n: 'Event #%s' % n)
    start = fuzzy.FuzzyDateTime(START_DT, END_DT)
    end = fuzzy.FuzzyDateTime(END_DT + datetime.timedelta(days=3))
    timezone = fuzzy.FuzzyChoice(common_timezones)
    venue = 'VenueName'
    city = 'CityName'
    region = 'RegionName'
    country = fuzzy.FuzzyChoice(COUNTRIES)
    lat = fuzzy.FuzzyInteger(-90, 90)
    lon = fuzzy.FuzzyInteger(-180, 180)
    external_link = 'example.com'
    owner = factory.SubFactory(UserFactory)
    estimated_attendance = fuzzy.FuzzyInteger(1, 100)
    actual_attendance = fuzzy.FuzzyInteger(1, 100)
    description = 'This is an event description.'
    extra_content = 'Extra content for event page.'
    mozilla_event = fuzzy.FuzzyChoice([True, False])
    hashtag = 'EventHashtag'
    converted_visitors = fuzzy.FuzzyInteger(100)
    swag_bug = factory.SubFactory(BugFactory)
    budget_bug = factory.SubFactory(BugFactory)
    times_edited = fuzzy.FuzzyInteger(10)

    @factory.post_generation
    def categories(self, create, extracted, **kwargs):
        """Add event categories after event creation."""
        if not create:
            return
        if extracted:
            for category in extracted:
                self.categories.add(category)
        else:
            # add random number of categories
            for i in range(randint(1, 6)):
                area = FunctionalAreaFactory.create()
                self.categories.add(area)

    @factory.post_generation
    def goals(self, create, extracted, **kwargs):
        """Add event goals after event creation."""
        if not create:
            return
        if extracted:
            for goal in extracted:
                self.goals.add(goal)
        else:
            # add random number of goals
            for i in range(randint(1, 6)):
                goal = EventGoalFactory.create()
                self.goals.add(goal)
Beispiel #9
0
class StudentModuleFactory(DjangoModelFactory):
    class Meta:
        model = StudentModule

    student = factory.SubFactory(UserFactory, )
    course_id = factory.Sequence(
        lambda n: as_course_key(COURSE_ID_STR_TEMPLATE.format(n)))
    created = fuzzy.FuzzyDateTime(
        datetime.datetime(2018, 2, 2, tzinfo=factory.compat.UTC))
    modified = fuzzy.FuzzyDateTime(
        datetime.datetime(2018, 2, 2, tzinfo=factory.compat.UTC))
class SubmissionWindowScheduleFactory(factory.Factory):
    class Meta:
        model = jobModels.SubmissionWindowSchedule

    year = fuzzy.FuzzyInteger(2010, 3000)
    period = fuzzy.FuzzyChoice((1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12))
    period_start = fuzzy.FuzzyDateTime(
        datetime(2010, 1, 1, tzinfo=timezone.utc))
    publish_deadline = fuzzy.FuzzyDateTime(
        datetime(2010, 1, 1, tzinfo=timezone.utc))
    certification_deadline = fuzzy.FuzzyDateTime(
        datetime(2010, 1, 1, tzinfo=timezone.utc))
Beispiel #11
0
class PollFactory(factory.django.DjangoModelFactory):
    """Factory_Boy model for the voting_poll db table."""
    FACTORY_FOR = Poll

    name = factory.Sequence(lambda n: 'Voting{0} example'.format(n))
    start = fuzzy.FuzzyDateTime(datetime(2011, 1, 1, tzinfo=pytz.UTC))
    end = fuzzy.FuzzyDateTime(POLL_END_DT + timedelta(days=2),
                              POLL_END_DT + timedelta(days=365 * 2))
    valid_groups = fuzzy.FuzzyChoice(VALID_GROUPS)
    description = factory.Sequence(lambda n:
                                   ('This is a description {0}'.format(n)))
    created_by = factory.SubFactory(UserFactory)
class ParkingGuidanceDisplayFactory(factory.DjangoModelFactory):
    class Meta:
        model = ParkingGuidanceDisplay

    id = factory.Sequence(lambda n: n)
    api_id = factory.Sequence(lambda n: str(n))
    pub_date = fuzzy.FuzzyDateTime(start_dt=timezone.now())
    guidance_sign = factory.SubFactory(GuidanceSignFactory)
    scraped_at = fuzzy.FuzzyDateTime(start_dt=timezone.now())
    output = fuzzy.FuzzyText(length=100)
    output_description = fuzzy.FuzzyText(length=100)
    type = fuzzy.FuzzyText(length=4)
    description = fuzzy.FuzzyText(length=100)
Beispiel #13
0
class AlertFactory(factory.DjangoModelFactory):
    class Meta:
        model = EnevoAlert

    id = factory.Sequence(lambda n: n)
    type = fuzzy.FuzzyInteger(0, 50)
    type_name = fuzzy.FuzzyText(length=30)
    reported = fuzzy.FuzzyDateTime(start_dt=timezone.now())
    last_observed = fuzzy.FuzzyDateTime(start_dt=timezone.now())
    site_name = fuzzy.FuzzyText(length=30)
    area = fuzzy.FuzzyInteger(0, 50)
    area_name = fuzzy.FuzzyText(length=30)
    content_type_name = fuzzy.FuzzyText(length=30)
    start = fuzzy.FuzzyDateTime(start_dt=timezone.now())
Beispiel #14
0
class OvFietsFactory(factory.DjangoModelFactory):
    class Meta:
        model = OvFiets

    id = factory.Sequence(lambda n: n)
    name = fuzzy.FuzzyText(length=20)
    station_code = fuzzy.FuzzyText(length=4)
    location_code = fuzzy.FuzzyText(length=7)
    open = fuzzy.FuzzyText(length=7)
    stadsdeel = fuzzy.FuzzyChoice(choices=['A', 'B', 'C'])
    rental_bikes = fuzzy.FuzzyInteger(0, 100)
    fetch_time = fuzzy.FuzzyDateTime(start_dt=timezone.now())
    scraped_at = fuzzy.FuzzyDateTime(start_dt=timezone.now())
    geometrie = get_puntje()
class GuidanceSignFactory(factory.DjangoModelFactory):
    class Meta:
        model = GuidanceSign

    id = factory.Sequence(lambda n: n)
    api_id = factory.Sequence(lambda n: str(n))
    name = fuzzy.FuzzyText(length=4)
    state = fuzzy.FuzzyText(length=4)
    type = fuzzy.FuzzyText(length=4)
    stadsdeel = fuzzy.FuzzyChoice(choices=['A', 'B', 'C'])
    geometrie = get_puntje()
    pub_date = fuzzy.FuzzyDateTime(start_dt=timezone.now())
    buurt_code = fuzzy.FuzzyText(length=4)
    scraped_at = fuzzy.FuzzyDateTime(start_dt=timezone.now())
Beispiel #16
0
class ItemFactory(factory.Factory):
    class Meta:
        model = Item

    buildyear = fuzzy.FuzzyInteger(0, 9999999999)
    charges_parkingspace = fuzzy.FuzzyDecimal(0, 99999999999)
    chargesfinancebasemonth = fuzzy.FuzzyDecimal(0, 99999999999)
    chargesmaintbasemonth = fuzzy.FuzzyDecimal(0, 99999999999)
    chargeswater_period = fuzzy.FuzzyText()
    condition_name = fuzzy.FuzzyChoice([c for c in Condition])
    coordinate = factory.List([factory.SubFactory(CoordinateFactory)])
    country = fuzzy.FuzzyChoice([c for c in Country])
    currency_code = "EUR"
    cust_itemcode = fuzzy.FuzzyText()
    debtfreeprice = fuzzy.FuzzyDecimal(0, 99999999999)
    extralink = factory.List(
        [factory.SubFactory(ExtraLinkFactory) for _ in range(2)])
    floors = fuzzy.FuzzyInteger(0, 9999999999)
    energyclass = fuzzy.FuzzyText(length=10)
    holdingtype = fuzzy.FuzzyChoice([c for c in HoldingType])
    image = factory.List([factory.SubFactory(ImageFactory) for _ in range(2)])
    itemgroup = fuzzy.FuzzyChoice([c for c in ItemGroup])
    livingaream2 = fuzzy.FuzzyDecimal(0, 99999999999)
    loclvlid = 1
    locsourceid = 4
    lotarea = fuzzy.FuzzyDecimal(0, 99999999999)
    lotareaunitcode = fuzzy.FuzzyText(length=2)
    lotholding = fuzzy.FuzzyText()
    postcode = fuzzy.FuzzyText(length=5)
    price = fuzzy.FuzzyDecimal(0, 99999999999)
    price_m2 = fuzzy.FuzzyDecimal(0, 99999999999)
    quarteroftown = fuzzy.FuzzyText(length=60)
    realtygroup = fuzzy.FuzzyChoice([c for c in RealtyGroup])
    realtyidentifier = fuzzy.FuzzyText(length=40)
    realty_itemgroup = fuzzy.FuzzyChoice([c for c in ItemGroup])
    realtytype = fuzzy.FuzzyChoice([c for c in RealtyType])
    realtyoption = factory.List([fuzzy.FuzzyText() for _ in range(2)])
    rc_parkingspace_count = fuzzy.FuzzyInteger(0, 9999999999)
    roomcount = fuzzy.FuzzyInteger(0, 9999999999)
    scontact = factory.List(
        [factory.SubFactory(ScontactFactory) for _ in range(2)])
    showingdate = fuzzy.FuzzyDateTime(timezone.now())
    showing_date2 = fuzzy.FuzzyDateTime(timezone.now())
    street = fuzzy.FuzzyText(length=200)
    supplier_source_itemcode = fuzzy.FuzzyText()
    text = factory.List([factory.SubFactory(TextFactory) for _ in range(2)])
    town = fuzzy.FuzzyText(length=60)
    tradetype = fuzzy.FuzzyChoice([c for c in TradeType])
    zoningname = fuzzy.FuzzyText()
Beispiel #17
0
class SignalFactory(factory.DjangoModelFactory):
    class Meta:
        model = Signal

    signal_id = fuzzy.FuzzyAttribute(uuid.uuid4)
    text = fuzzy.FuzzyText(length=100)
    text_extra = fuzzy.FuzzyText(length=100)

    # Creating (reverse FK) related objects after this `Signal` is created.
    location = factory.RelatedFactory(
        'tests.apps.signals.factories.LocationFactory', '_signal')
    status = factory.RelatedFactory(
        'tests.apps.signals.factories.StatusFactory', '_signal')
    category_assignment = factory.RelatedFactory(
        'tests.apps.signals.factories.CategoryAssignmentFactory', '_signal')
    reporter = factory.RelatedFactory(
        'tests.apps.signals.factories.ReporterFactory', '_signal')
    priority = factory.RelatedFactory(
        'tests.apps.signals.factories.PriorityFactory', '_signal')

    incident_date_start = fuzzy.FuzzyDateTime(
        datetime(2017, 11, 1, tzinfo=pytz.UTC),
        datetime(2018, 2, 1, tzinfo=pytz.UTC),
    )
    incident_date_end = fuzzy.FuzzyDateTime(
        datetime(2018, 2, 2, tzinfo=pytz.UTC),
        datetime(2019, 2, 2, tzinfo=pytz.UTC))
    extra_properties = {}

    # SIG-884
    parent = None

    @factory.post_generation
    def set_one_to_one_relations(self, create, extracted, **kwargs):
        """Set o2o relations on given `Signal` object."""
        self.location = self.locations.last()
        self.status = self.statuses.last()
        self.category_assignment = self.category_assignments.last()
        self.reporter = self.reporters.last()
        self.priority = self.priorities.last()

    @factory.post_generation
    def set_default_type(self, create, extracted, **kwargs):
        """
        This will add the default Type to the signal for a factory created signal
        """
        if create:
            TypeFactory(
                _signal=self)  # By default the type is set to "SIG (SIGNAL)"
class ClientFactory(factory.Factory):
    class Meta:
        model = Client

    client_id = factory.LazyAttribute(lambda x: randrange(100, 3000))
    gender = factory.LazyAttribute(lambda x: choice(GENDER)[1])
    birth_date = fuzzy.FuzzyDateTime(datetime(1945, 1, 1, tzinfo=timezone.utc))
class AccountFactory(factory.Factory):
    class Meta:
        model = Account

    account_id = factory.LazyAttribute(lambda x: randrange(1, 100))
    frequency = factory.LazyAttribute(lambda x: choice(FREQUENCY_CHOICES)[1])
    date = fuzzy.FuzzyDateTime(datetime(2019, 1, 1, tzinfo=timezone.utc))
Beispiel #20
0
class UserFactory(DjangoModelFactory):
    class Meta:
        model = get_user_model()

    username = factory.Sequence(lambda n: 'user{}'.format(n))
    password = factory.PostGenerationMethodCall('set_password', 'password')
    email = factory.LazyAttribute(
        lambda a: '{0}@example.com'.format(a.username))
    is_active = True
    is_staff = False
    is_superuser = False
    date_joined = fuzzy.FuzzyDateTime(
        datetime.datetime(2018, 4, 1, tzinfo=factory.compat.UTC))

    # TODO: Figure out if this can be a SubFactory and the advantages
    profile = factory.RelatedFactory(UserProfileFactory, 'user')

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

        if extracted:
            for team in extracted:
                self.teams.add(team)
    def test_posts_one_page(self):
        api_url = reverse('olap:communication_posts', kwargs={'course_id': self.course_offering.id})
        page = PageFactory(course_offering=self.course_offering, content_type='resource/x-bb-discussionboard')
        # For this one page, generate one post per week for the duration of the course
        for week_no in range(self.course_offering.no_weeks):
            week_start_dt = self.course_offering.start_datetime + datetime.timedelta(weeks=week_no)
            week_end_dt = week_start_dt + datetime.timedelta(days=7)
            post_event_dt = fuzzy.FuzzyDateTime(week_start_dt, week_end_dt)
            post_event = SummaryPostFactory(page=page, lms_user=self.lms_user, posted_at=post_event_dt)

        # Call the API endpoint
        response = self.client.get(api_url)
        self.assertEqual(response.status_code, HTTP_200_OK)
        totals = [1] * self.course_offering.no_weeks # One visit per week
        totals.append(self.course_offering.no_weeks) # Add a final number for the total visits
        expected = {
            'pageSet': [
                {
                    'id': page.id,
                    'title': page.title,
                    'content_type': page.content_type,
                    'weeks': [1] * self.course_offering.no_weeks, # One visit per week
                    'total': self.course_offering.no_weeks, # One visit per week
                    'percent': 100.0,
               },
            ],
            'totalsByWeek': totals,
        }
        response_dict = json.loads(response.content.decode('utf-8'))
        self.assertEqual(response_dict, expected)
Beispiel #22
0
class ProductFactory(factory.django.DjangoModelFactory):
    """
    ...
    """

    ptype = factory.SubFactory(ptypefactories.ProductTypeFactory)
    count = fuzzy.FuzzyInteger(0, 10000)
    updated = fuzzy.FuzzyDateTime(
        start_dt=datetime.datetime(2020, 1, 1, 0, 0, tzinfo=pytz.UTC),
        end_dt=datetime.datetime(2020, 3, 4, 0, 0, tzinfo=pytz.UTC),
    )

    class Meta:
        """
        ...
        """

        model = Product

    @factory.post_generation
    def set_timestamp(self, create, extracted, **kwargs):
        if not create:  # pragma: no cover
            return

        # print(self.id)
        # print(self.updated.timestamp())
        # print(self.updated.timestamp())
        # self.timestamp = self.updated.timestamp()
        # self.save()
        return
Beispiel #23
0
class ExamFactory(factory.django.DjangoModelFactory):
    class Meta:
        model = models.Exam
        django_get_or_create = ('course', 'description')

    course = factory.SubFactory(CourseFactory)
    description = "desc of exam"
    flow_id = DEFAULT_FLOW_ID
    active = True
    listed = True

    no_exams_before = fuzzy.FuzzyDateTime(
        datetime(2019, 1, 1, tzinfo=pytz.UTC),
        datetime(2019, 1, 31, tzinfo=pytz.UTC))
    no_exams_after = fuzzy.FuzzyDateTime(datetime(2019, 2, 1, tzinfo=pytz.UTC),
                                         datetime(2019, 3, 1, tzinfo=pytz.UTC))
    def test_accesses_one_page(self):
        self.api_url = reverse('olap:communication_accesses', kwargs={'course_id': self.course_offering.id})
        page = PageFactory(course_offering=self.course_offering, content_type='course/x-bb-collabsession')
        # For this one page, generate one visit per week for the duration of the course
        for week_no in range(self.course_offering.no_weeks):
            week_start_dt = self.course_offering.start_datetime + datetime.timedelta(weeks=week_no)
            week_end_dt = week_start_dt + datetime.timedelta(days=7)
            visit_dt = fuzzy.FuzzyDateTime(week_start_dt, week_end_dt)
            visit = PageVisitFactory(page=page, module='course/x-bb-collabsession', lms_user=self.lms_user, visited_at=visit_dt)

        # Call the API endpoint
        response = self.client.get(self.api_url)
        self.assertEqual(response.status_code, HTTP_200_OK)
        totals = [1] * self.course_offering.no_weeks # One visit per week
        totals.append(self.course_offering.no_weeks) # Add a final number for the total visits
        expected = {
            'pageSet': [
                {
                    # These keys aren't getting camel cased.  No idea why.
                    'id': page.id,
                    'title': page.title,
                    'content_type': page.content_type,
                    'weeks': [1] * self.course_offering.no_weeks, # One visit per week
                    'total': self.course_offering.no_weeks, # One visit per week
                    'percent': 100.0,
               },
            ],
            'totalsByWeek': totals,
        }
        response_dict = json.loads(response.content.decode('utf-8'))
        self.assertEqual(response_dict, expected)
Beispiel #25
0
class NotificationFactory(factory.django.DjangoModelFactory):
    class Meta:
        model = Notification

    from_date = fuzzy.FuzzyDateTime(start_dt=timezone.now(),
                                    force_hour=0,
                                    force_minute=0,
                                    force_second=0,
                                    force_microsecond=0)
    to_date = factory.LazyAttribute(lambda o: o.from_date + timedelta(days=7))
    message = fuzzy.FuzzyText()
    time_to_show = fuzzy.FuzzyInteger(1, 10)

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

        if extracted:
            # A list of groups were passed in, use them
            for user in extracted:
                self.users.add(user)

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

        if extracted:
            # A list of groups were passed in, use them
            for group in extracted:
                self.groups.add(group)
Beispiel #26
0
class FlwTransactionModelFactory(DjangoModelFactory):
    """Factory for the FlwTransactionModel"""

    plan = factory.SubFactory(FlwPlanModelFactory)
    user = factory.SubFactory(UserFactory)
    tx_ref = factory.Faker("word")
    flw_ref = factory.Faker("word")
    device_fingerprint = factory.Faker("word")
    amount = fuzzy.FuzzyDecimal(low=20, high=100, precision=2)
    currency = fuzzy.FuzzyChoice(choices=["USD", "ZAR", "EUR"])
    charged_amount = fuzzy.FuzzyDecimal(low=20, high=100, precision=2)
    app_fee = fuzzy.FuzzyDecimal(low=1, high=5, precision=2)
    merchant_fee = fuzzy.FuzzyDecimal(low=1, high=5, precision=2)
    processor_response = factory.Faker("word")
    auth_model = factory.Faker("word")
    ip = factory.Faker("word")
    narration = factory.Faker("word")
    status = fuzzy.FuzzyChoice(choices=["successful", "failed"])
    payment_type = fuzzy.FuzzyChoice(choices=["card", "ussd"])
    created_at = fuzzy.FuzzyDateTime(
        start_dt=datetime(2018, 8, 15, tzinfo=pytz.UTC),
        end_dt=datetime(2020, 8, 15, tzinfo=pytz.UTC),
    )
    account_id = fuzzy.FuzzyInteger(low=1, high=100)

    class Meta:
        model = FlwTransactionModel
Beispiel #27
0
class CityControlRoundtripFactory(factory.django.DjangoModelFactory):
    class Meta:
        model = CityControlRoundtrip

    _signal = factory.SubFactory(
        'signals.apps.signals.factories.SignalFactory')
    when = fuzzy.FuzzyDateTime(timezone.now())
Beispiel #28
0
class UserProfileFactory(factory.django.DjangoModelFactory):
    """Factory for UserProfile model."""

    date_joined_program = fuzzy.FuzzyDateTime(START_DT)
    local_name = 'Local Name'
    birth_date = datetime.date(1992, 1, 1)
    city = 'User city'
    region = 'User region'
    country = fuzzy.FuzzyChoice(COUNTRIES)
    lat = fuzzy.FuzzyInteger(-90, 90)
    lon = fuzzy.FuzzyInteger(-180, 180)
    display_name = factory.Sequence(lambda n: 'UserProfile%s' % n)
    private_email = factory.Sequence(lambda n: '*****@*****.**' % n)
    mozillians_profile_url = 'https://mozillians.org/'
    irc_name = factory.Sequence(lambda n: 'user%s' % n)
    twitter_account = factory.Sequence(lambda n: 'user%s' % n)
    facebook_url = factory.Sequence(lambda n: 'http://facebook.com/user%s' % n)
    linkedin_url = 'http://linkedin.com/profile/'
    wiki_profile_url = 'https://wiki.mozilla.org/User:'******'userprofile_email_mentor_notification'
        pre_save.disconnect(email_mentor_notification,
                            UserProfile,
                            dispatch_uid=dispatch_uid)
        profile = super(UserProfileFactory,
                        cls)._create(target_class, *args, **kwargs)
        pre_save.connect(email_mentor_notification,
                         UserProfile,
                         dispatch_uid=dispatch_uid)
        return profile

    @factory.post_generation
    def functional_areas(self, create, extracted, **kwargs):
        """Add functional areas list after object generation."""
        if not create:
            return
        if extracted:
            for area in extracted:
                self.functional_areas.add(area)
        else:
            # create random
            for i in range(randint(1, 6)):
                area = FunctionalAreaFactory.create()
                self.functional_areas.add(area)

    @factory.post_generation
    def initial_council(self, create, extracted, **kwargs):
        """Create userprofile with self as mentor."""
        if not create:
            return
        if extracted:
            self.mentor = self.user
Beispiel #29
0
class UserProfileFactory(factory.django.DjangoModelFactory):
    """UserProfile fixture factory."""
    FACTORY_FOR = UserProfile

    registration_complete = True
    date_joined_program = fuzzy.FuzzyDateTime(START_DT)
    local_name = 'Local Name'
    birth_date = datetime.date(1992, 1, 1)
    city = 'User city'
    region = 'User region'
    country = fuzzy.FuzzyChoice(COUNTRIES)
    lat = fuzzy.FuzzyInteger(-90, 90)
    lon = fuzzy.FuzzyInteger(-180, 180)
    display_name = factory.Sequence(lambda n: 'UserProfile%s' % n)
    private_email = factory.Sequence(lambda n: '*****@*****.**' % n)
    mozillians_profile_url = 'https://mozillians.org/'
    irc_name = factory.Sequence(lambda n: 'user%s' % n)
    wiki_profile_url = 'https://wiki.mozilla.org/User:'******'userprofile_email_mentor_notification'
        pre_save.disconnect(email_mentor_notification,
                            UserProfile,
                            dispatch_uid=dispatch_uid)
        profile = super(UserProfileFactory,
                        cls)._create(target_class, *args, **kwargs)
        pre_save.connect(email_mentor_notification,
                         UserProfile,
                         dispatch_uid=dispatch_uid)
        return profile

    @factory.post_generation
    def functional_areas(self, create, extracted, **kwargs):
        """Add functional areas list after object generation."""
        if not create:
            return
        if extracted:
            for area in extracted:
                self.functional_areas.add(area)

    @factory.post_generation
    def random_functional_areas(self, create, extracted, **kwargs):
        """Add random functional areas after object generation."""
        if not create:
            return
        if extracted:
            rand_int = randint(1, FunctionalArea.objects.count())
            for area in FunctionalArea.objects.all().order_by('?')[:rand_int]:
                self.functional_areas.add(area)

    @factory.post_generation
    def initial_council(self, create, extracted, **kwargs):
        """Create userprofile with self as mentor."""
        if not create:
            return
        if extracted:
            self.mentor = self.user
Beispiel #30
0
    def test_accurate_definition(self):
        """Tests explicit definition of a FuzzyDateTime."""
        fuzz = fuzzy.FuzzyDateTime(self.jan1, self.jan31)

        for _i in range(20):
            res = fuzz.evaluate(2, None, False)
            self.assertLessEqual(self.jan1, res)
            self.assertLessEqual(res, self.jan31)