Esempio n. 1
0
class ScenarioFactory(factory.Factory):
    class Meta:
        model = Scenario

    name = fuzzy.FuzzyText(length=8,
                           chars=string.ascii_lowercase + string.digits)
    user = fuzzy.FuzzyText(length=3, chars=string.digits)
    query = ''
    sensor_versions = [{
        'sensor': 'CAM',
        'version': 'v1.1'
    }, {
        'sensor': 'LDR',
        'version': 'v2.44'
    }]
    scenario_segments = factory.List([
        factory.SubFactory(ScenarioSegmentFactory),
        factory.SubFactory(ScenarioSegmentFactory),
        factory.SubFactory(ScenarioSegmentFactory),
        factory.SubFactory(ScenarioSegmentFactory),
        factory.SubFactory(ScenarioSegmentFactory),
    ])
    created_at = fuzzy.FuzzyNaiveDateTime(datetime(2015, 1, 1))
    updated_at = fuzzy.FuzzyNaiveDateTime(datetime(2015, 1, 1))
    started_at = fuzzy.FuzzyNaiveDateTime(datetime(2015, 1, 1))
    ended_at = fuzzy.FuzzyNaiveDateTime(datetime(2015, 1, 1))
    state = Scenario.State.CREATED
    cpu_time = fuzzy.FuzzyInteger(100, 1000)
    output_path = factory.LazyAttribute(lambda s: '/output/path/%s-%s' %
                                        (s.name, s.user))
class AccessionFactory(factory.django.DjangoModelFactory):
    accession_number = factory.Sequence(lambda n: str(n))
    donor = factory.SubFactory(DonorFactory)
    anonymous_accession = False
    date_paperwork_sent = fuzzy.FuzzyNaiveDateTime(datetime(2012, 1, 1))
    date_paperwork_returned = fuzzy.FuzzyNaiveDateTime(datetime(2012, 1, 2))

    class Meta:
        model = models.Accession
Esempio n. 3
0
class SMSTemplateFactory(factory_django.DjangoModelFactory):

    slug = 'test'
    body = 'Does rendering context variables work? {{ variable }}'
    created_at = fuzzy.FuzzyNaiveDateTime(start_dt=datetime.now() - timedelta(days=150))
    changed_at = fuzzy.FuzzyNaiveDateTime(start_dt=datetime.now() - timedelta(days=150))

    class Meta:
        model = SMSTemplate
class OutputSMSFactory(factory_django.DjangoModelFactory):
    # Do NOT add sent_at to the factory, must be set by hand to be able to test functionality
    sender = '+420777123456'
    recipient = fuzzy.FuzzyText(length=9, prefix='+420', chars=string.digits)
    opmid = ''
    dlr = '1'
    kw = fuzzy.FuzzyText(length=30)
    content = fuzzy.FuzzyText(length=160)
    created_at = fuzzy.FuzzyNaiveDateTime(start_dt=datetime.now() - timedelta(days=150))
    changed_at = fuzzy.FuzzyNaiveDateTime(start_dt=datetime.now() - timedelta(days=150))

    class Meta:
        model = OutputSMS
class InputSMSFactory(factory_django.DjangoModelFactory):

    received_at = fuzzy.FuzzyNaiveDateTime(start_dt=datetime.now() - timedelta(days=150))
    uniq = factory.Sequence(lambda n: n)
    sender = '777123456'
    recipient = '777444888'
    okey = fuzzy.FuzzyText(length=50)
    opid = fuzzy.FuzzyText(length=50)
    opmid = fuzzy.FuzzyText(length=50)
    content = fuzzy.FuzzyText(length=50)
    created_at = fuzzy.FuzzyNaiveDateTime(start_dt=datetime.now() - timedelta(days=150))
    changed_at = fuzzy.FuzzyNaiveDateTime(start_dt=datetime.now() - timedelta(days=150))

    class Meta:
        model = InputSMS
Esempio n. 6
0
class ArticleFactory(DjangoModelFactory):
    title = Sequence(lambda n: 'Article {}'.format(n))
    category = SubFactory(CategoryFactory)
    updated_at = fuzzy.FuzzyNaiveDateTime(datetime.datetime(2016, 1, 1))

    class Meta:
        model = Article
Esempio n. 7
0
    def test_accurate_definition(self):
        """Tests explicit definition of a FuzzyNaiveDateTime."""
        fuzz = fuzzy.FuzzyNaiveDateTime(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)
Esempio n. 8
0
    def test_force_microsecond(self):
        fuzz = fuzzy.FuzzyNaiveDateTime(self.jan1,
                                        self.jan31,
                                        force_microsecond=4)

        for _i in range(20):
            res = fuzz.evaluate(2, None, False)
            self.assertEqual(4, res.microsecond)
Esempio n. 9
0
    def test_force_microsecond(self):
        fuzz = fuzzy.FuzzyNaiveDateTime(self.jan1,
                                        self.jan31,
                                        force_microsecond=4)

        for _i in range(20):
            res = utils.evaluate_declaration(fuzz)
            self.assertEqual(4, res.microsecond)
Esempio n. 10
0
    def test_partial_definition(self):
        """Test defining a FuzzyNaiveDateTime without passing an end date."""
        with utils.mocked_datetime_now(self.jan3, fuzzy):
            fuzz = fuzzy.FuzzyNaiveDateTime(self.jan1)

        for _i in range(20):
            res = fuzz.evaluate(2, None, False)
            self.assertLessEqual(self.jan1, res)
            self.assertLessEqual(res, self.jan3)
Esempio n. 11
0
class ClientFactory(factory.django.DjangoModelFactory):
    class Meta:
        model = 'accounts.Client'

    contact = factory.SubFactory(ContactFactory)
    second_contact = factory.SubFactory(ContactFactory)
    organisation = factory.SubFactory(OrganisationFactory)
    office = factory.SubFactory(OfficeFactory)
    created_date = fuzzy.FuzzyNaiveDateTime(datetime.datetime(2017, 1, 1),
                                            datetime.datetime.now())
Esempio n. 12
0
class URLFactory(factory.django.DjangoModelFactory):

    user = factory.SubFactory(UserFactory)

    long_url = 'https://google.com/'
    created = fuzzy.FuzzyNaiveDateTime(datetime.datetime.now())
    count = fuzzy.FuzzyInteger(0)

    class Meta:
        model = models.URL
Esempio n. 13
0
    def test_biased(self):
        """Tests a FuzzyDate with a biased random.randint."""

        fake_randint = lambda low, high: (low + high) // 2
        fuzz = fuzzy.FuzzyNaiveDateTime(self.jan1, self.jan31)

        with mock.patch('factory.fuzzy._random.randint', fake_randint):
            res = fuzz.evaluate(2, None, False)

        self.assertEqual(datetime.datetime(2013, 1, 16), res)
Esempio n. 14
0
    def test_biased_partial(self):
        """Tests a FuzzyDate with a biased random and implicit upper bound."""
        with utils.mocked_datetime_now(self.jan3, fuzzy):
            fuzz = fuzzy.FuzzyNaiveDateTime(self.jan1)

        fake_randint = lambda low, high: (low + high) // 2
        with mock.patch('factory.fuzzy._random.randint', fake_randint):
            res = fuzz.evaluate(2, None, False)

        self.assertEqual(datetime.datetime(2013, 1, 2), res)
Esempio n. 15
0
    def test_biased(self):
        """Tests a FuzzyDate with a biased random.randint."""

        fake_randint = lambda low, high: (low + high) // 2
        fuzz = fuzzy.FuzzyNaiveDateTime(self.jan1, self.jan31)

        with mock.patch('factory.random.randgen.randint', fake_randint):
            res = utils.evaluate_declaration(fuzz)

        self.assertEqual(datetime.datetime(2013, 1, 16), res)
Esempio n. 16
0
class AsdmOutputFactory(factory.Factory):
    class Meta:
        model = AsdmOutput

    asdmoutput_id = factory.Sequence(lambda n: 'asdmoutput-%04d' % (n + 1, ))
    segment_id = factory.Sequence(lambda n: 'segment-%04d' % (n + 1, ))
    sensor_versions = [{
        'sensor': 'CAM',
        'version': 'v1.1'
    }, {
        'sensor': 'LDR',
        'version': 'v2.44'
    }]
    asdm_version = 'v2'
    cluster_id = 'cluster-1'
    created_at = fuzzy.FuzzyNaiveDateTime(datetime(2015, 1, 1))
    updated_at = fuzzy.FuzzyNaiveDateTime(datetime(2015, 1, 1))
    nfs_host = 'cluster-nfs-1'
    smb_host = 'cluster-smb-1'
    dat_file = '/file.dat'
    mat_file = '/file.mat'
    smb_share = factory.LazyAttribute(lambda s: r'\\%s%s' %
                                      (s.smb_host, s.path))
    path = factory.LazyAttribute(lambda d: '/path/%s' % d.asdmoutput_id)
Esempio n. 17
0
class ReaderFactory(factory.Factory):
    class Meta:
        model = Reader

    reader_id = factory.Sequence(lambda n: 'reader-%s' % n)
    hostname = fuzzy.FuzzyText(length=4,
                               prefix='ingest-',
                               chars=string.ascii_lowercase + string.digits)
    device = '/dev/md0'
    status = factory.Iterator(Reader.Status)
    ingest_state = factory.Iterator(Reader.IngestState)
    message = 'Foo bar'
    mount = '/mnt-1'
    port = 'sas-phy0'
    updated_at = fuzzy.FuzzyNaiveDateTime(datetime(2017, 10, 20))
Esempio n. 18
0
class CartridgeFactory(factory.Factory):
    class Meta:
        model = Cartridge

    cartridge_id = factory.Sequence(lambda n: 'FECA0779140801261903-%s' % n)
    device = '/dev/md0'
    ingest_station = fuzzy.FuzzyText(length=4,
                                     prefix='ingest-',
                                     chars=string.ascii_lowercase +
                                     string.digits)
    usage = fuzzy.FuzzyDecimal(0.5, 5.0)
    workflow_type = factory.Iterator(Cartridge.WorkflowType)

    ingest_state = factory.Iterator(Reader.IngestState)
    slot = 'sas-phy0'
    updated_at = fuzzy.FuzzyNaiveDateTime(datetime(2017, 10, 20))
Esempio n. 19
0
class OrderFactory(Factory):
    FACTORY_FOR = Order

    for_date = fuzzy.FuzzyDate(week_ago, week_ahead)
    placed_at = fuzzy.FuzzyNaiveDateTime(datetime.combine(week_ago, time.min))
    vendor = factory.SubFactory(VendorFactory)
    ordered_by = factory.SubFactory(UserFactory)

    @factory.post_generation
    def contributions(self, create, extracted, **kwargs):
        if not extracted:
            amount = fuzzy.FuzzyDecimal(low=2, high=15).fuzz()
            extracted = ((self.ordered_by, amount), )
        ret = []
        for user, amount in extracted:
            ret.append(
                OrderContributionFactory(
                    order=self,
                    user=user,
                    amount=amount,
                ))
        return ret
Esempio n. 20
0
 def test_invalid_definition(self):
     with self.assertRaises(ValueError):
         fuzzy.FuzzyNaiveDateTime(self.jan31, self.jan1)
Esempio n. 21
0
class BaseAssetFactory(DjangoModelFactory):
    FACTORY_FOR = Asset

    budget_info = SubFactory(BudgetInfoFactory)
    created = fuzzy.FuzzyNaiveDateTime(
        datetime.datetime(2008, 1, 1),
        force_microsecond=0,
    )
    delivery_date = fuzzy.FuzzyDate(datetime.date(2008, 1, 1))
    deprecation_end_date = fuzzy.FuzzyDate(datetime.date(2008, 1, 1))
    deprecation_rate = fuzzy.FuzzyInteger(0, 100)
    device_environment = SubFactory(DeviceEnvironmentFactory)
    invoice_date = fuzzy.FuzzyDate(datetime.date(2008, 1, 1))
    invoice_no = Sequence(lambda n: 'Invoice no #{}'.format(n))
    location = Sequence(lambda n: 'location #{}'.format(n))
    model = SubFactory(AssetModelFactory)
    niw = Sequence(lambda n: 'Inventory number #{}'.format(n))
    order_no = Sequence(lambda n: 'Order no #{}'.format(n))
    owner = SubFactory(UserFactory)
    price = fuzzy.FuzzyDecimal(0, 100)
    property_of = SubFactory(AssetOwnerFactory)
    provider = Sequence(lambda n: 'Provider #%s' % n)
    provider_order_date = fuzzy.FuzzyDate(datetime.date(2008, 1, 1))
    remarks = Sequence(lambda n: 'Remarks #{}'.format(n))
    request_date = fuzzy.FuzzyDate(datetime.date(2008, 1, 1))
    service = SubFactory(ServiceCatalogFactory)
    service_name = SubFactory(ServiceFactory)
    # sn exists below, as a lazy_attribute
    source = AssetSource.shipment
    status = AssetStatus.new
    task_url = Sequence(lambda n: 'http://www.url-{}.com/'.format(n))
    user = SubFactory(UserFactory)
    warehouse = SubFactory(WarehouseFactory)

    @lazy_attribute
    def barcode(self):
        return generate_barcode()

    @lazy_attribute
    def sn(self):
        return generate_sn()

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

        if extracted:
            self.device_environment = extracted
        else:
            if self.service:
                ci_relation = CIRelationFactory(parent=self.service)
                self.device_environment = ci_relation.child

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

        if extracted:
            # A list of supports were passed in, use them
            for support in extracted:
                self.supports.add(support)
Esempio n. 22
0
 def test_aware_start(self):
     """Tests that a timezone-aware start datetime is rejected."""
     with self.assertRaises(ValueError):
         fuzzy.FuzzyNaiveDateTime(self.jan1.replace(tzinfo=datetime.timezone.utc), self.jan31)
Esempio n. 23
0
 def test_invalid_partial_definition(self):
     with utils.mocked_datetime_now(self.jan1, fuzzy):
         with self.assertRaises(ValueError):
             fuzzy.FuzzyNaiveDateTime(self.jan31)
Esempio n. 24
0
 def test_aware_end(self):
     """Tests that a timezone-aware end datetime is rejected."""
     with self.assertRaises(ValueError):
         fuzzy.FuzzyNaiveDateTime(self.jan1,
                                  self.jan31.replace(tzinfo=compat.UTC))