Private
Public Access
1
0

more tests and coverage

This commit is contained in:
Sander Roosendaal
2021-05-17 09:53:00 +02:00
parent d195f03a55
commit ce9621890a
5 changed files with 28 additions and 20 deletions

View File

@@ -200,7 +200,7 @@ def garmin_can_export_session(user):
if 'WORKOUT_IMPORT' in result:
return True
return False
return False # pragma: no cover
from rowers import utils
@@ -261,19 +261,19 @@ def step_to_garmin(step,order=0):
try:
targetValue = step['dict']['targetValue']
if targetValue == 0:
if targetValue == 0: # pragma: no cover
targetValue = None
except KeyError:
targetValue = None
try:
targetValueLow = step['dict']['targetValueLow']
if targetValueLow == 0:
if targetValueLow == 0: # pragma: no cover
targetValueLow = None
except KeyError:
targetValueLow = None
try:
targetValueHigh = step['dict']['targetValueHigh']
if targetValueHigh == 0:
if targetValueHigh == 0: # pragma: no cover
targetValueHigh = None
except KeyError:
targetValueHigh = None
@@ -282,9 +282,9 @@ def step_to_garmin(step,order=0):
targetType = 'POWER'
if targetValue is not None and targetValue > 1000:
targetValue -= 1000
if targetValueHigh is not None and targetValueHigh > 1000:
if targetValueHigh is not None and targetValueHigh > 1000: # pragma: no cover
targetValueHigh -= 1000
if targetValueLow is not None and targetValueLow > 1000:
if targetValueLow is not None and targetValueLow > 1000: # pragma: no cover
targetValueLow -= 1000
# temp - throw away target other than power
@@ -377,7 +377,7 @@ def ps_to_garmin(ps,r):
def get_garmin_permissions(user):
r = Rower.objects.get(user=user)
if (r.garmintoken == '') or (r.garmintoken is None):
if (r.garmintoken == '') or (r.garmintoken is None): # pragma: no cover
s = "Token doesn't exist. Need to authorize"
return custom_exception_handler(401,s)
@@ -397,19 +397,19 @@ def get_garmin_permissions(user):
if result.status_code == 200:
return result.json()
return []
return [] # pragma: no cover
def garmin_session_create(ps,user):
if not ps.steps:
return 0
return 0 # pragma: no cover
if not garmin_can_export_session(user):
return 0
return 0 # pragma: no cover
if ps.garmin_schedule_id != 0:
return ps.garmin_schedule_id
return ps.garmin_schedule_id # pragma: no cover
r = Rower.objects.get(user=user)
if (r.garmintoken == '') or (r.garmintoken is None):
if (r.garmintoken == '') or (r.garmintoken is None): # pragma: no cover
s = "Token doesn't exist. Need to authorize"
return custom_exception_handler(401,s)
@@ -427,7 +427,7 @@ def garmin_session_create(ps,user):
response = requests.post(url,auth=garminheaders,json=payload)
if response.status_code != 200:
if response.status_code != 200: # pragma: no cover
return 0
garmin_workout_id = response.json()['workoutId']
@@ -442,9 +442,9 @@ def garmin_session_create(ps,user):
response = requests.post(url,auth=garminheaders,json=payload)
if response.status_code != 200:
if response.status_code != 200: # pragma: no cover
return 0
ps.garmin_schedule_id = response.json()

View File

@@ -383,7 +383,7 @@ def async_get_workout(user,stravaid):
# Get a Strava workout summary data and stroke data by ID
def get_workout(user,stravaid,do_async=False):
if do_async:
if do_async: # pragma: no cover
res = async_get_workout(user,stravaid)
return {},pd.DataFrame()
try:

View File

@@ -3364,7 +3364,7 @@ def fetch_strava_workout(stravatoken,oauth_data,stravaid,csvfilename,userid,debu
try:
thetimezone = workoutsummary['timezone']
except:
except: # pragma: no cover
thetimezone = 'UTC'
try:

View File

@@ -181,6 +181,14 @@ class GarminObjects(DjangoTestCase):
res = gs.garmin_session_create(self.ps_trimp,self.u)
self.assertEqual(res,1212)
@patch('rowers.garmin_stuff.requests.get',side_effect=mocked_requests)
@patch('rowers.garmin_stuff.requests.post',side_effect=mocked_requests)
def test_togarmin_view(self,mock_get,mock_post):
url = reverse('plannedsession_togarmin_view',kwargs={'id':self.ps_trimp.id})
response = self.c.get(url,follow=True)
self.assertEqual(response.status_code,200)
@pytest.mark.django_db
@override_settings(TESTING=True)

View File

@@ -1994,9 +1994,9 @@ def plannedsession_togarmin_view(request,id=0):
result = gs.garmin_session_create(ps,r.user)
if not result:
messages.error(request,'You failed to export your session to Garmin Connect')
else:
if not result: # pragma: no cover
messages.error(request,'You failed to export your session to Garmin Connect') # pragma: no cover
else: # pragma: no cover
messages.info(request,'Session is now on Garmin Connect. Sync your Garmin watch')
url = reverse(plannedsession_view,kwargs={'userid':r.user.id,