def handler(entity): if isinstance(entity, datetime.datetime): return dateutils.to_iso(entity) elif isinstance(entity, bytes): return entity.decode('utf-8') raise NotImplementedError(""" You should implement method `dumps(self, data)` in your view class and override default json handler """)
def create_event_upcoming_fixtures(number=50): events_upcoming = (dict( name=f'Name{i}', location=f'Location{i}', start_date=to_iso(datetime.datetime.utcnow() + datetime.timedelta(days=(i % 50) * 365)), end_date=datetime.datetime.utcnow(), key=event_urls[i % len(event_urls)], lat=40.123456, lon=38.6543211, ) for i in range(number)) Event.insert_many(events_upcoming).execute()
def setUp(self): super().setUp() self.now = to_iso(datetime.datetime.utcnow()) self.manager = peewee_async.Manager(self.database, loop=self.loop) for m in self.models: m._meta.database = self.database m.objects = self.manager self.database.create_tables(self.models, safe=True) self.create_fixtures()
def iso_test(self, tz_name): utcnow = datetime.datetime.utcnow() iso = dateutils.to_iso(utcnow, tz_name) matched = re.match(self.regex, iso) offseted = utcnow + pytz.timezone(tz_name).utcoffset(utcnow) self.assertTrue(offseted.hour == int(matched.group(4)))
async def test_dateutil_now_timezone_isoformat_minus(self): dt = dateutils.now('Europe/Moscow') matched = re.match(self.regex, dateutils.to_iso(dt)) self.assertTrue(matched is not None)
async def test_dateutil_now_timezone_isoformat(self): dt = dateutils.now() matched = re.match(self.regex, dateutils.to_iso(dt)) self.assertTrue(matched is not None)
def setUp(self): self.now = to_iso(datetime.datetime.utcnow()) self.loop = asyncio.new_event_loop() asyncio.set_event_loop(None)