some changes
This commit is contained in:
@@ -42,7 +42,7 @@ from pyarrow.lib import ArrowInvalid
|
|||||||
|
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
from django.utils.timezone import get_current_timezone
|
from django.utils.timezone import get_current_timezone
|
||||||
from django_mailbox.models import Message,Mailbox,MessageAttachment
|
#from django_mailbox.models import Message,Mailbox,MessageAttachment
|
||||||
from django.core.exceptions import ValidationError
|
from django.core.exceptions import ValidationError
|
||||||
|
|
||||||
from time import strftime
|
from time import strftime
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ from rowers.tasks import (
|
|||||||
handle_sendemail_unrecognized,
|
handle_sendemail_unrecognized,
|
||||||
handle_sendemail_unrecognizedowner
|
handle_sendemail_unrecognizedowner
|
||||||
)
|
)
|
||||||
from django_mailbox.models import Message, MessageAttachment,Mailbox
|
#from django_mailbox.models import Message, MessageAttachment,Mailbox
|
||||||
|
|
||||||
#workoutmailbox = Mailbox.objects.get(name='workouts')
|
#workoutmailbox = Mailbox.objects.get(name='workouts')
|
||||||
#failedmailbox = Mailbox.objects.get(name='Failed')
|
#failedmailbox = Mailbox.objects.get(name='Failed')
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ import json
|
|||||||
import io
|
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.urls import reverse
|
from django.urls import reverse
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
|
||||||
@@ -182,16 +182,6 @@ class Command(BaseCommand):
|
|||||||
else: # pragma: no cover
|
else: # pragma: no cover
|
||||||
testing = False
|
testing = False
|
||||||
|
|
||||||
if 'mailbox' in options:
|
|
||||||
workoutmailbox = Mailbox.objects.get(name=options['mailbox'])
|
|
||||||
else: # pragma: no cover
|
|
||||||
workoutmailbox = Mailbox.objects.get(name='workouts')
|
|
||||||
|
|
||||||
if 'failedmailbox' in options: # pragma: no cover
|
|
||||||
failedmailbox = Mailbox.objects.get(name=options['failedmailbox'])
|
|
||||||
else: # pragma: no cover
|
|
||||||
failedmailbox = Mailbox.objects.get(name='Failed')
|
|
||||||
|
|
||||||
# Polar
|
# Polar
|
||||||
try:
|
try:
|
||||||
polar_available = polarstuff.get_polar_notifications()
|
polar_available = polarstuff.get_polar_notifications()
|
||||||
@@ -235,100 +225,6 @@ class Command(BaseCommand):
|
|||||||
lines = traceback.format_exception(exc_type, exc_value, exc_traceback)
|
lines = traceback.format_exception(exc_type, exc_value, exc_traceback)
|
||||||
dologging('processemail.log',''.join('!! ' + line for line in lines))
|
dologging('processemail.log',''.join('!! ' + line for line in lines))
|
||||||
|
|
||||||
|
|
||||||
messages = Message.objects.filter(mailbox_id = workoutmailbox.id)
|
|
||||||
message_ids = [m.id for m in messages]
|
|
||||||
attachments = MessageAttachment.objects.filter(
|
|
||||||
message_id__in=message_ids
|
|
||||||
)
|
|
||||||
cntr = 0
|
|
||||||
for attachment in attachments:
|
|
||||||
filename, extension = os.path.splitext(attachment.document.name)
|
|
||||||
extension = extension.lower()
|
|
||||||
# extension = attachment.document.name[-3:].lower()
|
|
||||||
try:
|
|
||||||
message = Message.objects.get(id=attachment.message_id)
|
|
||||||
if message.encoded: # pragma: no cover
|
|
||||||
# if message.text:
|
|
||||||
body = "\n".join(message.text.splitlines())
|
|
||||||
else:
|
|
||||||
body = message.get_body()
|
|
||||||
|
|
||||||
uploadoptions = uploads.upload_options(body)
|
|
||||||
|
|
||||||
from_address = get_from_address(message)
|
|
||||||
|
|
||||||
name = message.subject
|
|
||||||
# get a list of users
|
|
||||||
# theusers = User.objects.filter(email=from_address)
|
|
||||||
rowers = [
|
|
||||||
r for r in Rower.objects.all() if r.user.email.lower() == from_address
|
|
||||||
]
|
|
||||||
try: # pragma: no cover
|
|
||||||
rowers2 = [
|
|
||||||
r for r in Rower.objects.all() if from_address in r.emailalternatives
|
|
||||||
]
|
|
||||||
rowers = rowers+rowers2
|
|
||||||
except TypeError:
|
|
||||||
pass
|
|
||||||
except IOError: # pragma: no cover
|
|
||||||
rowers = []
|
|
||||||
except Message.DoesNotExist: # pragma: no cover
|
|
||||||
try:
|
|
||||||
attachment.delete()
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
for rower in rowers:
|
|
||||||
if 'zip' in extension:
|
|
||||||
try:
|
|
||||||
zip_file = zipfile.ZipFile(attachment.document)
|
|
||||||
for id,filename in enumerate(zip_file.namelist()):
|
|
||||||
datafile = zip_file.extract(
|
|
||||||
filename, path='media/')
|
|
||||||
if id>0:
|
|
||||||
title = name+' ('+str(id+1)+')'
|
|
||||||
else:
|
|
||||||
title = name
|
|
||||||
workoutid = processattachment(
|
|
||||||
rower, datafile, title, uploadoptions,
|
|
||||||
testing=testing
|
|
||||||
)
|
|
||||||
except BadZipFile: # pragma: no cover
|
|
||||||
pass
|
|
||||||
|
|
||||||
else:
|
|
||||||
# move attachment and make workout
|
|
||||||
|
|
||||||
workoutid = processattachment(
|
|
||||||
rower, attachment.document, name, uploadoptions,
|
|
||||||
testing=testing
|
|
||||||
)
|
|
||||||
|
|
||||||
# We're done with the attachment. It can be deleted
|
|
||||||
try:
|
|
||||||
attachment.delete()
|
|
||||||
except IOError: # pragma: no cover
|
|
||||||
pass
|
|
||||||
except WindowsError: # pragma: no cover
|
|
||||||
if not testing:
|
|
||||||
time.sleep(2)
|
|
||||||
try:
|
|
||||||
attachment.delete()
|
|
||||||
except WindowsError:
|
|
||||||
pass
|
|
||||||
except: # pragma: no cover
|
|
||||||
message.mailbox = failedmailbox
|
|
||||||
message.save()
|
|
||||||
|
|
||||||
if message.attachments.exists() is False:
|
|
||||||
# no attachments, so can be deleted
|
|
||||||
message.delete()
|
|
||||||
|
|
||||||
messages = Message.objects.all()
|
|
||||||
for message in messages:
|
|
||||||
if message.attachments.exists() is False:
|
|
||||||
message.delete()
|
|
||||||
|
|
||||||
# Strava
|
# Strava
|
||||||
#rowers = Rower.objects.filter(strava_auto_import=True)
|
#rowers = Rower.objects.filter(strava_auto_import=True)
|
||||||
#for r in rowers:
|
#for r in rowers:
|
||||||
|
|||||||
@@ -47,8 +47,6 @@ from io import StringIO
|
|||||||
import stravalib
|
import stravalib
|
||||||
from stravalib.exc import ActivityUploadFailed,TimeoutExceeded
|
from stravalib.exc import ActivityUploadFailed,TimeoutExceeded
|
||||||
|
|
||||||
from django_mailbox.models import Message,Mailbox,MessageAttachment
|
|
||||||
|
|
||||||
from rowsandall_app.settings import (
|
from rowsandall_app.settings import (
|
||||||
POLAR_CLIENT_ID, POLAR_REDIRECT_URI, POLAR_CLIENT_SECRET,
|
POLAR_CLIENT_ID, POLAR_REDIRECT_URI, POLAR_CLIENT_SECRET,
|
||||||
)
|
)
|
||||||
@@ -231,17 +229,21 @@ def get_polar_workouts(user):
|
|||||||
with open(filename,'wb') as fop:
|
with open(filename,'wb') as fop:
|
||||||
fop.write(response.content)
|
fop.write(response.content)
|
||||||
|
|
||||||
msg = Message(mailbox=workoutsbox,
|
# post file to upload api
|
||||||
from_header=user.email,
|
json_data = {
|
||||||
subject = '',
|
'title':'',
|
||||||
body=bodyyaml)
|
'workouttype':'',
|
||||||
|
'user':user.id,
|
||||||
|
'secret':settings.UPLOAD_SERVICE_SECRET,
|
||||||
|
'file':filename,
|
||||||
|
}
|
||||||
|
url = reverse('workout_upload_api')
|
||||||
|
response = requests.post(url,json_data)
|
||||||
|
|
||||||
msg.save()
|
if response.status_code == 200:
|
||||||
|
exercise_dict['filename'] = filename
|
||||||
a = MessageAttachment(message=msg,document=filename[6:])
|
else:
|
||||||
a.save()
|
print(response.status_code)
|
||||||
|
|
||||||
exercise_dict['filename'] = filename
|
|
||||||
else:
|
else:
|
||||||
exercise_dict['filename'] = ''
|
exercise_dict['filename'] = ''
|
||||||
|
|
||||||
|
|||||||
@@ -11,8 +11,6 @@ import time
|
|||||||
from time import strftime
|
from time import strftime
|
||||||
|
|
||||||
|
|
||||||
from django_mailbox.models import Message,Mailbox,MessageAttachment
|
|
||||||
|
|
||||||
import django_rq
|
import django_rq
|
||||||
queue = django_rq.get_queue('default')
|
queue = django_rq.get_queue('default')
|
||||||
queuelow = django_rq.get_queue('low')
|
queuelow = django_rq.get_queue('low')
|
||||||
@@ -212,157 +210,6 @@ def get_strava_workout_list(user,limit_n=0):
|
|||||||
return s
|
return s
|
||||||
|
|
||||||
|
|
||||||
# gets all new Strava workouts for a rower
|
|
||||||
def get_strava_workouts(rower): # pragma: no cover
|
|
||||||
try:
|
|
||||||
thetoken = strava_open(rower.user)
|
|
||||||
except NoTokenError:
|
|
||||||
return 0
|
|
||||||
|
|
||||||
res = get_strava_workout_list(rower.user,limit_n=10)
|
|
||||||
|
|
||||||
if (res.status_code != 200):
|
|
||||||
return 0
|
|
||||||
else:
|
|
||||||
stravaids = [int(item['id']) for item in res.json()]
|
|
||||||
stravadata = [{
|
|
||||||
'id':int(item['id']),
|
|
||||||
'elapsed_time':item['elapsed_time'],
|
|
||||||
'start_date':item['start_date'],
|
|
||||||
} for item in res.json()]
|
|
||||||
|
|
||||||
alldata = {}
|
|
||||||
for item in res.json():
|
|
||||||
alldata[item['id']] = item
|
|
||||||
|
|
||||||
|
|
||||||
wfailed = Workout.objects.filter(user=rower,uploadedtostrava=-1)
|
|
||||||
|
|
||||||
for w in wfailed:
|
|
||||||
for item in stravadata:
|
|
||||||
elapsed_time = item['elapsed_time']
|
|
||||||
start_date = item['start_date']
|
|
||||||
stravaid = item['id']
|
|
||||||
|
|
||||||
if arrow.get(start_date) == arrow.get(w.startdatetime):
|
|
||||||
dd = datetime.min + timedelta(
|
|
||||||
seconds=int(elapsed_time)
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
delta = datetime.combine(datetime.min,datetime.time(dd))-datetime.combine(datetime.min,w.duration)
|
|
||||||
|
|
||||||
if delta < timedelta(minutes=2):
|
|
||||||
w.uploadedtostrava = int(stravaid)
|
|
||||||
w.save()
|
|
||||||
|
|
||||||
knownstravaids = [
|
|
||||||
w.uploadedtostrava for w in Workout.objects.filter(user=rower)
|
|
||||||
]
|
|
||||||
|
|
||||||
tombstones = [
|
|
||||||
t.uploadedtostrava for t in TombStone.objects.filter(user=rower)
|
|
||||||
]
|
|
||||||
|
|
||||||
knownstravaids = uniqify(knownstravaids+tombstones)
|
|
||||||
|
|
||||||
newids = [stravaid for stravaid in stravaids if not stravaid in knownstravaids]
|
|
||||||
|
|
||||||
for stravaid in newids:
|
|
||||||
result = create_async_workout(alldata,rower.user,stravaid)
|
|
||||||
|
|
||||||
return 1
|
|
||||||
|
|
||||||
def create_async_workout(alldata,user,stravaid,debug=False):
|
|
||||||
data = alldata[stravaid]
|
|
||||||
r = Rower.objects.get(user=user)
|
|
||||||
distance = data['distance']
|
|
||||||
stravaid = data['id']
|
|
||||||
try:
|
|
||||||
workouttype = mytypes.stravamappinginv[data['type']]
|
|
||||||
except: # pragma: no cover
|
|
||||||
workouttype = 'other'
|
|
||||||
|
|
||||||
if workouttype not in [x[0] for x in Workout.workouttypes]: # pragma: no cover
|
|
||||||
workouttype = 'other'
|
|
||||||
|
|
||||||
if workouttype.lower() == 'rowing': # pragma: no cover
|
|
||||||
workouttype = 'rower'
|
|
||||||
if 'summary_polyline' in data['map']:
|
|
||||||
workouttype = 'water'
|
|
||||||
|
|
||||||
|
|
||||||
try:
|
|
||||||
comments = data['comments']
|
|
||||||
except:
|
|
||||||
comments = ' '
|
|
||||||
|
|
||||||
try:
|
|
||||||
thetimezone = tz(data['timezone'])
|
|
||||||
except:
|
|
||||||
thetimezone = 'UTC'
|
|
||||||
|
|
||||||
try:
|
|
||||||
rowdatetime = iso8601.parse_date(data['date_utc'])
|
|
||||||
except KeyError:
|
|
||||||
rowdatetime = iso8601.parse_date(data['start_date'])
|
|
||||||
except ParseError: # pragma: no cover
|
|
||||||
rowdatetime = iso8601.parse_date(data['date'])
|
|
||||||
|
|
||||||
try:
|
|
||||||
c2intervaltype = data['workout_type']
|
|
||||||
|
|
||||||
except KeyError: # pragma: no cover
|
|
||||||
c2intervaltype = ''
|
|
||||||
|
|
||||||
try:
|
|
||||||
title = data['name']
|
|
||||||
except KeyError: # pragma: no cover
|
|
||||||
title = ""
|
|
||||||
try:
|
|
||||||
t = data['comments'].split('\n', 1)[0]
|
|
||||||
title += t[:20]
|
|
||||||
except:
|
|
||||||
title = ''
|
|
||||||
|
|
||||||
workoutdate = rowdatetime.astimezone(
|
|
||||||
pytz.timezone(thetimezone)
|
|
||||||
).strftime('%Y-%m-%d')
|
|
||||||
|
|
||||||
starttime = rowdatetime.astimezone(
|
|
||||||
pytz.timezone(thetimezone)
|
|
||||||
).strftime('%H:%M:%S')
|
|
||||||
|
|
||||||
totaltime = data['elapsed_time']
|
|
||||||
duration = dataprep.totaltime_sec_to_string(totaltime)
|
|
||||||
|
|
||||||
weightcategory = 'hwt'
|
|
||||||
|
|
||||||
# Create CSV file name and save data to CSV file
|
|
||||||
csvfilename ='media/mailbox_attachments/{code}_{importid}.csv'.format(
|
|
||||||
importid=stravaid,
|
|
||||||
code = uuid4().hex[:16]
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Check if workout has stroke data, and get the stroke data
|
|
||||||
|
|
||||||
starttimeunix = arrow.get(rowdatetime).timestamp()
|
|
||||||
|
|
||||||
result = handle_strava_import_stroke_data(
|
|
||||||
title,
|
|
||||||
user.email,
|
|
||||||
r.stravatoken,
|
|
||||||
stravaid,
|
|
||||||
starttimeunix,
|
|
||||||
csvfilename,
|
|
||||||
workouttype = workouttype,
|
|
||||||
boattype = '1x'
|
|
||||||
)
|
|
||||||
|
|
||||||
return 1
|
|
||||||
|
|
||||||
from rowers.utils import get_strava_stream
|
from rowers.utils import get_strava_stream
|
||||||
|
|
||||||
def async_get_workout(user,stravaid):
|
def async_get_workout(user,stravaid):
|
||||||
@@ -559,174 +406,3 @@ def workout_strava_upload(user,w, quick=False,asynchron=True):
|
|||||||
os.remove(tcxfile)
|
os.remove(tcxfile)
|
||||||
return message,stravaid
|
return message,stravaid
|
||||||
return message,stravaid # pragma: no cover
|
return message,stravaid # pragma: no cover
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def handle_strava_import_stroke_data(title,
|
|
||||||
useremail,
|
|
||||||
stravatoken,
|
|
||||||
stravaid,
|
|
||||||
starttimeunix,
|
|
||||||
csvfilename,debug=True,
|
|
||||||
workouttype = 'rower',
|
|
||||||
boattype = '1x',
|
|
||||||
**kwargs):
|
|
||||||
# ready to fetch. Hurray
|
|
||||||
|
|
||||||
fetchresolution = 'high'
|
|
||||||
series_type = 'time'
|
|
||||||
authorizationstring = str('Bearer ' + stravatoken)
|
|
||||||
headers = {'Authorization': authorizationstring,
|
|
||||||
'user-agent': 'sanderroosendaal',
|
|
||||||
'Content-Type': 'application/json',
|
|
||||||
'resolution': 'medium',}
|
|
||||||
url = "https://www.strava.com/api/v3/activities/"+str(stravaid)
|
|
||||||
workoutsummary = requests.get(url,headers=headers).json()
|
|
||||||
|
|
||||||
workoutsummary['timezone'] = "Etc/UTC"
|
|
||||||
startdatetime = workoutsummary['start_date']
|
|
||||||
|
|
||||||
r = type('Rower', (object,), {"stravatoken": stravatoken})
|
|
||||||
|
|
||||||
spm = get_strava_stream(r,'cadence',stravaid)
|
|
||||||
t = get_strava_stream(r,'time',stravaid)
|
|
||||||
|
|
||||||
try:
|
|
||||||
hr = get_strava_stream(r,'heartrate',stravaid)
|
|
||||||
except JSONDecodeError: # pragma: no cover
|
|
||||||
hr = 0*spm
|
|
||||||
|
|
||||||
try:
|
|
||||||
velo = get_strava_stream(r,'velocity_smooth',stravaid)
|
|
||||||
except JSONDecodeError: # pragma: no cover
|
|
||||||
velo = 0*t
|
|
||||||
|
|
||||||
try:
|
|
||||||
d = get_strava_stream(r,'distance',stravaid)
|
|
||||||
except JSONDecodeError: # pragma: no cover
|
|
||||||
d = 0*t
|
|
||||||
|
|
||||||
try:
|
|
||||||
coords = get_strava_stream(r,'latlng',stravaid)
|
|
||||||
except JSONDecodeError: # pragma: no cover
|
|
||||||
coords = 0*t
|
|
||||||
try:
|
|
||||||
power = get_strava_stream(r,'watts',stravaid)
|
|
||||||
except JSONDecodeError: # pragma: no cover
|
|
||||||
power = 0*t
|
|
||||||
|
|
||||||
if t is not None:
|
|
||||||
nr_rows = len(t)
|
|
||||||
else: # pragma: no cover
|
|
||||||
return 0
|
|
||||||
|
|
||||||
if nr_rows == 0: # pragma: no cover
|
|
||||||
return 0
|
|
||||||
|
|
||||||
if d is None: # pragma: no cover
|
|
||||||
d = 0*t
|
|
||||||
|
|
||||||
if spm is None: # pragma: no cover
|
|
||||||
spm = np.zeros(nr_rows)
|
|
||||||
|
|
||||||
if power is None: # pragma: no cover
|
|
||||||
power = np.zeros(nr_rows)
|
|
||||||
|
|
||||||
if hr is None: # pragma: no cover
|
|
||||||
hr = np.zeros(nr_rows)
|
|
||||||
|
|
||||||
if velo is None: # pragma: no cover
|
|
||||||
velo = np.zeros(nr_rows)
|
|
||||||
|
|
||||||
|
|
||||||
f = np.diff(t).mean()
|
|
||||||
if f != 0:
|
|
||||||
windowsize = 2*(int(10./(f)))+1
|
|
||||||
else: # pragma: no cover
|
|
||||||
windowsize = 1
|
|
||||||
|
|
||||||
if windowsize > 3 and windowsize < len(velo):
|
|
||||||
velo2 = savgol_filter(velo,windowsize,3)
|
|
||||||
else: # pragma: no cover
|
|
||||||
velo2 = velo
|
|
||||||
|
|
||||||
if coords is not None:
|
|
||||||
try:
|
|
||||||
lat = coords[:,0]
|
|
||||||
lon = coords[:,1]
|
|
||||||
if lat.std() == 0 and lon.std() == 0 and workouttype == 'water': # pragma: no cover
|
|
||||||
workouttype = 'rower'
|
|
||||||
except IndexError: # pragma: no cover
|
|
||||||
lat = np.zeros(len(t))
|
|
||||||
lon = np.zeros(len(t))
|
|
||||||
if workouttype == 'water':
|
|
||||||
workouttype = 'rower'
|
|
||||||
else: # pragma: no cover
|
|
||||||
lat = np.zeros(len(t))
|
|
||||||
lon = np.zeros(len(t))
|
|
||||||
if workouttype == 'water':
|
|
||||||
workouttype = 'rower'
|
|
||||||
|
|
||||||
strokelength = velo*60./(spm)
|
|
||||||
strokelength[np.isinf(strokelength)] = 0.0
|
|
||||||
|
|
||||||
pace = 500./(1.0*velo2)
|
|
||||||
pace[np.isinf(pace)] = 0.0
|
|
||||||
|
|
||||||
unixtime = starttimeunix+t
|
|
||||||
|
|
||||||
strokedistance = 60.*velo2/spm
|
|
||||||
|
|
||||||
if workouttype == 'rower' and pd.Series(power).mean() == 0: # pragma: no cover
|
|
||||||
power = 2.8*(velo2**3)
|
|
||||||
|
|
||||||
nr_strokes = len(t)
|
|
||||||
|
|
||||||
df = pd.DataFrame({'TimeStamp (sec)':unixtime,
|
|
||||||
' ElapsedTime (sec)':t,
|
|
||||||
' Horizontal (meters)':d,
|
|
||||||
' Stroke500mPace (sec/500m)':pace,
|
|
||||||
' Cadence (stokes/min)':spm,
|
|
||||||
' HRCur (bpm)':hr,
|
|
||||||
' latitude':lat,
|
|
||||||
' longitude':lon,
|
|
||||||
' StrokeDistance (meters)':strokelength,
|
|
||||||
'cum_dist':d,
|
|
||||||
' DragFactor':np.zeros(nr_strokes),
|
|
||||||
' DriveLength (meters)':np.zeros(nr_strokes),
|
|
||||||
' StrokeDistance (meters)':strokedistance,
|
|
||||||
' DriveTime (ms)':np.zeros(nr_strokes),
|
|
||||||
' StrokeRecoveryTime (ms)':np.zeros(nr_strokes),
|
|
||||||
' AverageDriveForce (lbs)':np.zeros(nr_strokes),
|
|
||||||
' PeakDriveForce (lbs)':np.zeros(nr_strokes),
|
|
||||||
' lapIdx':np.zeros(nr_strokes),
|
|
||||||
' Power (watts)':power,
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
df.sort_values(by='TimeStamp (sec)',ascending=True)
|
|
||||||
|
|
||||||
res = df.to_csv(csvfilename,index_label='index')
|
|
||||||
|
|
||||||
workoutsbox = Mailbox.objects.filter(name='workouts')[0]
|
|
||||||
|
|
||||||
body = """stravaid {stravaid}
|
|
||||||
workouttype {workouttype}
|
|
||||||
boattype {boattype}""".format(
|
|
||||||
stravaid=stravaid,
|
|
||||||
workouttype=workouttype,
|
|
||||||
boattype=boattype
|
|
||||||
)
|
|
||||||
|
|
||||||
msg = Message(mailbox=workoutsbox,
|
|
||||||
from_header=useremail,
|
|
||||||
subject=title,
|
|
||||||
body=body)
|
|
||||||
msg.save()
|
|
||||||
|
|
||||||
a = MessageAttachment(message=msg,document=csvfilename[6:])
|
|
||||||
a.save()
|
|
||||||
|
|
||||||
return res
|
|
||||||
|
|||||||
@@ -8,15 +8,6 @@
|
|||||||
<h1>Available on Strava</h1>
|
<h1>Available on Strava</h1>
|
||||||
{% if workouts %}
|
{% if workouts %}
|
||||||
<ul class="main-content">
|
<ul class="main-content">
|
||||||
<li>
|
|
||||||
<a href="/rowers/workout/stravaimport/all/" class="blue button">Import all NEW</a>
|
|
||||||
</li>
|
|
||||||
<li class="grid_3">
|
|
||||||
<p>This imports all workouts that have not been imported to rowsandall.com.
|
|
||||||
The action may take a longer time to process, so please be patient. Click on Import in the list below to import an individual workout.
|
|
||||||
</p>
|
|
||||||
</li>
|
|
||||||
|
|
||||||
<li class="grid_4">
|
<li class="grid_4">
|
||||||
<form enctype="multipart/form-data" method="post">
|
<form enctype="multipart/form-data" method="post">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
|
|||||||
@@ -57,7 +57,6 @@ from rowers.dataprep import delete_strokedata
|
|||||||
from redis import StrictRedis
|
from redis import StrictRedis
|
||||||
redis_connection = StrictRedis()
|
redis_connection = StrictRedis()
|
||||||
|
|
||||||
from django_mailbox.models import Mailbox,MessageAttachment,Message
|
|
||||||
|
|
||||||
def mocked_grpc(*args, **kwargs):
|
def mocked_grpc(*args, **kwargs):
|
||||||
class insecure_channel:
|
class insecure_channel:
|
||||||
|
|||||||
@@ -85,7 +85,6 @@ from importlib import import_module
|
|||||||
from redis import StrictRedis
|
from redis import StrictRedis
|
||||||
redis_connection = StrictRedis()
|
redis_connection = StrictRedis()
|
||||||
|
|
||||||
from django_mailbox.models import Mailbox,MessageAttachment,Message
|
|
||||||
|
|
||||||
from rowers.tests.mocks import *
|
from rowers.tests.mocks import *
|
||||||
|
|
||||||
|
|||||||
@@ -29,18 +29,7 @@ class EmailUpload(TestCase):
|
|||||||
rowerplan='coach')
|
rowerplan='coach')
|
||||||
|
|
||||||
nu = datetime.datetime.now()
|
nu = datetime.datetime.now()
|
||||||
workoutsbox = Mailbox.objects.create(name='workouts1')
|
|
||||||
workoutsbox.save()
|
|
||||||
failbox = Mailbox.objects.create(name='Failed')
|
|
||||||
failbox.save()
|
|
||||||
|
|
||||||
m = Message(mailbox=workoutsbox,
|
|
||||||
from_header = u.email,
|
|
||||||
subject = "run",
|
|
||||||
body = """
|
|
||||||
workout run
|
|
||||||
""")
|
|
||||||
m.save()
|
|
||||||
a2 = 'media/mailbox_attachments/colin3.csv'
|
a2 = 'media/mailbox_attachments/colin3.csv'
|
||||||
copy('rowers/tests/testdata/emails/colin.csv',a2)
|
copy('rowers/tests/testdata/emails/colin.csv',a2)
|
||||||
a3 = 'media/mailbox_attachments/colin4.csv'
|
a3 = 'media/mailbox_attachments/colin4.csv'
|
||||||
@@ -52,8 +41,6 @@ workout run
|
|||||||
a6 = 'media/mailbox_attachments/colin7.csv'
|
a6 = 'media/mailbox_attachments/colin7.csv'
|
||||||
copy('rowers/tests/testdata/emails/colin.csv',a6)
|
copy('rowers/tests/testdata/emails/colin.csv',a6)
|
||||||
|
|
||||||
a = MessageAttachment(message=m,document=a2[6:])
|
|
||||||
a.save()
|
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
for filename in os.listdir('media/mailbox_attachments'):
|
for filename in os.listdir('media/mailbox_attachments'):
|
||||||
@@ -64,6 +51,7 @@ workout run
|
|||||||
except (IOError,FileNotFoundError,OSError):
|
except (IOError,FileNotFoundError,OSError):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
@patch('rowers.dataprep.create_engine')
|
@patch('rowers.dataprep.create_engine')
|
||||||
@patch('rowers.dataprep.getsmallrowdata_db',side_effect=mocked_getsmallrowdata_db)
|
@patch('rowers.dataprep.getsmallrowdata_db',side_effect=mocked_getsmallrowdata_db)
|
||||||
def test_uploadapi(self,mocked_sqlalchemy,mocked_getsmallrowdata_db):
|
def test_uploadapi(self,mocked_sqlalchemy,mocked_getsmallrowdata_db):
|
||||||
@@ -168,266 +156,7 @@ workout run
|
|||||||
self.assertEqual(response.status_code,403)
|
self.assertEqual(response.status_code,403)
|
||||||
|
|
||||||
|
|
||||||
@patch('rowers.dataprep.create_engine')
|
|
||||||
@patch('rowers.polarstuff.get_polar_notifications')
|
|
||||||
@patch('rowers.c2stuff.requests.get', side_effect=mocked_requests)
|
|
||||||
@patch('rowers.c2stuff.requests.post', side_effect=mocked_requests)
|
|
||||||
def test_emailupload(
|
|
||||||
self, mocked_sqlalchemy,mocked_polar_notifications, mock_get, mock_post):
|
|
||||||
out = StringIO()
|
|
||||||
call_command('processemail', stdout=out,testing=True,mailbox='workouts1')
|
|
||||||
self.assertIn('Successfully processed email attachments',out.getvalue())
|
|
||||||
|
|
||||||
ws = Workout.objects.filter(name="run")
|
|
||||||
|
|
||||||
self.assertEqual(len(ws),1)
|
|
||||||
w = ws[0]
|
|
||||||
self.assertEqual(w.workouttype,'Run')
|
|
||||||
|
|
||||||
@override_settings(TESTING=True)
|
|
||||||
class ZipEmailUpload(TestCase):
|
|
||||||
def setUp(self):
|
|
||||||
redis_connection.publish('tasks','KILL')
|
|
||||||
u = User.objects.create_user('john',
|
|
||||||
'sander@ds.ds',
|
|
||||||
'koeinsloot')
|
|
||||||
r = Rower.objects.create(user=u,gdproptin=True,surveydone=True,
|
|
||||||
gdproptindate=timezone.now()
|
|
||||||
)
|
|
||||||
|
|
||||||
self.theadmin = UserFactory(is_staff=True)
|
|
||||||
self.rtheadmin = Rower.objects.create(user=self.theadmin,
|
|
||||||
birthdate = faker.profile()['birthdate'],
|
|
||||||
gdproptin=True,surveydone=True,
|
|
||||||
gdproptindate=timezone.now(),
|
|
||||||
rowerplan='coach')
|
|
||||||
|
|
||||||
nu = datetime.datetime.now()
|
|
||||||
workoutsbox = Mailbox.objects.create(name='workouts1')
|
|
||||||
workoutsbox.save()
|
|
||||||
failbox = Mailbox.objects.create(name='Failed')
|
|
||||||
failbox.save()
|
|
||||||
|
|
||||||
m = Message(mailbox=workoutsbox,
|
|
||||||
from_header = u.email,
|
|
||||||
subject = "Sprint",
|
|
||||||
body = """
|
|
||||||
workout water
|
|
||||||
""")
|
|
||||||
m.save()
|
|
||||||
a2 = 'media/mailbox_attachments/zipfile.zip'
|
|
||||||
copy('rowers/tests/testdata/zipfile.zip',a2)
|
|
||||||
a = MessageAttachment(message=m,document=a2[6:])
|
|
||||||
a.save()
|
|
||||||
|
|
||||||
def tearDown(self):
|
|
||||||
for filename in os.listdir('media/mailbox_attachments'):
|
|
||||||
path = os.path.join('media/mailbox_attachments/',filename)
|
|
||||||
if not os.path.isdir(path):
|
|
||||||
try:
|
|
||||||
os.remove(path)
|
|
||||||
except (IOError,FileNotFoundError,OSError):
|
|
||||||
pass
|
|
||||||
|
|
||||||
@patch('rowers.dataprep.create_engine')
|
|
||||||
@patch('rowers.polarstuff.get_polar_notifications')
|
|
||||||
@patch('rowers.c2stuff.requests.get', side_effect=mocked_requests)
|
|
||||||
@patch('rowers.c2stuff.requests.post', side_effect=mocked_requests)
|
|
||||||
def test_emailupload(
|
|
||||||
self, mocked_sqlalchemy,mocked_polar_notifications, mock_get, mock_post):
|
|
||||||
out = StringIO()
|
|
||||||
call_command('processemail', stdout=out,testing=True,mailbox='workouts1')
|
|
||||||
self.assertIn('Successfully processed email attachments',out.getvalue())
|
|
||||||
|
|
||||||
ws = Workout.objects.all()
|
|
||||||
|
|
||||||
self.assertEqual(len(ws),5)
|
|
||||||
w = ws[4]
|
|
||||||
self.assertEqual(w.name,'Sprint (5)')
|
|
||||||
|
|
||||||
|
|
||||||
@override_settings(TESTING=True)
|
|
||||||
class EmailUniCodeUpload(TestCase):
|
|
||||||
def setUp(self):
|
|
||||||
redis_connection.publish('tasks','KILL')
|
|
||||||
u = User.objects.create_user('john',
|
|
||||||
'sander@ds.ds',
|
|
||||||
'koeinsloot')
|
|
||||||
r = Rower.objects.create(user=u,gdproptin=True,surveydone=True,
|
|
||||||
gdproptindate=timezone.now()
|
|
||||||
)
|
|
||||||
|
|
||||||
self.theadmin = UserFactory(is_staff=True)
|
|
||||||
self.rtheadmin = Rower.objects.create(user=self.theadmin,
|
|
||||||
birthdate = faker.profile()['birthdate'],
|
|
||||||
gdproptin=True,surveydone=True,
|
|
||||||
gdproptindate=timezone.now(),
|
|
||||||
rowerplan='coach')
|
|
||||||
|
|
||||||
nu = datetime.datetime.now()
|
|
||||||
workoutsbox = Mailbox.objects.create(name='workouts2')
|
|
||||||
workoutsbox.save()
|
|
||||||
failbox = Mailbox.objects.create(name='Failed')
|
|
||||||
failbox.save()
|
|
||||||
|
|
||||||
m = Message(mailbox=workoutsbox,
|
|
||||||
from_header = u.email,
|
|
||||||
subject = "Třeboň",
|
|
||||||
body = """
|
|
||||||
workout water
|
|
||||||
""")
|
|
||||||
m.save()
|
|
||||||
a2 = 'media/mailbox_attachments/colin4a.csv'
|
|
||||||
copy('rowers/tests/testdata/emails/colin.csv',a2)
|
|
||||||
a = MessageAttachment(message=m,document=a2[6:])
|
|
||||||
a.save()
|
|
||||||
|
|
||||||
def tearDown(self):
|
|
||||||
filename = 'colin4a.csv'
|
|
||||||
path = os.path.join('media/mailbox_attachments/',filename)
|
|
||||||
if not os.path.isdir(path):
|
|
||||||
try:
|
|
||||||
os.remove(path)
|
|
||||||
except (IOError,FileNotFoundError,OSError):
|
|
||||||
pass
|
|
||||||
|
|
||||||
@patch('rowers.dataprep.create_engine')
|
|
||||||
@patch('rowers.polarstuff.get_polar_notifications')
|
|
||||||
@patch('rowers.c2stuff.requests.get', side_effect=mocked_requests)
|
|
||||||
@patch('rowers.c2stuff.requests.post', side_effect=mocked_requests)
|
|
||||||
def test_emailupload(
|
|
||||||
self, mocked_sqlalchemy,mocked_polar_notifications, mock_get, mock_post):
|
|
||||||
out = StringIO()
|
|
||||||
call_command('processemail', stdout=out,testing=True,mailbox='workouts2')
|
|
||||||
self.assertIn('Successfully processed email attachments',out.getvalue())
|
|
||||||
|
|
||||||
ws = Workout.objects.filter(name="Třeboň")
|
|
||||||
|
|
||||||
self.assertEqual(len(ws),1)
|
|
||||||
w = ws[0]
|
|
||||||
self.assertEqual(w.workouttype,'water')
|
|
||||||
|
|
||||||
@override_settings(TESTING=True)
|
|
||||||
class EmailBikeErgUpload(TestCase):
|
|
||||||
def setUp(self):
|
|
||||||
redis_connection.publish('tasks','KILL')
|
|
||||||
u = User.objects.create_user('john',
|
|
||||||
'sander@ds.ds',
|
|
||||||
'koeinsloot')
|
|
||||||
r = Rower.objects.create(user=u,gdproptin=True,surveydone=True,
|
|
||||||
gdproptindate=timezone.now()
|
|
||||||
)
|
|
||||||
|
|
||||||
self.theadmin = UserFactory(is_staff=True)
|
|
||||||
self.rtheadmin = Rower.objects.create(user=self.theadmin,
|
|
||||||
birthdate = faker.profile()['birthdate'],
|
|
||||||
gdproptin=True,surveydone=True,
|
|
||||||
gdproptindate=timezone.now(),
|
|
||||||
rowerplan='coach')
|
|
||||||
|
|
||||||
nu = datetime.datetime.now()
|
|
||||||
workoutsbox = Mailbox.objects.create(name='workouts2')
|
|
||||||
workoutsbox.save()
|
|
||||||
failbox = Mailbox.objects.create(name='Failed')
|
|
||||||
failbox.save()
|
|
||||||
|
|
||||||
m = Message(mailbox=workoutsbox,
|
|
||||||
from_header = u.email,
|
|
||||||
subject = "bikeerg",
|
|
||||||
body = """
|
|
||||||
workout bikeerg
|
|
||||||
""")
|
|
||||||
m.save()
|
|
||||||
a2 = 'media/mailbox_attachments/colin3.csv'
|
|
||||||
copy('rowers/tests/testdata/emails/colin.csv',a2)
|
|
||||||
a = MessageAttachment(message=m,document=a2[6:])
|
|
||||||
a.save()
|
|
||||||
|
|
||||||
def tearDown(self):
|
|
||||||
filename = 'colin3.csv'
|
|
||||||
path = os.path.join('media/mailbox_attachments/',filename)
|
|
||||||
if not os.path.isdir(path):
|
|
||||||
try:
|
|
||||||
os.remove(path)
|
|
||||||
except (IOError,FileNotFoundError,OSError):
|
|
||||||
pass
|
|
||||||
|
|
||||||
@patch('rowers.dataprep.create_engine')
|
|
||||||
@patch('rowers.polarstuff.get_polar_notifications')
|
|
||||||
@patch('rowers.c2stuff.requests.get', side_effect=mocked_requests)
|
|
||||||
@patch('rowers.c2stuff.requests.post', side_effect=mocked_requests)
|
|
||||||
def test_emailupload(
|
|
||||||
self, mocked_sqlalchemy,mocked_polar_notifications, mock_get, mock_post):
|
|
||||||
out = StringIO()
|
|
||||||
call_command('processemail', stdout=out,testing=True,mailbox='workouts2')
|
|
||||||
self.assertIn('Successfully processed email attachments',out.getvalue())
|
|
||||||
|
|
||||||
ws = Workout.objects.filter(name="bikeerg")
|
|
||||||
|
|
||||||
self.assertEqual(len(ws),1)
|
|
||||||
w = ws[0]
|
|
||||||
self.assertEqual(w.workouttype,'bikeerg')
|
|
||||||
|
|
||||||
@override_settings(TESTING=True)
|
|
||||||
class EmailBikeUpload(TestCase):
|
|
||||||
def setUp(self):
|
|
||||||
redis_connection.publish('tasks','KILL')
|
|
||||||
u = User.objects.create_user('john',
|
|
||||||
'sander@ds.ds',
|
|
||||||
'koeinsloot')
|
|
||||||
r = Rower.objects.create(user=u,gdproptin=True,surveydone=True,
|
|
||||||
gdproptindate=timezone.now()
|
|
||||||
)
|
|
||||||
|
|
||||||
self.theadmin = UserFactory(is_staff=True)
|
|
||||||
self.rtheadmin = Rower.objects.create(user=self.theadmin,
|
|
||||||
birthdate = faker.profile()['birthdate'],
|
|
||||||
gdproptin=True,surveydone=True,
|
|
||||||
gdproptindate=timezone.now(),
|
|
||||||
rowerplan='coach')
|
|
||||||
|
|
||||||
nu = datetime.datetime.now()
|
|
||||||
workoutsbox = Mailbox.objects.create(name='workouts3')
|
|
||||||
workoutsbox.save()
|
|
||||||
failbox = Mailbox.objects.create(name='Failed')
|
|
||||||
failbox.save()
|
|
||||||
|
|
||||||
m = Message(mailbox=workoutsbox,
|
|
||||||
from_header = u.email,
|
|
||||||
subject = "bike",
|
|
||||||
body = """
|
|
||||||
workout bike
|
|
||||||
""")
|
|
||||||
m.save()
|
|
||||||
a2 = 'media/mailbox_attachments/colin4.csv'
|
|
||||||
copy('rowers/tests/testdata/emails/colin.csv',a2)
|
|
||||||
a = MessageAttachment(message=m,document=a2[6:])
|
|
||||||
a.save()
|
|
||||||
|
|
||||||
def tearDown(self):
|
|
||||||
filename = 'colin4.csv'
|
|
||||||
path = os.path.join('media/mailbox_attachments/',filename)
|
|
||||||
if not os.path.isdir(path):
|
|
||||||
try:
|
|
||||||
os.remove(path)
|
|
||||||
except (IOError,FileNotFoundError,OSError):
|
|
||||||
pass
|
|
||||||
|
|
||||||
@patch('rowers.dataprep.create_engine')
|
|
||||||
@patch('rowers.polarstuff.get_polar_notifications')
|
|
||||||
@patch('rowers.c2stuff.requests.get', side_effect=mocked_requests)
|
|
||||||
@patch('rowers.c2stuff.requests.post', side_effect=mocked_requests)
|
|
||||||
def test_emailupload(
|
|
||||||
self, mocked_sqlalchemy,mocked_polar_notifications, mock_get, mock_post):
|
|
||||||
out = StringIO()
|
|
||||||
call_command('processemail', stdout=out,testing=True,mailbox='workouts3')
|
|
||||||
self.assertIn('Successfully processed email attachments',out.getvalue())
|
|
||||||
|
|
||||||
ws = Workout.objects.filter(name="bike")
|
|
||||||
|
|
||||||
self.assertEqual(len(ws),1)
|
|
||||||
w = ws[0]
|
|
||||||
self.assertEqual(w.workouttype,'bike')
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -451,48 +180,17 @@ class EmailTests(TestCase):
|
|||||||
rowerplan='coach')
|
rowerplan='coach')
|
||||||
|
|
||||||
nu = datetime.datetime.now()
|
nu = datetime.datetime.now()
|
||||||
workoutsbox = Mailbox.objects.create(name='workouts4')
|
a2 = 'media/mailbox_attachments/colin3.csv'
|
||||||
workoutsbox.save()
|
|
||||||
failbox = Mailbox.objects.create(name='Failed')
|
|
||||||
failbox.save()
|
|
||||||
|
|
||||||
|
|
||||||
for filename in os.listdir(u'rowers/tests/testdata/emails'):
|
|
||||||
m = Message(mailbox=workoutsbox,
|
|
||||||
from_header = u.email,
|
|
||||||
subject = filename,
|
|
||||||
body="""
|
|
||||||
---
|
|
||||||
workouttype: water
|
|
||||||
boattype: 4x
|
|
||||||
...
|
|
||||||
""")
|
|
||||||
m.save()
|
|
||||||
a2 = 'media/mailbox_attachments/'+filename
|
|
||||||
copy(u'rowers/tests/testdata/emails/'+filename,a2)
|
|
||||||
a = MessageAttachment(message=m,document=a2[6:])
|
|
||||||
a.save()
|
|
||||||
|
|
||||||
m = Message(mailbox=workoutsbox,
|
|
||||||
from_header = u.email,
|
|
||||||
subject = "3x(5min/2min)/r2 \r2",
|
|
||||||
body = """
|
|
||||||
workout water
|
|
||||||
""")
|
|
||||||
m.save()
|
|
||||||
a2 = 'media/mailbox_attachments/colin2.csv'
|
|
||||||
copy('rowers/tests/testdata/emails/colin.csv',a2)
|
copy('rowers/tests/testdata/emails/colin.csv',a2)
|
||||||
a = MessageAttachment(message=m,document=a2[6:])
|
a3 = 'media/mailbox_attachments/colin4.csv'
|
||||||
a.save()
|
copy('rowers/tests/testdata/emails/colin.csv',a3)
|
||||||
|
a4 = 'media/mailbox_attachments/colin5.csv'
|
||||||
|
copy('rowers/tests/testdata/emails/colin.csv',a4)
|
||||||
|
a5 = 'media/mailbox_attachments/colin6.csv'
|
||||||
|
copy('rowers/tests/testdata/emails/colin.csv',a5)
|
||||||
|
a6 = 'media/mailbox_attachments/colin7.csv'
|
||||||
|
copy('rowers/tests/testdata/emails/colin.csv',a6)
|
||||||
|
|
||||||
m = Message(mailbox=workoutsbox,
|
|
||||||
from_header = self.theadmin.email,
|
|
||||||
subject = "johnsworkout",
|
|
||||||
body = """
|
|
||||||
user john
|
|
||||||
race 1
|
|
||||||
""")
|
|
||||||
m.save()
|
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
for filename in os.listdir('media/mailbox_attachments'):
|
for filename in os.listdir('media/mailbox_attachments'):
|
||||||
@@ -512,79 +210,3 @@ race 1
|
|||||||
out = StringIO()
|
out = StringIO()
|
||||||
call_command('processemail', stdout=out,testing=True,mailbox='workouts4')
|
call_command('processemail', stdout=out,testing=True,mailbox='workouts4')
|
||||||
self.assertIn('Successfully processed email attachments',out.getvalue())
|
self.assertIn('Successfully processed email attachments',out.getvalue())
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@override_settings(TESTING=True)
|
|
||||||
class EmailAdminUpload(TestCase):
|
|
||||||
def setUp(self):
|
|
||||||
redis_connection.publish('tasks','KILL')
|
|
||||||
u = User.objects.create_user('john',
|
|
||||||
'sander@ds.ds',
|
|
||||||
'koeinsloot')
|
|
||||||
r = Rower.objects.create(user=u,gdproptin=True,surveydone=True,
|
|
||||||
gdproptindate=timezone.now(),
|
|
||||||
birthdate = faker.profile()['birthdate']
|
|
||||||
)
|
|
||||||
|
|
||||||
self.theadmin = UserFactory(is_staff=True)
|
|
||||||
self.rtheadmin = Rower.objects.create(user=self.theadmin,
|
|
||||||
birthdate = faker.profile()['birthdate'],
|
|
||||||
gdproptin=True,surveydone=True,
|
|
||||||
gdproptindate=timezone.now(),
|
|
||||||
rowerplan='coach')
|
|
||||||
|
|
||||||
self.race = RaceFactory(manager = self.theadmin)
|
|
||||||
|
|
||||||
nu = datetime.datetime.now()
|
|
||||||
workoutsbox = Mailbox.objects.create(name='workouts5')
|
|
||||||
workoutsbox.save()
|
|
||||||
failbox = Mailbox.objects.create(name='Failed')
|
|
||||||
failbox.save()
|
|
||||||
|
|
||||||
m = Message(mailbox=workoutsbox,
|
|
||||||
from_header = self.theadmin.email,
|
|
||||||
subject = "johnsworkout",
|
|
||||||
body = """
|
|
||||||
user john
|
|
||||||
race 1
|
|
||||||
""")
|
|
||||||
m.save()
|
|
||||||
a2 = 'media/mailbox_attachments/minute.csv'
|
|
||||||
copy('rowers/tests/testdata/minute.csv',a2)
|
|
||||||
a = MessageAttachment(message=m,document=a2[6:])
|
|
||||||
a.save()
|
|
||||||
|
|
||||||
def tearDown(self):
|
|
||||||
for filename in os.listdir('media/mailbox_attachments'):
|
|
||||||
path = os.path.join('media/mailbox_attachments/',filename)
|
|
||||||
if not os.path.isdir(path):
|
|
||||||
try:
|
|
||||||
os.remove(path)
|
|
||||||
except (IOError,FileNotFoundError,OSError):
|
|
||||||
pass
|
|
||||||
|
|
||||||
@patch('rowers.dataprep.create_engine')
|
|
||||||
@patch('rowers.polarstuff.get_polar_notifications')
|
|
||||||
@patch('rowers.c2stuff.requests.get', side_effect=mocked_requests)
|
|
||||||
@patch('rowers.c2stuff.requests.post', side_effect=mocked_requests)
|
|
||||||
def test_email_admin_upload(
|
|
||||||
self, mocked_sqlalchemy,mocked_polar_notifications, mock_get, mock_post):
|
|
||||||
out = StringIO()
|
|
||||||
call_command('processemail', stdout=out,testing=True,mailbox='workouts5')
|
|
||||||
self.assertIn('Successfully processed email attachments',out.getvalue())
|
|
||||||
|
|
||||||
ws = Workout.objects.filter(name="johnsworkout")
|
|
||||||
|
|
||||||
self.assertEqual(len(ws),1)
|
|
||||||
|
|
||||||
w = ws[0]
|
|
||||||
self.assertEqual(w.user.user.username,u'john')
|
|
||||||
|
|
||||||
results = IndoorVirtualRaceResult.objects.filter(
|
|
||||||
race=self.race)
|
|
||||||
|
|
||||||
self.assertEqual(len(results),1)
|
|
||||||
result = results[0]
|
|
||||||
|
|
||||||
self.assertTrue(result.coursecompleted)
|
|
||||||
|
|||||||
@@ -510,7 +510,7 @@ urlpatterns = [
|
|||||||
re_path(r'^workout/rp3import/all/$',views.workout_getrp3workout_all,name='workout_getrp3workout_all'),
|
re_path(r'^workout/rp3import/all/$',views.workout_getrp3workout_all,name='workout_getrp3workout_all'),
|
||||||
re_path(r'^workout/(?P<source>\w+.*)import/(?P<externalid>\d+)/$',views.workout_getimportview,name='workout_getimportview'),
|
re_path(r'^workout/(?P<source>\w+.*)import/(?P<externalid>\d+)/$',views.workout_getimportview,name='workout_getimportview'),
|
||||||
re_path(r'^workout/(?P<source>\w+.*)import/(?P<externalid>\d+)/async/$',views.workout_getimportview,{'do_async':True},name='workout_getimportview'),
|
re_path(r'^workout/(?P<source>\w+.*)import/(?P<externalid>\d+)/async/$',views.workout_getimportview,{'do_async':True},name='workout_getimportview'),
|
||||||
re_path(r'^workout/stravaimport/all/$',views.workout_getstravaworkout_all,name='workout_getstravaworkout_all'),
|
# re_path(r'^workout/stravaimport/all/$',views.workout_getstravaworkout_all,name='workout_getstravaworkout_all'),
|
||||||
re_path(r'^workout/stravaimport/next/$',views.workout_getstravaworkout_next,name='workout_getstravaworkout_next'),
|
re_path(r'^workout/stravaimport/next/$',views.workout_getstravaworkout_next,name='workout_getstravaworkout_next'),
|
||||||
re_path(r'^workout/sporttracksimport/$',views.workout_sporttracksimport_view,name='workout_sporttracksimport_view'),
|
re_path(r'^workout/sporttracksimport/$',views.workout_sporttracksimport_view,name='workout_sporttracksimport_view'),
|
||||||
re_path(r'^workout/sporttracksimport/user/(?P<userid>\d+)/$',views.workout_sporttracksimport_view,name='workout_sporttracksimport_view'),
|
re_path(r'^workout/sporttracksimport/user/(?P<userid>\d+)/$',views.workout_sporttracksimport_view,name='workout_sporttracksimport_view'),
|
||||||
|
|||||||
@@ -271,7 +271,7 @@ from rq import Queue,cancel_job
|
|||||||
from django.utils.crypto import get_random_string
|
from django.utils.crypto import get_random_string
|
||||||
|
|
||||||
from django.core.cache import cache
|
from django.core.cache import cache
|
||||||
from django_mailbox.models import Message,Mailbox,MessageAttachment
|
#from django_mailbox.models import Message,Mailbox,MessageAttachment
|
||||||
|
|
||||||
from rules.contrib.views import permission_required, objectgetter
|
from rules.contrib.views import permission_required, objectgetter
|
||||||
|
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ INSTALLED_APPS = [
|
|||||||
'django_rq',
|
'django_rq',
|
||||||
# 'django_rq_dashboard',
|
# 'django_rq_dashboard',
|
||||||
# 'translation_manager',
|
# 'translation_manager',
|
||||||
'django_mailbox',
|
# 'django_mailbox',
|
||||||
'rest_framework',
|
'rest_framework',
|
||||||
'datetimewidget',
|
'datetimewidget',
|
||||||
'rest_framework_swagger',
|
'rest_framework_swagger',
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ Including another URLconf
|
|||||||
1. Import the include() function: from django.conf.urls import url, include
|
1. Import the include() function: from django.conf.urls import url, include
|
||||||
2. Add a URL to urlpatterns: re_path(r'^blog/', include('blog.urls'))
|
2. Add a URL to urlpatterns: re_path(r'^blog/', include('blog.urls'))
|
||||||
"""
|
"""
|
||||||
from django.conf.urls import url,include
|
from django.conf.urls import include
|
||||||
from django.urls import path, re_path
|
from django.urls import path, re_path
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.conf.urls.static import static
|
from django.conf.urls.static import static
|
||||||
|
|||||||
Reference in New Issue
Block a user