almost passing tests
This commit is contained in:
@@ -42,7 +42,9 @@ 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.urls import reverse
|
||||||
|
import requests
|
||||||
|
|
||||||
from django.core.exceptions import ValidationError
|
from django.core.exceptions import ValidationError
|
||||||
|
|
||||||
from time import strftime
|
from time import strftime
|
||||||
@@ -2102,21 +2104,26 @@ def new_workout_from_file(r, f2,
|
|||||||
|
|
||||||
# Save zip files to email box for further processing
|
# Save zip files to email box for further processing
|
||||||
if len(fileformat) == 3 and fileformat[0] == 'zip': # pragma: no cover
|
if len(fileformat) == 3 and fileformat[0] == 'zip': # pragma: no cover
|
||||||
uploadoptions['fromuploadform'] = True
|
uploadoptions['secret'] = settings.UPLOAD_SERVICE_SECRET
|
||||||
bodyyaml = yaml.safe_dump(uploadoptions,default_flow_style=False)
|
uploadoptions['user'] = r.user.id
|
||||||
f_to_be_deleted = f2
|
uploadoptions['title'] = title
|
||||||
|
try:
|
||||||
|
zip_file = zipfile.ZipFile(f2)
|
||||||
|
for id,filename in enumerate(zip_file.namelist()):
|
||||||
|
datafile = zip_file.extract(filename, path='media/')
|
||||||
|
if id>0:
|
||||||
|
uploadoptions['title'] = title+' ('+str(id+1)+')'
|
||||||
|
else:
|
||||||
|
uploadoptions['title'] = title
|
||||||
|
|
||||||
|
uploadoptions['file'] = datafile
|
||||||
|
url = settings.UPLOAD_SERVICE_URL
|
||||||
|
|
||||||
|
response = requests.post(url,uploadoptions)
|
||||||
|
|
||||||
|
except BadZipFile: # pragma: no cover
|
||||||
|
pass
|
||||||
|
|
||||||
workoutsbox = Mailbox.objects.filter(name='workouts')[0]
|
|
||||||
msg = Message(mailbox=workoutsbox,
|
|
||||||
from_header=r.user.email,
|
|
||||||
subject = title,body=bodyyaml)
|
|
||||||
msg.save()
|
|
||||||
f3 = 'media/mailbox_attachments/'+f2[6:]
|
|
||||||
copyfile(f2,f3)
|
|
||||||
f3 = f3[6:]
|
|
||||||
a = MessageAttachment(message=msg,document=f3)
|
|
||||||
a.save()
|
|
||||||
message = "Zip file was stored for offline processing"
|
|
||||||
|
|
||||||
return -1, message, f2
|
return -1, message, f2
|
||||||
|
|
||||||
|
|||||||
@@ -12,11 +12,6 @@ from rowers.tasks import (
|
|||||||
handle_sendemail_unrecognized,
|
handle_sendemail_unrecognized,
|
||||||
handle_sendemail_unrecognizedowner
|
handle_sendemail_unrecognizedowner
|
||||||
)
|
)
|
||||||
#from django_mailbox.models import Message, MessageAttachment,Mailbox
|
|
||||||
|
|
||||||
#workoutmailbox = Mailbox.objects.get(name='workouts')
|
|
||||||
#failedmailbox = Mailbox.objects.get(name='Failed')
|
|
||||||
|
|
||||||
|
|
||||||
from rowers.models import User, Rower, RowerForm
|
from rowers.models import User, Rower, RowerForm
|
||||||
|
|
||||||
|
|||||||
@@ -195,7 +195,6 @@ def get_polar_workouts(user):
|
|||||||
|
|
||||||
if response.status_code == 201:
|
if response.status_code == 201:
|
||||||
|
|
||||||
workoutsbox = Mailbox.objects.filter(name='workouts')[0]
|
|
||||||
uploadoptions = {
|
uploadoptions = {
|
||||||
'makeprivate':False,
|
'makeprivate':False,
|
||||||
}
|
}
|
||||||
@@ -242,8 +241,6 @@ def get_polar_workouts(user):
|
|||||||
|
|
||||||
if response.status_code == 200:
|
if response.status_code == 200:
|
||||||
exercise_dict['filename'] = filename
|
exercise_dict['filename'] = filename
|
||||||
else:
|
|
||||||
print(response.status_code)
|
|
||||||
else:
|
else:
|
||||||
exercise_dict['filename'] = ''
|
exercise_dict['filename'] = ''
|
||||||
|
|
||||||
|
|||||||
@@ -37,10 +37,6 @@ class OwnApi(TestCase):
|
|||||||
gdproptindate=timezone.now(),
|
gdproptindate=timezone.now(),
|
||||||
rowerplan='coach',subscription_id=1)
|
rowerplan='coach',subscription_id=1)
|
||||||
|
|
||||||
workoutsbox = Mailbox.objects.create(name='workouts')
|
|
||||||
workoutsbox.save()
|
|
||||||
failbox = Mailbox.objects.create(name='Failed')
|
|
||||||
failbox.save()
|
|
||||||
|
|
||||||
self.c = Client()
|
self.c = Client()
|
||||||
self.user_workouts = WorkoutFactory.create_batch(5, user=self.r)
|
self.user_workouts = WorkoutFactory.create_batch(5, user=self.r)
|
||||||
|
|||||||
@@ -69,10 +69,6 @@ class BraintreeUnits(TestCase):
|
|||||||
gdproptindate=timezone.now(),
|
gdproptindate=timezone.now(),
|
||||||
rowerplan='coach',subscription_id=1)
|
rowerplan='coach',subscription_id=1)
|
||||||
|
|
||||||
workoutsbox = Mailbox.objects.create(name='workouts')
|
|
||||||
workoutsbox.save()
|
|
||||||
failbox = Mailbox.objects.create(name='Failed')
|
|
||||||
failbox.save()
|
|
||||||
|
|
||||||
self.pp = PaidPlan.objects.create(price=0,paymentprocessor='braintree')
|
self.pp = PaidPlan.objects.create(price=0,paymentprocessor='braintree')
|
||||||
self.p2 = PaidPlan.objects.create(price=25,paymentprocessor='braintree')
|
self.p2 = PaidPlan.objects.create(price=25,paymentprocessor='braintree')
|
||||||
|
|||||||
@@ -1258,62 +1258,3 @@ class TPObjects(DjangoTestCase):
|
|||||||
|
|
||||||
self.assertEqual(response.url, '/rowers/workout/'+encoded1+'/edit/')
|
self.assertEqual(response.url, '/rowers/workout/'+encoded1+'/edit/')
|
||||||
self.assertEqual(response.status_code, 302)
|
self.assertEqual(response.status_code, 302)
|
||||||
|
|
||||||
|
|
||||||
#@pytest.mark.django_db
|
|
||||||
@override_settings(TESTING=True)
|
|
||||||
class AutoExportTests(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()
|
|
||||||
)
|
|
||||||
|
|
||||||
r.c2_auto_export = True
|
|
||||||
r.sporttracks_auto_export = True
|
|
||||||
r.mapmyfitness_auto_export = True
|
|
||||||
r.trainingpeaks_auto_export = True
|
|
||||||
|
|
||||||
r.save()
|
|
||||||
|
|
||||||
nu = datetime.datetime.now()
|
|
||||||
workoutsbox = Mailbox.objects.create(name='workouts')
|
|
||||||
workoutsbox.save()
|
|
||||||
failbox = Mailbox.objects.create(name='Failed')
|
|
||||||
failbox.save()
|
|
||||||
|
|
||||||
filename = 'testdata.csv'
|
|
||||||
|
|
||||||
m = Message(mailbox=workoutsbox,
|
|
||||||
from_header = u.email,
|
|
||||||
subject = filename,
|
|
||||||
body="""
|
|
||||||
---
|
|
||||||
workouttype: water
|
|
||||||
boattype: 2x
|
|
||||||
...
|
|
||||||
""")
|
|
||||||
m.save()
|
|
||||||
a2 = 'media/mailbox_attachments/'+filename
|
|
||||||
copy('rowers/tests/testdata/'+filename,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 (FileNotFoundError,OSError):
|
|
||||||
pass
|
|
||||||
|
|
||||||
@patch('rowers.tpstuff.requests.post', side_effect=mocked_requests)
|
|
||||||
@patch('rowers.tpstuff.requests.get', side_effect=mocked_requests)
|
|
||||||
def test_emailprocessing(self, mock_post, mock_get):
|
|
||||||
out = StringIO()
|
|
||||||
call_command('processemail', stdout=out, testing=True)
|
|
||||||
self.assertIn('Successfully processed email attachments',out.getvalue())
|
|
||||||
|
|||||||
@@ -35,10 +35,6 @@ class OtherUnitTests(TestCase):
|
|||||||
defaulttimezone='US/Pacific',
|
defaulttimezone='US/Pacific',
|
||||||
rowerplan='coach')
|
rowerplan='coach')
|
||||||
|
|
||||||
workoutsbox = Mailbox.objects.create(name='workouts')
|
|
||||||
workoutsbox.save()
|
|
||||||
failbox = Mailbox.objects.create(name='Failed')
|
|
||||||
failbox.save()
|
|
||||||
|
|
||||||
# Test get_dates_timeperiod
|
# Test get_dates_timeperiod
|
||||||
def test_get_dates_timeperiod(self):
|
def test_get_dates_timeperiod(self):
|
||||||
@@ -99,20 +95,6 @@ class OtherUnitTests(TestCase):
|
|||||||
self.assertTrue('US/Pacific' in str(startdate.tzinfo))
|
self.assertTrue('US/Pacific' in str(startdate.tzinfo))
|
||||||
|
|
||||||
|
|
||||||
@patch('rowers.tasks.requests.get',side_effect=mocked_requests)
|
|
||||||
def test_strava_asyncworkout(self,mock_get):
|
|
||||||
with open('rowers/tests/testdata/stravaworkoutlist.txt','r') as f:
|
|
||||||
s = f.read()
|
|
||||||
|
|
||||||
jsondata = json.loads(s)
|
|
||||||
alldata = {}
|
|
||||||
for item in jsondata:
|
|
||||||
alldata[item['id']] = item
|
|
||||||
|
|
||||||
theid = jsondata[0]['id']
|
|
||||||
|
|
||||||
workoutid = stravastuff.create_async_workout(alldata,self.r.user,theid)
|
|
||||||
self.assertEqual(workoutid,1)
|
|
||||||
|
|
||||||
def test_summaryfromsplitdata(self):
|
def test_summaryfromsplitdata(self):
|
||||||
with open('rowers/tests/testdata/c2splits.json','r') as f:
|
with open('rowers/tests/testdata/c2splits.json','r') as f:
|
||||||
|
|||||||
@@ -87,7 +87,6 @@
|
|||||||
97,114,workout_undo_smoothenpace_view,unsmoothen pace,TRUE,403,pro,302,302,pro,403,403,coach,302,403,FALSE,FALSE,TRUE,TRUE,TRUE,
|
97,114,workout_undo_smoothenpace_view,unsmoothen pace,TRUE,403,pro,302,302,pro,403,403,coach,302,403,FALSE,FALSE,TRUE,TRUE,TRUE,
|
||||||
98,115,workout_c2import_view,list workouts to be imported (test stops at notokenerror),TRUE,302,basic,302,302,basic,403,403,coach,302,403,FALSE,TRUE,FALSE,TRUE,TRUE,
|
98,115,workout_c2import_view,list workouts to be imported (test stops at notokenerror),TRUE,302,basic,302,302,basic,403,403,coach,302,403,FALSE,TRUE,FALSE,TRUE,TRUE,
|
||||||
99,120,workout_stravaimport_view,list workouts to be imported (test stops at notokenerror),TRUE,302,basic,302,302,basic,403,403,coach,302,403,FALSE,TRUE,FALSE,TRUE,TRUE,
|
99,120,workout_stravaimport_view,list workouts to be imported (test stops at notokenerror),TRUE,302,basic,302,302,basic,403,403,coach,302,403,FALSE,TRUE,FALSE,TRUE,TRUE,
|
||||||
100,122,workout_getc2workout_all,gets all C2 workouts (now redirects due to NoTokenError,TRUE,302,basic,302,302,FALSE,302,302,FALSE,302,302,FALSE,FALSE,FALSE,TRUE,TRUE,
|
|
||||||
101,124,workout_getimportview,imports a workout from third party,TRUE,200,basic,200,302,FALSE,200,302,FALSE,200,302,FALSE,FALSE,FALSE,FALSE,FALSE,
|
101,124,workout_getimportview,imports a workout from third party,TRUE,200,basic,200,302,FALSE,200,302,FALSE,200,302,FALSE,FALSE,FALSE,FALSE,FALSE,
|
||||||
102,125,workout_getstravaworkout_all,gets all C2 workouts (now redirects due to NoTokenError,TRUE,302,basic,302,302,FALSE,302,302,FALSE,302,302,FALSE,FALSE,FALSE,TRUE,TRUE,
|
102,125,workout_getstravaworkout_all,gets all C2 workouts (now redirects due to NoTokenError,TRUE,302,basic,302,302,FALSE,302,302,FALSE,302,302,FALSE,FALSE,FALSE,TRUE,TRUE,
|
||||||
103,126,workout_getstravaworkout_next,gets all strava workouts,TRUE,302,basic,302,302,FALSE,200,302,FALSE,200,302,FALSE,FALSE,FALSE,FALSE,FALSE,
|
103,126,workout_getstravaworkout_next,gets all strava workouts,TRUE,302,basic,302,302,FALSE,200,302,FALSE,200,302,FALSE,FALSE,FALSE,FALSE,FALSE,
|
||||||
|
|||||||
|
@@ -271,7 +271,6 @@ 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 rules.contrib.views import permission_required, objectgetter
|
from rules.contrib.views import permission_required, objectgetter
|
||||||
|
|
||||||
|
|||||||
@@ -5435,26 +5435,15 @@ def workout_upload_view(request,
|
|||||||
title = t,
|
title = t,
|
||||||
notes=notes,
|
notes=notes,
|
||||||
)
|
)
|
||||||
else: # pragma: no cover
|
else:
|
||||||
workoutsbox = Mailbox.objects.filter(name='workouts')[0]
|
uploadoptions['secret'] = settings.UPLOAD_SERVICE_SECRET
|
||||||
uploadoptions['fromuploadform'] = True
|
uploadoptions['user'] = r.user.id
|
||||||
bodyyaml = yaml.safe_dump(
|
uploadoptions['title'] = t
|
||||||
uploadoptions,
|
uploadoptions['file'] = f2
|
||||||
default_flow_style=False
|
|
||||||
)
|
url = settings.UPLOAD_SERVICE_URL
|
||||||
msg = Message(mailbox=workoutsbox,
|
|
||||||
from_header=r.user.email,
|
response = requests.post(url,uploadoptions)
|
||||||
subject = t,body=bodyyaml)
|
|
||||||
msg.save()
|
|
||||||
f3 = 'media/mailbox_attachments/'+f2[6:]
|
|
||||||
copyfile(f2,f3)
|
|
||||||
f3 = f3[6:]
|
|
||||||
a = MessageAttachment(message=msg,document=f3)
|
|
||||||
try:
|
|
||||||
a.save()
|
|
||||||
except DataError:
|
|
||||||
pass
|
|
||||||
os.remove(f2)
|
|
||||||
|
|
||||||
messages.info(
|
messages.info(
|
||||||
request,
|
request,
|
||||||
|
|||||||
Reference in New Issue
Block a user