I have the following model and form
class TravelShare(Share): # indirect derived via Share from models.Model
source = models.PointField(geography=True, srid=4326)
destination = models.PointField(geography=True, srid=4326)
departure = models.DateTimeField(default=timezone.now)
departure_delta = models.SmallIntegerField(default=60)
objects = TravelShareManager()
def __str__(self):
return self.id
class TravelShareForm(forms.ModelForm):
class Meta:
model = TravelShare
fields = ['source', 'destination', 'departure', 'departure_delta']
When testing the form with
def test_TravelShareCreate(self):
source = Point(x=48.0, y=11.0, srid=4326)
destination = Point(x=48.0001, y=11.0001, srid=4326)
now = timezone.localtime(timezone.now())
print ("now : %s" % (now))
now_string = now.strftime('%m.%d.%Y %H:%M:%S')
form_data = {
'source': source,
'destination': destination,
'departure': now_string,
'departure_delta': 30,
}
form = TravelShareForm (form_data)
print (form.errors)
self.assertTrue(form.is_valid())
form.instance.creator = self.creator
result = form.save()
self.assertEqual(result.creator_id, self.creator.id)
self.assertEqual(result.source, source)
self.assertEqual(result.destination, destination)
result_dep = timezone.localtime(result.departure)
print("result_dep : %s" % (result_dep))
self.assertEqual(result.departure, now)
I am ending up in
now : 2017-02-10 15:49:21.935894+01:00
result_dep : 2017-10-02 15:49:21+02:00
Failure
Traceback (most recent call last): File "/home/michael/PycharmProjects/sharadar/main/tests/test_forms.py", line 43, in test_TravelShareCreate self.assertEqual(result.departure, now) AssertionError: datet[14 chars]017, 10, 2, 15, 49, 21, tzinfo=DstTzInfo 'Eur[25 chars]DST) != datet[14 chars]017, 2, 10, 15, 49, 21, 935894, tzinfo=DstTzI[32 chars]STD
It seems that the resulted DateTime has a different TZ or at least shows +2 instead of +1
Thanks for any help
Michael