fixing tests
This commit is contained in:
@@ -23,6 +23,15 @@ from json.decoder import JSONDecodeError
|
|||||||
|
|
||||||
from pytz.exceptions import UnknownTimeZoneError
|
from pytz.exceptions import UnknownTimeZoneError
|
||||||
|
|
||||||
|
def dologging(s):
|
||||||
|
tstamp = time.localtime()
|
||||||
|
timestamp = time.strftime('%b-%d-%Y %H:%M:%S', tstamp)
|
||||||
|
with open('debuglog.log','a') as f:
|
||||||
|
f.write('\n')
|
||||||
|
f.write(timestamp)
|
||||||
|
f.write(' ')
|
||||||
|
f.write(s)
|
||||||
|
|
||||||
from rowsandall_app.settings import (
|
from rowsandall_app.settings import (
|
||||||
C2_CLIENT_ID, C2_REDIRECT_URI, C2_CLIENT_SECRET,
|
C2_CLIENT_ID, C2_REDIRECT_URI, C2_CLIENT_SECRET,
|
||||||
UPLOAD_SERVICE_URL, UPLOAD_SERVICE_SECRET
|
UPLOAD_SERVICE_URL, UPLOAD_SERVICE_SECRET
|
||||||
@@ -695,7 +704,7 @@ def createc2workoutdata(w):
|
|||||||
workouttype = 'water'
|
workouttype = 'water'
|
||||||
|
|
||||||
|
|
||||||
wendtime = w.startdatetime-datetime.timedelta(seconds=makeseconds(durationstr))
|
wendtime = w.startdatetime+datetime.timedelta(seconds=makeseconds(durationstr))
|
||||||
|
|
||||||
data = {
|
data = {
|
||||||
"type": mytypes.c2mapping[workouttype],
|
"type": mytypes.c2mapping[workouttype],
|
||||||
@@ -1018,7 +1027,9 @@ def workout_c2_upload(user,w,asynchron=False):
|
|||||||
if not c2userid: # pragma: no cover
|
if not c2userid: # pragma: no cover
|
||||||
raise NoTokenError("User has no token")
|
raise NoTokenError("User has no token")
|
||||||
|
|
||||||
|
dologging('Upload to C2 user {userid}'.format(userid=user.id))
|
||||||
data = createc2workoutdata(w)
|
data = createc2workoutdata(w)
|
||||||
|
dologging(json.dumps(data))
|
||||||
|
|
||||||
if data == 0: # pragma: no cover
|
if data == 0: # pragma: no cover
|
||||||
return "Error: No data file. Contact info@rowsandall.com if the problem persists",0
|
return "Error: No data file. Contact info@rowsandall.com if the problem persists",0
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ import iso8601
|
|||||||
from iso8601 import ParseError
|
from iso8601 import ParseError
|
||||||
|
|
||||||
from json.decoder import JSONDecodeError
|
from json.decoder import JSONDecodeError
|
||||||
|
from pytz.exceptions import UnknownTimeZoneError
|
||||||
|
|
||||||
from matplotlib.backends.backend_agg import FigureCanvas
|
from matplotlib.backends.backend_agg import FigureCanvas
|
||||||
#from matplotlib.backends.backend_cairo import FigureCanvasCairo as FigureCanvas
|
#from matplotlib.backends.backend_cairo import FigureCanvasCairo as FigureCanvas
|
||||||
@@ -3032,7 +3032,10 @@ def handle_c2_async_workout(alldata,userid,c2token,c2id,delaysec,defaulttimezone
|
|||||||
starttimeunix = arrow.get(startdatetime).timestamp()-totaltime
|
starttimeunix = arrow.get(startdatetime).timestamp()-totaltime
|
||||||
startdatetime = arrow.get(starttimeunix)
|
startdatetime = arrow.get(starttimeunix)
|
||||||
|
|
||||||
timezone = pytz.timezone(data['timezone'])
|
try:
|
||||||
|
timezone = pytz.timezone(data['timezone'])
|
||||||
|
except UnknownTimeZoneError:
|
||||||
|
timezone = 'UTC'
|
||||||
startdatetime = startdatetime.astimezone(timezone)
|
startdatetime = startdatetime.astimezone(timezone)
|
||||||
|
|
||||||
s = 'Time zone {timezone}, stardatetime {startdatetime}, duration {duration}'.format(
|
s = 'Time zone {timezone}, stardatetime {startdatetime}, duration {duration}'.format(
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ from django.db import transaction
|
|||||||
from .statements import *
|
from .statements import *
|
||||||
nu = datetime.datetime.now()
|
nu = datetime.datetime.now()
|
||||||
|
|
||||||
|
import numpy as np
|
||||||
|
|
||||||
import rowers
|
import rowers
|
||||||
from rowers import dataprep
|
from rowers import dataprep
|
||||||
@@ -188,7 +189,7 @@ class GarminObjects(DjangoTestCase):
|
|||||||
response = self.c.get(url,follow=True)
|
response = self.c.get(url,follow=True)
|
||||||
|
|
||||||
self.assertEqual(response.status_code,200)
|
self.assertEqual(response.status_code,200)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
@override_settings(TESTING=True)
|
@override_settings(TESTING=True)
|
||||||
@@ -249,10 +250,15 @@ class C2Objects(DjangoTestCase):
|
|||||||
|
|
||||||
def test_timezone_c2(self):
|
def test_timezone_c2(self):
|
||||||
data = c2stuff.createc2workoutdata(self.w)
|
data = c2stuff.createc2workoutdata(self.w)
|
||||||
wenddtime = self.w.startdatetime-datetime.timedelta(seconds=self.totaltime)
|
wenddtime = self.w.startdatetime+datetime.timedelta(seconds=self.totaltime)
|
||||||
|
t1 = arrow.get(wenddtime).timestamp()
|
||||||
|
t2 = arrow.get(data['date']).timestamp()
|
||||||
|
diff = np.abs(t1-t2)
|
||||||
|
|
||||||
|
|
||||||
self.assertEqual(data['timezone'],'Europe/Amsterdam')
|
self.assertEqual(data['timezone'],'Europe/Amsterdam')
|
||||||
self.assertEqual(data['date'],wenddtime.strftime('%Y-%m-%d %H:%M:%S'))
|
self.assertTrue(diff<2)
|
||||||
|
#self.assertEqual(data['date'],wenddtime.strftime('%Y-%m-%d %H:%M:%S'))
|
||||||
|
|
||||||
|
|
||||||
@patch('rowers.c2stuff.Session', side_effect=mocked_requests)
|
@patch('rowers.c2stuff.Session', side_effect=mocked_requests)
|
||||||
|
|||||||
@@ -14,6 +14,15 @@ def default(o): # pragma: no cover
|
|||||||
|
|
||||||
from rowsandall_app.settings import NK_OAUTH_LOCATION
|
from rowsandall_app.settings import NK_OAUTH_LOCATION
|
||||||
|
|
||||||
|
def dologging(s):
|
||||||
|
tstamp = time.localtime()
|
||||||
|
timestamp = time.strftime('%b-%d-%Y %H:%M:%S', tstamp)
|
||||||
|
with open('debuglog.log','a') as f:
|
||||||
|
f.write('\n')
|
||||||
|
f.write(timestamp)
|
||||||
|
f.write(' ')
|
||||||
|
f.write(s)
|
||||||
|
|
||||||
# Send workout to TP
|
# Send workout to TP
|
||||||
@permission_required('workout.change_workout',fn=get_workout_by_opaqueid,raise_exception=True)
|
@permission_required('workout.change_workout',fn=get_workout_by_opaqueid,raise_exception=True)
|
||||||
def workout_tp_upload_view(request,id=0):
|
def workout_tp_upload_view(request,id=0):
|
||||||
@@ -188,6 +197,13 @@ def workout_c2_upload_view(request,id=0):
|
|||||||
w = get_workout(id)
|
w = get_workout(id)
|
||||||
r = w.user
|
r = w.user
|
||||||
|
|
||||||
|
s = 'C2 Upload Workout starttime {startdatetime} timezone {timezone} user id {userid}'.format(
|
||||||
|
startdatetime = w.startdatetime,
|
||||||
|
timezone = w.timezone,
|
||||||
|
userid = w.user.user.id
|
||||||
|
)
|
||||||
|
dologging(s)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
message,c2id = c2stuff.workout_c2_upload(request.user,w)
|
message,c2id = c2stuff.workout_c2_upload(request.user,w)
|
||||||
except NoTokenError: # pragma: no cover
|
except NoTokenError: # pragma: no cover
|
||||||
|
|||||||
Reference in New Issue
Block a user