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 iso8601 import ParseError
|
||||
|
||||
import numpy
|
||||
|
||||
from rowsandall_app.settings import (
|
||||
C2_CLIENT_ID, C2_REDIRECT_URI, C2_CLIENT_SECRET
|
||||
)
|
||||
@@ -424,7 +426,11 @@ def createc2workoutdata(w):
|
||||
hr = 0*d
|
||||
stroke_data = []
|
||||
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)
|
||||
|
||||
try:
|
||||
@@ -551,7 +557,7 @@ def make_authorization_url(request):
|
||||
params = {"client_id": C2_CLIENT_ID,
|
||||
"response_type": "code",
|
||||
"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
|
||||
|
||||
return HttpResponseRedirect(url)
|
||||
@@ -697,6 +703,10 @@ def process_callback(request):
|
||||
|
||||
return HttpResponse("got a user name: %s" % username)
|
||||
|
||||
def default(o):
|
||||
if isinstance(o, numpy.int64): return int(o)
|
||||
raise TypeError
|
||||
|
||||
# Uploading workout
|
||||
def workout_c2_upload(user,w):
|
||||
message = 'trying C2 upload'
|
||||
@@ -717,6 +727,7 @@ def workout_c2_upload(user,w):
|
||||
raise NoTokenError
|
||||
|
||||
data = createc2workoutdata(w)
|
||||
|
||||
if data == 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'}
|
||||
import urllib
|
||||
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 ):
|
||||
message = "Concept2 Duplicate error"
|
||||
|
||||
@@ -280,7 +280,7 @@ def imports_make_authorization_url(oauth_data):
|
||||
|
||||
|
||||
import urllib
|
||||
url = oauth_data['authorizaton_uri']+urllib.urlencode(params)
|
||||
url = oauth_data['authorizaton_uri']+urllib.parse.urlencode(params)
|
||||
|
||||
return HttpResponseRedirect(url)
|
||||
|
||||
|
||||
@@ -1,13 +1,17 @@
|
||||
#!/srv/venv/bin/python
|
||||
|
||||
""" Process emails """
|
||||
import sys
|
||||
import os
|
||||
PY3K = sys.version_info >= (3, 0)
|
||||
|
||||
import zipfile
|
||||
import re
|
||||
import time
|
||||
from time import strftime
|
||||
|
||||
import io
|
||||
|
||||
from django.core.management.base import BaseCommand
|
||||
from django_mailbox.models import Message, MessageAttachment,Mailbox
|
||||
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
|
||||
try:
|
||||
with open('media/'+filename,'r') as fop:
|
||||
with io.open('media/'+filename,'rb') as fop:
|
||||
line = fop.readline()
|
||||
except (IOError, UnicodeEncodeError):
|
||||
if testing:
|
||||
@@ -164,6 +168,11 @@ def get_from_address(message):
|
||||
except IndexError:
|
||||
first_line = ''
|
||||
|
||||
try:
|
||||
first_line = first_line.decode('utf-8')
|
||||
except AttributeError:
|
||||
pass
|
||||
|
||||
if "quiske" in first_line:
|
||||
match = re.search(r'[\w\.-]+@[\w\.-]+', first_line)
|
||||
return match.group(0)
|
||||
|
||||
@@ -128,7 +128,7 @@ def make_authorization_url(request):
|
||||
|
||||
|
||||
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)
|
||||
|
||||
|
||||
@@ -106,7 +106,7 @@ def make_authorization_url():
|
||||
"redirect_uri": POLAR_REDIRECT_URI,
|
||||
"scope":"write"}
|
||||
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)
|
||||
|
||||
@@ -29,6 +29,8 @@ oauth_data = {
|
||||
}
|
||||
|
||||
|
||||
import numpy
|
||||
|
||||
def splitrunkeeperlatlongdata(lijst,tname,latname,lonname):
|
||||
t = []
|
||||
lat = []
|
||||
@@ -262,6 +264,10 @@ def get_userid(access_token):
|
||||
|
||||
return str(res)
|
||||
|
||||
def default(o):
|
||||
if isinstance(o, numpy.int64): return int(o)
|
||||
raise TypeError
|
||||
|
||||
def workout_runkeeper_upload(user,w):
|
||||
message = "Uploading to Runkeeper"
|
||||
rkid = 0
|
||||
@@ -287,7 +293,7 @@ def workout_runkeeper_upload(user,w):
|
||||
'Content-Length':'nnn'}
|
||||
|
||||
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
|
||||
if (response.status_code == 409 ):
|
||||
|
||||
@@ -6,6 +6,8 @@ from __future__ import unicode_literals
|
||||
from __future__ import unicode_literals, absolute_import
|
||||
# All the functionality to connect to SportTracks
|
||||
|
||||
import numpy
|
||||
|
||||
from rowers.imports import *
|
||||
import re
|
||||
from rowsandall_app.settings import (
|
||||
@@ -235,6 +237,11 @@ def getidfromresponse(response):
|
||||
|
||||
return int(id)
|
||||
|
||||
def default(o):
|
||||
if isinstance(o, numpy.int64): return int(o)
|
||||
raise TypeError
|
||||
|
||||
|
||||
|
||||
def workout_sporttracks_upload(user,w):
|
||||
message = "Uploading to SportTracks"
|
||||
@@ -257,7 +264,7 @@ def workout_sporttracks_upload(user,w):
|
||||
'Content-Type': 'application/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
|
||||
if (response.status_code == 409 ):
|
||||
|
||||
@@ -16,11 +16,12 @@ class TestErrorPages(TestCase):
|
||||
factory = RequestFactory()
|
||||
request = factory.get('/')
|
||||
response = error404_view(request)
|
||||
|
||||
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)
|
||||
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)
|
||||
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 rowers.imports import *
|
||||
|
||||
import numpy
|
||||
|
||||
import rowers.mytypes as mytypes
|
||||
from rowers.mytypes import otwtypes
|
||||
|
||||
@@ -305,6 +307,11 @@ def get_userid(access_token):
|
||||
|
||||
return res
|
||||
|
||||
def default(o):
|
||||
if isinstance(o, numpy.int64): return int(o)
|
||||
raise TypeError
|
||||
|
||||
|
||||
def workout_ua_upload(user,w):
|
||||
message = "Uploading to MapMyFitness"
|
||||
uaid = 0
|
||||
@@ -331,7 +338,7 @@ def workout_ua_upload(user,w):
|
||||
}
|
||||
|
||||
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
|
||||
if (response.status_code == 409 ):
|
||||
|
||||
@@ -44,6 +44,11 @@ from rowers.utils import (
|
||||
)
|
||||
|
||||
def cleanbody(body):
|
||||
try:
|
||||
body = body.decode('utf-8')
|
||||
except AttributeError:
|
||||
pass
|
||||
|
||||
regex = r".*---\n([\s\S]*?)\.\.\..*"
|
||||
matches = re.finditer(regex,body)
|
||||
|
||||
|
||||
@@ -5,6 +5,12 @@ from __future__ import unicode_literals
|
||||
|
||||
from rowers.views.statements import *
|
||||
|
||||
import numpy
|
||||
|
||||
def default(o):
|
||||
if isinstance(o, numpy.int64): return int(o)
|
||||
raise TypeError
|
||||
|
||||
|
||||
# Send workout to TP
|
||||
@login_required()
|
||||
@@ -228,7 +234,7 @@ def workout_runkeeper_upload_view(request,id=0):
|
||||
'Content-Length':'nnn'}
|
||||
|
||||
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
|
||||
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/"
|
||||
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
|
||||
@@ -356,7 +362,7 @@ def workout_sporttracks_upload_view(request,id=0):
|
||||
'Content-Type': 'application/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
|
||||
|
||||
@@ -28,6 +28,9 @@ import isodate
|
||||
import re
|
||||
import cgi
|
||||
from icalendar import Calendar, Event
|
||||
|
||||
from functools import reduce
|
||||
|
||||
import rowers.braintreestuff as braintreestuff
|
||||
import rowers.payments as payments
|
||||
from rowers.opaque import encoder
|
||||
@@ -502,7 +505,7 @@ def remove_asynctask(request,id):
|
||||
def get_job_result(jobid):
|
||||
if settings.TESTING:
|
||||
return None
|
||||
elif settings.DEBUG:
|
||||
elif settings.CELERY:
|
||||
result = celery_result.AsyncResult(jobid).result
|
||||
else:
|
||||
running_job_ids = rq_registry.get_job_ids()
|
||||
@@ -541,7 +544,7 @@ def get_job_status(jobid):
|
||||
'started_at':None,
|
||||
}
|
||||
return summary
|
||||
elif settings.DEBUG:
|
||||
elif settings.CELERY:
|
||||
job = celery_result.AsyncResult(jobid)
|
||||
jobresult = job.result
|
||||
|
||||
@@ -592,7 +595,7 @@ def get_job_status(jobid):
|
||||
return summary
|
||||
|
||||
def kill_async_job(request,id='aap'):
|
||||
if settings.DEBUG:
|
||||
if settings.CELERY:
|
||||
job = celery_result.AsyncResult(id)
|
||||
job.revoke()
|
||||
else:
|
||||
@@ -734,7 +737,7 @@ def get_stored_tasks_status(request):
|
||||
if finished:
|
||||
cache.set(id,100)
|
||||
progress = 100
|
||||
elif cached_progress>0:
|
||||
elif cached_progress is not None and cached_progress>0:
|
||||
progress = cached_progress
|
||||
else:
|
||||
progress = 0
|
||||
|
||||
@@ -4595,7 +4595,7 @@ def workout_split_view(request,id=0):
|
||||
pass
|
||||
|
||||
qdict = {'q':rowname}
|
||||
url+='?'+urllib.urlencode(qdict)
|
||||
url+='?'+urllib.parse.urlencode(qdict)
|
||||
|
||||
return HttpResponseRedirect(url)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user