bug fix tp_open
This commit is contained in:
@@ -90,9 +90,15 @@ def imports_open(user,oauth_data):
|
|||||||
s = "Token doesn't exist. Need to authorize"
|
s = "Token doesn't exist. Need to authorize"
|
||||||
raise NoTokenError("User has no token")
|
raise NoTokenError("User has no token")
|
||||||
else:
|
else:
|
||||||
|
tokenname = oauth_data['tokenname']
|
||||||
|
refreshtokenname = oauth_data['refreshtokenname']
|
||||||
|
expirydatename = oauth_data['expirydatename']
|
||||||
if tokenexpirydate and timezone.now()>tokenexpirydate:
|
if tokenexpirydate and timezone.now()>tokenexpirydate:
|
||||||
token = imports_token_refresh(
|
token = imports_token_refresh(
|
||||||
user,oauth_data,
|
user,
|
||||||
|
tokenname,
|
||||||
|
refreshtokenname,
|
||||||
|
expirydatename,
|
||||||
)
|
)
|
||||||
|
|
||||||
return token
|
return token
|
||||||
|
|||||||
@@ -5,7 +5,8 @@ import re
|
|||||||
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,
|
||||||
STRAVA_CLIENT_ID, STRAVA_REDIRECT_URI, STRAVA_CLIENT_SECRET,
|
STRAVA_CLIENT_ID, STRAVA_REDIRECT_URI, STRAVA_CLIENT_SECRET,
|
||||||
SPORTTRACKS_CLIENT_SECRET, SPORTTRACKS_CLIENT_ID, SPORTTRACKS_REDIRECT_URI
|
SPORTTRACKS_CLIENT_SECRET, SPORTTRACKS_CLIENT_ID,
|
||||||
|
SPORTTRACKS_REDIRECT_URI
|
||||||
)
|
)
|
||||||
|
|
||||||
oauth_data = {
|
oauth_data = {
|
||||||
@@ -232,8 +233,7 @@ def workout_sporttracks_upload(user,w):
|
|||||||
# ready to upload. Hurray
|
# ready to upload. Hurray
|
||||||
r = w.user
|
r = w.user
|
||||||
|
|
||||||
res = sporttracks_open(user)
|
thetoken = sporttracks_open(user)
|
||||||
thetoken = res[0]
|
|
||||||
|
|
||||||
if (checkworkoutuser(user,w)):
|
if (checkworkoutuser(user,w)):
|
||||||
data = createsporttracksworkoutdata(w)
|
data = createsporttracksworkoutdata(w)
|
||||||
|
|||||||
@@ -959,6 +959,59 @@ class NewUserRegistrationTest(TestCase):
|
|||||||
status_code=302,target_status_code=200)
|
status_code=302,target_status_code=200)
|
||||||
|
|
||||||
from django_mailbox.models import Mailbox,MessageAttachment,Message
|
from django_mailbox.models import Mailbox,MessageAttachment,Message
|
||||||
|
|
||||||
|
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,
|
||||||
|
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
|
||||||
|
copyfile('rowers/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):
|
||||||
|
os.remove(path)
|
||||||
|
|
||||||
|
@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())
|
||||||
|
|
||||||
class EmailTests(TestCase):
|
class EmailTests(TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user