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