Dajngo 1.5 Timezone.now()
I am newbie and trying to make my Unit Test pass but having problems with
DateTimeField.
In my settings, I have USE_TZ = True and TIME_ZONE set.
Using MongoDb.
First the test is giving me an error complaining about comparing
offset-naive and offset-aware. Changed auto_now_add=True to
datetime.datetime.utcnow().replace(tzinfo=utc))
I Still couldn't get the right time and date to my TIME_ZONE.
After I put these in my Database (settings.py)
'OPTIONS' : {
'tz_aware' : True,
}
Now I can change my TIME_ZONE and the time and date shows my localtime,
not utc.
But when I run a test model:
nf.data_emissao = timezone.now()
...
#check if the nf is in database
lista_nfse = Nfse.objects.all()
self.assertEquals(lista_nfse.count(), 1)
nfse_no_banco = lista_nfse[0]
...
self.assertEquals( nfse_no_banco.data_emissao, nf.data_emissao)
My test fails:
AssertionError: datetime.datetime(2013, 8, 10, 2, 49, 59, 391000, tzinfo=
<bson.tz_util.FixedOffset object at 0x2bdd1d0>) != datetime.datetime(2013,
8, 10, 2, 49, 59,
391122, tzinfo=<UTC>)
I see the diff between 391000 and 391122 but don't know how to fix that.
No comments:
Post a Comment