added test for c2 auto import
This commit is contained in:
@@ -159,7 +159,7 @@ def add_stroke_data(user,c2id,workoutid,startdatetime,csvfilename,
|
||||
|
||||
return 1
|
||||
|
||||
def get_c2_workouts(rower):
|
||||
def get_c2_workouts(rower,do_async=True):
|
||||
try:
|
||||
thetoken = c2_open(rower.user)
|
||||
except NoTokenError:
|
||||
@@ -188,6 +188,7 @@ def get_c2_workouts(rower):
|
||||
newids = [c2id for c2id in c2ids if not c2id in knownc2ids]
|
||||
|
||||
for c2id in newids:
|
||||
if do_async:
|
||||
res = myqueue(queuehigh,
|
||||
handle_c2_async_workout,
|
||||
alldata,
|
||||
@@ -195,8 +196,9 @@ def get_c2_workouts(rower):
|
||||
rower.c2token,
|
||||
c2id,
|
||||
)
|
||||
#workoutid = create_async_workout(alldata,
|
||||
# rower.user,c2id)
|
||||
else:
|
||||
workoutid = create_async_workout(alldata,
|
||||
rower.user,c2id)
|
||||
|
||||
|
||||
return 1
|
||||
@@ -364,7 +366,10 @@ def create_async_workout(alldata,user,c2id):
|
||||
if response.status_code != 200:
|
||||
return 0
|
||||
|
||||
try:
|
||||
workoutid = response.json()['id']
|
||||
except KeyError:
|
||||
workoutid = 1
|
||||
|
||||
return workoutid
|
||||
|
||||
|
||||
@@ -699,7 +699,8 @@ def mocked_requests(*args, **kwargs):
|
||||
pass
|
||||
|
||||
def post(self, *args, **kwargs):
|
||||
return MockResponse('',200)
|
||||
json_data = {'id':1}
|
||||
return MockResponse(json_data,200)
|
||||
|
||||
def send(self,prepped):
|
||||
# prepped.url
|
||||
@@ -710,7 +711,7 @@ def mocked_requests(*args, **kwargs):
|
||||
json_data = {
|
||||
'access_token': 'TA3n1vrNjuQJWw0TdCDHnjSmrjIPULhTlejMIWqq',
|
||||
'expires_in': 604800,
|
||||
'refresh_token': 'jHJhFzCfOOKB8oyiayubhLAlxaMkG3ruC1E8YxaR'
|
||||
'refresh_token': 'jHJhFzCfOOKB8oyiayubhLAlxaMkG3ruC1E8YxaR',
|
||||
}
|
||||
|
||||
return MockResponse(json_data,200)
|
||||
|
||||
@@ -13,6 +13,7 @@ nu = datetime.datetime.now()
|
||||
import rowers
|
||||
from rowers import dataprep
|
||||
from rowers import tasks
|
||||
from rowers import c2stuff
|
||||
|
||||
@pytest.mark.django_db
|
||||
@override_settings(TESTING=True)
|
||||
@@ -195,7 +196,6 @@ class C2Objects(DjangoTestCase):
|
||||
def test_c2_callback(self, mock_Session):
|
||||
response = self.c.get('/call_back?code=dsdoij232s',follow=True)
|
||||
|
||||
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
|
||||
@@ -205,6 +205,19 @@ class C2Objects(DjangoTestCase):
|
||||
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
@patch('rowers.c2stuff.requests.post', side_effect=mocked_requests)
|
||||
@patch('rowers.c2stuff.requests.get', side_effect=mocked_requests)
|
||||
@patch('rowers.c2stuff.requests.session', side_effect=mocked_requests)
|
||||
def test_c2_auto_import(self, mock_get, mock_post,MockSession):
|
||||
self.r.sporttracks_auto_export = True
|
||||
self.r.save()
|
||||
res = c2stuff.get_c2_workouts(self.r)
|
||||
self.assertEqual(res,1)
|
||||
|
||||
res = c2stuff.get_c2_workouts(self.r,do_async=False)
|
||||
self.assertEqual(res,1)
|
||||
|
||||
|
||||
|
||||
@patch('rowers.c2stuff.requests.post', side_effect=mocked_requests)
|
||||
@patch('rowers.c2stuff.requests.get', side_effect=mocked_requests)
|
||||
|
||||
Reference in New Issue
Block a user