passing all tests on py3
This commit is contained in:
@@ -16,6 +16,8 @@ import rowers.mytypes as mytypes
|
|||||||
from rowers.mytypes import otwtypes
|
from rowers.mytypes import otwtypes
|
||||||
from iso8601 import ParseError
|
from iso8601 import ParseError
|
||||||
|
|
||||||
|
import numpy
|
||||||
|
|
||||||
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
|
||||||
)
|
)
|
||||||
@@ -424,7 +426,11 @@ def createc2workoutdata(w):
|
|||||||
hr = 0*d
|
hr = 0*d
|
||||||
stroke_data = []
|
stroke_data = []
|
||||||
for i in range(len(t)):
|
for i in range(len(t)):
|
||||||
thisrecord = {"t":t[i],"d":d[i],"p":p[i],"spm":spm[i],"hr":hr[i]}
|
thisrecord = {"t":t[i].astype(int),
|
||||||
|
"d":d[i].astype(int),
|
||||||
|
"p":p[i].astype(int),
|
||||||
|
"spm":spm[i].astype(int),
|
||||||
|
"hr":hr[i].astype(int)}
|
||||||
stroke_data.append(thisrecord)
|
stroke_data.append(thisrecord)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@@ -440,7 +446,7 @@ def createc2workoutdata(w):
|
|||||||
startdatetime = w.startdatetime.isoformat()
|
startdatetime = w.startdatetime.isoformat()
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
startdate = datetime.datetime.combine(w.date,datetime.time())
|
startdate = datetime.datetime.combine(w.date,datetime.time())
|
||||||
|
|
||||||
data = {
|
data = {
|
||||||
"type": mytypes.c2mapping[workouttype],
|
"type": mytypes.c2mapping[workouttype],
|
||||||
"date": w.startdatetime.isoformat(),
|
"date": w.startdatetime.isoformat(),
|
||||||
@@ -551,7 +557,7 @@ def make_authorization_url(request):
|
|||||||
params = {"client_id": C2_CLIENT_ID,
|
params = {"client_id": C2_CLIENT_ID,
|
||||||
"response_type": "code",
|
"response_type": "code",
|
||||||
"redirect_uri": C2_REDIRECT_URI}
|
"redirect_uri": C2_REDIRECT_URI}
|
||||||
url = "https://log.concept2.com/oauth/authorize?"+ urllib.urlencode(params)
|
url = "https://log.concept2.com/oauth/authorize?"+ urllib.parse.urlencode(params)
|
||||||
url += "&scope="+scope
|
url += "&scope="+scope
|
||||||
|
|
||||||
return HttpResponseRedirect(url)
|
return HttpResponseRedirect(url)
|
||||||
@@ -697,6 +703,10 @@ def process_callback(request):
|
|||||||
|
|
||||||
return HttpResponse("got a user name: %s" % username)
|
return HttpResponse("got a user name: %s" % username)
|
||||||
|
|
||||||
|
def default(o):
|
||||||
|
if isinstance(o, numpy.int64): return int(o)
|
||||||
|
raise TypeError
|
||||||
|
|
||||||
# Uploading workout
|
# Uploading workout
|
||||||
def workout_c2_upload(user,w):
|
def workout_c2_upload(user,w):
|
||||||
message = 'trying C2 upload'
|
message = 'trying C2 upload'
|
||||||
@@ -717,6 +727,7 @@ def workout_c2_upload(user,w):
|
|||||||
raise NoTokenError
|
raise NoTokenError
|
||||||
|
|
||||||
data = createc2workoutdata(w)
|
data = createc2workoutdata(w)
|
||||||
|
|
||||||
if data == 0:
|
if data == 0:
|
||||||
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
|
||||||
|
|
||||||
@@ -726,7 +737,7 @@ def workout_c2_upload(user,w):
|
|||||||
'Content-Type': 'application/json'}
|
'Content-Type': 'application/json'}
|
||||||
import urllib
|
import urllib
|
||||||
url = "https://log.concept2.com/api/users/%s/results" % (c2userid)
|
url = "https://log.concept2.com/api/users/%s/results" % (c2userid)
|
||||||
response = requests.post(url,headers=headers,data=json.dumps(data))
|
response = requests.post(url,headers=headers,data=json.dumps(data,default=default))
|
||||||
|
|
||||||
if (response.status_code == 409 ):
|
if (response.status_code == 409 ):
|
||||||
message = "Concept2 Duplicate error"
|
message = "Concept2 Duplicate error"
|
||||||
|
|||||||
@@ -280,7 +280,7 @@ def imports_make_authorization_url(oauth_data):
|
|||||||
|
|
||||||
|
|
||||||
import urllib
|
import urllib
|
||||||
url = oauth_data['authorizaton_uri']+urllib.urlencode(params)
|
url = oauth_data['authorizaton_uri']+urllib.parse.urlencode(params)
|
||||||
|
|
||||||
return HttpResponseRedirect(url)
|
return HttpResponseRedirect(url)
|
||||||
|
|
||||||
|
|||||||
@@ -1,13 +1,17 @@
|
|||||||
#!/srv/venv/bin/python
|
#!/srv/venv/bin/python
|
||||||
|
|
||||||
""" Process emails """
|
""" Process emails """
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
|
PY3K = sys.version_info >= (3, 0)
|
||||||
|
|
||||||
import zipfile
|
import zipfile
|
||||||
import re
|
import re
|
||||||
import time
|
import time
|
||||||
from time import strftime
|
from time import strftime
|
||||||
|
|
||||||
|
import io
|
||||||
|
|
||||||
from django.core.management.base import BaseCommand
|
from django.core.management.base import BaseCommand
|
||||||
from django_mailbox.models import Message, MessageAttachment,Mailbox
|
from django_mailbox.models import Message, MessageAttachment,Mailbox
|
||||||
from django.core.urlresolvers import reverse
|
from django.core.urlresolvers import reverse
|
||||||
@@ -62,7 +66,7 @@ def processattachment(rower, fileobj, title, uploadoptions,testing=False):
|
|||||||
|
|
||||||
# test if file exists and is not empty
|
# test if file exists and is not empty
|
||||||
try:
|
try:
|
||||||
with open('media/'+filename,'r') as fop:
|
with io.open('media/'+filename,'rb') as fop:
|
||||||
line = fop.readline()
|
line = fop.readline()
|
||||||
except (IOError, UnicodeEncodeError):
|
except (IOError, UnicodeEncodeError):
|
||||||
if testing:
|
if testing:
|
||||||
@@ -164,6 +168,11 @@ def get_from_address(message):
|
|||||||
except IndexError:
|
except IndexError:
|
||||||
first_line = ''
|
first_line = ''
|
||||||
|
|
||||||
|
try:
|
||||||
|
first_line = first_line.decode('utf-8')
|
||||||
|
except AttributeError:
|
||||||
|
pass
|
||||||
|
|
||||||
if "quiske" in first_line:
|
if "quiske" in first_line:
|
||||||
match = re.search(r'[\w\.-]+@[\w\.-]+', first_line)
|
match = re.search(r'[\w\.-]+@[\w\.-]+', first_line)
|
||||||
return match.group(0)
|
return match.group(0)
|
||||||
|
|||||||
@@ -128,7 +128,7 @@ def make_authorization_url(request):
|
|||||||
|
|
||||||
|
|
||||||
import urllib
|
import urllib
|
||||||
url = "http://localhost:8000/rowers/o/authorize" +urllib.urlencode(params)
|
url = "http://localhost:8000/rowers/o/authorize" +urllib.parse.urlencode(params)
|
||||||
|
|
||||||
return HttpResponseRedirect(url)
|
return HttpResponseRedirect(url)
|
||||||
|
|
||||||
|
|||||||
@@ -106,7 +106,7 @@ def make_authorization_url():
|
|||||||
"redirect_uri": POLAR_REDIRECT_URI,
|
"redirect_uri": POLAR_REDIRECT_URI,
|
||||||
"scope":"write"}
|
"scope":"write"}
|
||||||
import urllib
|
import urllib
|
||||||
url = "https://flow.polar.com/oauth2/authorization" +urllib.urlencode(params)
|
url = "https://flow.polar.com/oauth2/authorization" +urllib.parse.urlencode(params)
|
||||||
|
|
||||||
|
|
||||||
return HttpResponseRedirect(url)
|
return HttpResponseRedirect(url)
|
||||||
|
|||||||
@@ -29,6 +29,8 @@ oauth_data = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
import numpy
|
||||||
|
|
||||||
def splitrunkeeperlatlongdata(lijst,tname,latname,lonname):
|
def splitrunkeeperlatlongdata(lijst,tname,latname,lonname):
|
||||||
t = []
|
t = []
|
||||||
lat = []
|
lat = []
|
||||||
@@ -262,6 +264,10 @@ def get_userid(access_token):
|
|||||||
|
|
||||||
return str(res)
|
return str(res)
|
||||||
|
|
||||||
|
def default(o):
|
||||||
|
if isinstance(o, numpy.int64): return int(o)
|
||||||
|
raise TypeError
|
||||||
|
|
||||||
def workout_runkeeper_upload(user,w):
|
def workout_runkeeper_upload(user,w):
|
||||||
message = "Uploading to Runkeeper"
|
message = "Uploading to Runkeeper"
|
||||||
rkid = 0
|
rkid = 0
|
||||||
@@ -287,7 +293,7 @@ def workout_runkeeper_upload(user,w):
|
|||||||
'Content-Length':'nnn'}
|
'Content-Length':'nnn'}
|
||||||
|
|
||||||
url = "https://api.runkeeper.com/fitnessActivities"
|
url = "https://api.runkeeper.com/fitnessActivities"
|
||||||
response = requests.post(url,headers=headers,data=json.dumps(data))
|
response = requests.post(url,headers=headers,data=json.dumps(data,default=default))
|
||||||
|
|
||||||
# check for duplicate error first
|
# check for duplicate error first
|
||||||
if (response.status_code == 409 ):
|
if (response.status_code == 409 ):
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ from __future__ import unicode_literals
|
|||||||
from __future__ import unicode_literals, absolute_import
|
from __future__ import unicode_literals, absolute_import
|
||||||
# All the functionality to connect to SportTracks
|
# All the functionality to connect to SportTracks
|
||||||
|
|
||||||
|
import numpy
|
||||||
|
|
||||||
from rowers.imports import *
|
from rowers.imports import *
|
||||||
import re
|
import re
|
||||||
from rowsandall_app.settings import (
|
from rowsandall_app.settings import (
|
||||||
@@ -235,6 +237,11 @@ def getidfromresponse(response):
|
|||||||
|
|
||||||
return int(id)
|
return int(id)
|
||||||
|
|
||||||
|
def default(o):
|
||||||
|
if isinstance(o, numpy.int64): return int(o)
|
||||||
|
raise TypeError
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def workout_sporttracks_upload(user,w):
|
def workout_sporttracks_upload(user,w):
|
||||||
message = "Uploading to SportTracks"
|
message = "Uploading to SportTracks"
|
||||||
@@ -257,7 +264,7 @@ def workout_sporttracks_upload(user,w):
|
|||||||
'Content-Type': 'application/json'}
|
'Content-Type': 'application/json'}
|
||||||
|
|
||||||
url = "https://api.sporttracks.mobi/api/v2/fitnessActivities.json"
|
url = "https://api.sporttracks.mobi/api/v2/fitnessActivities.json"
|
||||||
response = requests.post(url,headers=headers,data=json.dumps(data))
|
response = requests.post(url,headers=headers,data=json.dumps(data,default=default))
|
||||||
|
|
||||||
# check for duplicate error first
|
# check for duplicate error first
|
||||||
if (response.status_code == 409 ):
|
if (response.status_code == 409 ):
|
||||||
|
|||||||
@@ -16,11 +16,12 @@ class TestErrorPages(TestCase):
|
|||||||
factory = RequestFactory()
|
factory = RequestFactory()
|
||||||
request = factory.get('/')
|
request = factory.get('/')
|
||||||
response = error404_view(request)
|
response = error404_view(request)
|
||||||
|
|
||||||
self.assertEqual(response.status_code, 404)
|
self.assertEqual(response.status_code, 404)
|
||||||
self.assertIn('404 Page not found', unicode(response))
|
self.assertIn('404 Page not found', str(response.content))
|
||||||
response = error500_view(request)
|
response = error500_view(request)
|
||||||
self.assertEqual(response.status_code, 500)
|
self.assertEqual(response.status_code, 500)
|
||||||
self.assertIn('500 Internal Server Error', unicode(response))
|
self.assertIn('500 Internal Server Error', str(response.content))
|
||||||
|
|
||||||
response = error400_view(request)
|
response = error400_view(request)
|
||||||
self.assertEqual(response.status_code, 400)
|
self.assertEqual(response.status_code, 400)
|
||||||
|
|||||||
BIN
rowers/tests/testdata/testdata.csv.gz
vendored
BIN
rowers/tests/testdata/testdata.csv.gz
vendored
Binary file not shown.
@@ -5,6 +5,8 @@ from __future__ import unicode_literals
|
|||||||
from __future__ import unicode_literals, absolute_import
|
from __future__ import unicode_literals, absolute_import
|
||||||
from rowers.imports import *
|
from rowers.imports import *
|
||||||
|
|
||||||
|
import numpy
|
||||||
|
|
||||||
import rowers.mytypes as mytypes
|
import rowers.mytypes as mytypes
|
||||||
from rowers.mytypes import otwtypes
|
from rowers.mytypes import otwtypes
|
||||||
|
|
||||||
@@ -305,6 +307,11 @@ def get_userid(access_token):
|
|||||||
|
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
def default(o):
|
||||||
|
if isinstance(o, numpy.int64): return int(o)
|
||||||
|
raise TypeError
|
||||||
|
|
||||||
|
|
||||||
def workout_ua_upload(user,w):
|
def workout_ua_upload(user,w):
|
||||||
message = "Uploading to MapMyFitness"
|
message = "Uploading to MapMyFitness"
|
||||||
uaid = 0
|
uaid = 0
|
||||||
@@ -331,7 +338,7 @@ def workout_ua_upload(user,w):
|
|||||||
}
|
}
|
||||||
|
|
||||||
url = "https://api.ua.com/v7.1/workout/"
|
url = "https://api.ua.com/v7.1/workout/"
|
||||||
response = requests.post(url,headers=headers,data=json.dumps(data))
|
response = requests.post(url,headers=headers,data=json.dumps(data,default=default))
|
||||||
|
|
||||||
# check for duplicate error first
|
# check for duplicate error first
|
||||||
if (response.status_code == 409 ):
|
if (response.status_code == 409 ):
|
||||||
|
|||||||
@@ -44,6 +44,11 @@ from rowers.utils import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
def cleanbody(body):
|
def cleanbody(body):
|
||||||
|
try:
|
||||||
|
body = body.decode('utf-8')
|
||||||
|
except AttributeError:
|
||||||
|
pass
|
||||||
|
|
||||||
regex = r".*---\n([\s\S]*?)\.\.\..*"
|
regex = r".*---\n([\s\S]*?)\.\.\..*"
|
||||||
matches = re.finditer(regex,body)
|
matches = re.finditer(regex,body)
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,12 @@ from __future__ import unicode_literals
|
|||||||
|
|
||||||
from rowers.views.statements import *
|
from rowers.views.statements import *
|
||||||
|
|
||||||
|
import numpy
|
||||||
|
|
||||||
|
def default(o):
|
||||||
|
if isinstance(o, numpy.int64): return int(o)
|
||||||
|
raise TypeError
|
||||||
|
|
||||||
|
|
||||||
# Send workout to TP
|
# Send workout to TP
|
||||||
@login_required()
|
@login_required()
|
||||||
@@ -228,7 +234,7 @@ def workout_runkeeper_upload_view(request,id=0):
|
|||||||
'Content-Length':'nnn'}
|
'Content-Length':'nnn'}
|
||||||
|
|
||||||
url = "https://api.runkeeper.com/fitnessActivities"
|
url = "https://api.runkeeper.com/fitnessActivities"
|
||||||
response = requests.post(url,headers=headers,data=json.dumps(data))
|
response = requests.post(url,headers=headers,data=json.dumps(data,default=default))
|
||||||
|
|
||||||
# check for duplicate error first
|
# check for duplicate error first
|
||||||
if (response.status_code == 409 ):
|
if (response.status_code == 409 ):
|
||||||
@@ -293,7 +299,7 @@ def workout_underarmour_upload_view(request,id=0):
|
|||||||
}
|
}
|
||||||
|
|
||||||
url = "https://api.ua.com/v7.1/workout/"
|
url = "https://api.ua.com/v7.1/workout/"
|
||||||
response = requests.post(url,headers=headers,data=json.dumps(data))
|
response = requests.post(url,headers=headers,data=json.dumps(data,default=default))
|
||||||
|
|
||||||
|
|
||||||
# check for duplicate error first
|
# check for duplicate error first
|
||||||
@@ -356,7 +362,7 @@ def workout_sporttracks_upload_view(request,id=0):
|
|||||||
'Content-Type': 'application/json'}
|
'Content-Type': 'application/json'}
|
||||||
|
|
||||||
url = "https://api.sporttracks.mobi/api/v2/fitnessActivities.json"
|
url = "https://api.sporttracks.mobi/api/v2/fitnessActivities.json"
|
||||||
response = requests.post(url,headers=headers,data=json.dumps(data))
|
response = requests.post(url,headers=headers,data=json.dumps(data,default=default))
|
||||||
|
|
||||||
|
|
||||||
# check for duplicate error first
|
# check for duplicate error first
|
||||||
|
|||||||
@@ -28,6 +28,9 @@ import isodate
|
|||||||
import re
|
import re
|
||||||
import cgi
|
import cgi
|
||||||
from icalendar import Calendar, Event
|
from icalendar import Calendar, Event
|
||||||
|
|
||||||
|
from functools import reduce
|
||||||
|
|
||||||
import rowers.braintreestuff as braintreestuff
|
import rowers.braintreestuff as braintreestuff
|
||||||
import rowers.payments as payments
|
import rowers.payments as payments
|
||||||
from rowers.opaque import encoder
|
from rowers.opaque import encoder
|
||||||
@@ -502,7 +505,7 @@ def remove_asynctask(request,id):
|
|||||||
def get_job_result(jobid):
|
def get_job_result(jobid):
|
||||||
if settings.TESTING:
|
if settings.TESTING:
|
||||||
return None
|
return None
|
||||||
elif settings.DEBUG:
|
elif settings.CELERY:
|
||||||
result = celery_result.AsyncResult(jobid).result
|
result = celery_result.AsyncResult(jobid).result
|
||||||
else:
|
else:
|
||||||
running_job_ids = rq_registry.get_job_ids()
|
running_job_ids = rq_registry.get_job_ids()
|
||||||
@@ -541,7 +544,7 @@ def get_job_status(jobid):
|
|||||||
'started_at':None,
|
'started_at':None,
|
||||||
}
|
}
|
||||||
return summary
|
return summary
|
||||||
elif settings.DEBUG:
|
elif settings.CELERY:
|
||||||
job = celery_result.AsyncResult(jobid)
|
job = celery_result.AsyncResult(jobid)
|
||||||
jobresult = job.result
|
jobresult = job.result
|
||||||
|
|
||||||
@@ -592,7 +595,7 @@ def get_job_status(jobid):
|
|||||||
return summary
|
return summary
|
||||||
|
|
||||||
def kill_async_job(request,id='aap'):
|
def kill_async_job(request,id='aap'):
|
||||||
if settings.DEBUG:
|
if settings.CELERY:
|
||||||
job = celery_result.AsyncResult(id)
|
job = celery_result.AsyncResult(id)
|
||||||
job.revoke()
|
job.revoke()
|
||||||
else:
|
else:
|
||||||
@@ -734,7 +737,7 @@ def get_stored_tasks_status(request):
|
|||||||
if finished:
|
if finished:
|
||||||
cache.set(id,100)
|
cache.set(id,100)
|
||||||
progress = 100
|
progress = 100
|
||||||
elif cached_progress>0:
|
elif cached_progress is not None and cached_progress>0:
|
||||||
progress = cached_progress
|
progress = cached_progress
|
||||||
else:
|
else:
|
||||||
progress = 0
|
progress = 0
|
||||||
|
|||||||
@@ -4595,7 +4595,7 @@ def workout_split_view(request,id=0):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
qdict = {'q':rowname}
|
qdict = {'q':rowname}
|
||||||
url+='?'+urllib.urlencode(qdict)
|
url+='?'+urllib.parse.urlencode(qdict)
|
||||||
|
|
||||||
return HttpResponseRedirect(url)
|
return HttpResponseRedirect(url)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user