Private
Public Access
1
0

fixing tests

This commit is contained in:
Sander Roosendaal
2021-05-20 21:23:31 +02:00
parent b5660813fa
commit 3d208527ee
4 changed files with 42 additions and 6 deletions

View File

@@ -23,6 +23,15 @@ from json.decoder import JSONDecodeError
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 (
C2_CLIENT_ID, C2_REDIRECT_URI, C2_CLIENT_SECRET,
UPLOAD_SERVICE_URL, UPLOAD_SERVICE_SECRET
@@ -695,7 +704,7 @@ def createc2workoutdata(w):
workouttype = 'water'
wendtime = w.startdatetime-datetime.timedelta(seconds=makeseconds(durationstr))
wendtime = w.startdatetime+datetime.timedelta(seconds=makeseconds(durationstr))
data = {
"type": mytypes.c2mapping[workouttype],
@@ -1018,7 +1027,9 @@ def workout_c2_upload(user,w,asynchron=False):
if not c2userid: # pragma: no cover
raise NoTokenError("User has no token")
dologging('Upload to C2 user {userid}'.format(userid=user.id))
data = createc2workoutdata(w)
dologging(json.dumps(data))
if data == 0: # pragma: no cover
return "Error: No data file. Contact info@rowsandall.com if the problem persists",0

View File

@@ -35,7 +35,7 @@ import iso8601
from iso8601 import ParseError
from json.decoder import JSONDecodeError
from pytz.exceptions import UnknownTimeZoneError
from matplotlib.backends.backend_agg import 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
startdatetime = arrow.get(starttimeunix)
timezone = pytz.timezone(data['timezone'])
try:
timezone = pytz.timezone(data['timezone'])
except UnknownTimeZoneError:
timezone = 'UTC'
startdatetime = startdatetime.astimezone(timezone)
s = 'Time zone {timezone}, stardatetime {startdatetime}, duration {duration}'.format(

View File

@@ -9,6 +9,7 @@ from django.db import transaction
from .statements import *
nu = datetime.datetime.now()
import numpy as np
import rowers
from rowers import dataprep
@@ -188,7 +189,7 @@ class GarminObjects(DjangoTestCase):
response = self.c.get(url,follow=True)
self.assertEqual(response.status_code,200)
@pytest.mark.django_db
@override_settings(TESTING=True)
@@ -249,10 +250,15 @@ class C2Objects(DjangoTestCase):
def test_timezone_c2(self):
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['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)

View File

@@ -14,6 +14,15 @@ def default(o): # pragma: no cover
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
@permission_required('workout.change_workout',fn=get_workout_by_opaqueid,raise_exception=True)
def workout_tp_upload_view(request,id=0):
@@ -188,6 +197,13 @@ def workout_c2_upload_view(request,id=0):
w = get_workout(id)
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:
message,c2id = c2stuff.workout_c2_upload(request.user,w)
except NoTokenError: # pragma: no cover