Exemplo n.º 1
0
    def test_get_past_datetime(self):
        now = datetime.datetime.utcnow()
        for x in range(5):
            dt = testdata.get_past_datetime()
            self.assertGreater(now, dt)

        for x in range(5):
            dt = testdata.get_past_datetime(now)
            self.assertGreater(now, dt)
            now = dt
Exemplo n.º 2
0
    def get_fields(self, schema, **field_kwargs):
        """return the fields of orm with randomized data"""
        fields = {}
        for k, v in schema.fields.items():
            if v.is_pk(): continue

            if issubclass(v.type, basestring):
                fields[k] = testdata.get_words()

            elif issubclass(v.type, int):
                fields[k] = testdata.get_int32()

            elif issubclass(v.type, long):
                fields[k] = testdata.get_int64()

            elif issubclass(v.type, datetime.datetime):
                fields[k] = testdata.get_past_datetime()

            elif issubclass(v.type, float):
                fields[k] = testdata.get_float()

            elif issubclass(v.type, bool):
                fields[k] = True if random.randint(0, 1) == 1 else False

            else:
                raise ValueError("{}".format(v.type))

        fields.update(field_kwargs)
        return fields
Exemplo n.º 3
0
    def get_fields(self, schema, **field_kwargs):
        """return the fields of orm with randomized data"""
        fields = {}
        for k, v in schema.fields.items():
            if v.is_pk(): continue

            if issubclass(v.type, basestring):
                fields[k] = testdata.get_words()

            elif issubclass(v.type, int):
                fields[k] = testdata.get_int32()

            elif issubclass(v.type, long):
                fields[k] = testdata.get_int64()

            elif issubclass(v.type, datetime.datetime):
                fields[k] = testdata.get_past_datetime()

            elif issubclass(v.type, float):
                fields[k] = testdata.get_float()

            elif issubclass(v.type, bool):
                fields[k] = True if random.randint(0, 1) == 1 else False

            else:
                raise ValueError("{}".format(v.type))

        fields.update(field_kwargs)
        return fields
Exemplo n.º 4
0
    def test_updated_set(self):
        orm_class = self.get_orm_class()
        o = orm_class(foo=1, bar="1")

        _updated = testdata.get_past_datetime()
        o._updated = _updated
        o.save()

        o2 = o.query.eq_pk(o.pk).one()
        self.assertEqual(_updated, o2._updated)

        _updated2 = testdata.get_past_datetime()
        o2._updated = _updated2
        o2.save()

        o3 = o.query.eq_pk(o.pk).one()
        self.assertEqual(_updated2, o3._updated)
Exemplo n.º 5
0
    def test_non_list(self):
        r = make_list(1)
        self.assertEqual([1], r)

        r = make_list("foo")
        self.assertEqual(["foo"], r)

        r = make_list(testdata.get_past_datetime())
        self.assertEqual(1, len(r))
Exemplo n.º 6
0
 def test_in_past(self):
     future_sesh = Session.objects.create(
         name = testdata.get_str(str_size=128),
         when = testdata.get_future_datetime(),
         where = self.create_site(),
     )
     future_sesh.save()
     past_sesh = Session.objects.create(
         name = testdata.get_str(str_size=128),
         when = testdata.get_past_datetime(),
         where = self.create_site(),
     )
     past_sesh.save()
     self.assertFalse(future_sesh.in_past())
     self.assertTrue(past_sesh.in_past())
Exemplo n.º 7
0
    def test_get_between_datetime(self):
        start = testdata.get_past_datetime()
        for x in range(5):
            dt = testdata.get_between_datetime(start)
            now = datetime.datetime.utcnow()
            self.assertGreater(now, dt)

        time.sleep(0.1)
        stop = datetime.datetime.utcnow()
        for x in range(5):
            dt = testdata.get_between_datetime(start, stop)
            self.assertGreater(dt, start)
            self.assertGreater(stop, dt)
            start = dt

        now = datetime.datetime.utcnow()
        with self.assertRaises(ValueError):
            dt = testdata.get_between_datetime(now, now)
Exemplo n.º 8
0
 def test_get_between_datetime_same_microseconds(self):
     """noticed a problem when using the same now"""
     now = datetime.datetime.utcnow()
     start_dt = testdata.get_past_datetime(now)
     stop_dt = testdata.get_between_datetime(start_dt, now)
     self.assertGreater(stop_dt, start_dt)