Fix timezone issues and create coffee view unit test

This commit is contained in:
Jan Tuomi
2017-09-25 19:45:58 +03:00
parent e00f1edaa0
commit 91a0694ae5
6 changed files with 67 additions and 13 deletions
+5 -4
View File
@@ -3,7 +3,8 @@
import urllib.request
import json
import logging
from datetime import datetime, timedelta
from datetime import timedelta, datetime
from django.utils import timezone
from django.conf import settings
@@ -20,7 +21,7 @@ class HSLFetcher:
def fetch_if_needed(self):
"""Check if new fetch from HSL API is needed."""
if (datetime.now() - HSLFetcher.last_fetched >
if (timezone.now() - HSLFetcher.last_fetched >
timedelta(minutes=HSLFetcher.INTERVAL)):
self.fetch()
@@ -38,7 +39,7 @@ class HSLFetcher:
arr = []
time = (datetime.now() +
time = (timezone.now() +
timedelta(minutes=settings.HSL_DEPARTURE_THRESHOLD))
time = "{0:02d}{0:02d}".format(time.hour, time.minute)
for element in data:
@@ -65,7 +66,7 @@ class HSLFetcher:
obj = model_arr[count - 1]
obj.data = json_dump
obj.save()
now = datetime.now()
now = timezone.now()
HSLFetcher.last_fetched = now
logging.info(