some coverage related changes, new tests
This commit is contained in:
@@ -12,6 +12,42 @@ nu = datetime.datetime.now()
|
||||
# interactive plots
|
||||
from rowers import interactiveplots
|
||||
from rowers import dataprep
|
||||
from rowers.views.workoutviews import get_video_id
|
||||
|
||||
class OtherUnitTests(TestCase):
|
||||
def test_get_video_id(self):
|
||||
url1 = 'http://youtu.be/_lOT2p_FCvA'
|
||||
url2 = 'www.youtube.com/watch?v=_lOT2p_FCvA&feature=feedu'
|
||||
url3 = 'http://www.youtube.com/embed/_lOT2p_FCvA'
|
||||
url4 = 'http://www.youtube.com/v/_lOT2p_FCvA?version=3&hl=en_US'
|
||||
url5 = 'https://www.youtube.com/watch?v=rTHlyTphWP0&index=6&list=PLjeDyYvG6-40qawYNR4juzvSOg-ezZ2a6'
|
||||
url6 = 'youtube.com/watch?v=_lOT2p_FCvA'
|
||||
expected = '_lOT2p_FCvA'
|
||||
expected2 = 'rTHlyTphWP0'
|
||||
|
||||
result = get_video_id(url1)
|
||||
|
||||
self.assertEqual(result,expected)
|
||||
|
||||
result = get_video_id(url2)
|
||||
|
||||
self.assertEqual(result,expected)
|
||||
|
||||
result = get_video_id(url3)
|
||||
|
||||
self.assertEqual(result,expected)
|
||||
|
||||
result = get_video_id(url4)
|
||||
|
||||
self.assertEqual(result,expected)
|
||||
|
||||
result = get_video_id(url5)
|
||||
|
||||
self.assertEqual(result,expected2)
|
||||
|
||||
result = get_video_id(url6)
|
||||
|
||||
self.assertEqual(result,expected)
|
||||
|
||||
class DataPrepTests(TestCase):
|
||||
def setUp(self):
|
||||
|
||||
@@ -17,7 +17,7 @@ import rowers.utils as utils
|
||||
from urllib.parse import urlparse, parse_qs
|
||||
from json.decoder import JSONDecodeError
|
||||
|
||||
def default(o):
|
||||
def default(o): # pragma: no cover
|
||||
if isinstance(o, numpy.int64): return int(o)
|
||||
if isinstance(o, numpy.int32): return int(o)
|
||||
raise TypeError
|
||||
@@ -52,7 +52,7 @@ def get_video_id(url):
|
||||
return query.path.split('/')[2]
|
||||
elif 'youtu.be' in query.hostname:
|
||||
return query.path[1:]
|
||||
else:
|
||||
else: # pragma: no cover
|
||||
raise ValueError
|
||||
|
||||
# Show a video compared with data
|
||||
@@ -60,7 +60,7 @@ def workout_video_view_mini(request,id=''):
|
||||
try:
|
||||
id = encoder.decode_hex(id)
|
||||
analysis = VideoAnalysis.objects.get(id=id)
|
||||
except VideoAnalysis.DoesNotExist:
|
||||
except VideoAnalysis.DoesNotExist: # pragma: no cover
|
||||
raise Http404("Video Analysis does not exist")
|
||||
|
||||
w = analysis.workout
|
||||
@@ -173,7 +173,7 @@ def workout_video_view(request,id=''):
|
||||
try:
|
||||
id = encoder.decode_hex(id)
|
||||
analysis = VideoAnalysis.objects.get(id=id)
|
||||
except VideoAnalysis.DoesNotExist:
|
||||
except VideoAnalysis.DoesNotExist: # pragma: no cover
|
||||
raise Http404("Video Analysis does not exist")
|
||||
|
||||
w = analysis.workout
|
||||
@@ -199,7 +199,7 @@ def workout_video_view(request,id=''):
|
||||
video_id = form.cleaned_data['url']
|
||||
try:
|
||||
video_id = get_video_id(form.cleaned_data['url'])
|
||||
except (TypeError,ValueError):
|
||||
except (TypeError,ValueError): # pragma: no cover
|
||||
pass
|
||||
delay = form.cleaned_data['delay']
|
||||
metricsgroups = metricsform.cleaned_data['groups']
|
||||
@@ -314,7 +314,7 @@ def workout_video_create_view(request,id=0):
|
||||
url = reverse('workout_video_view',
|
||||
kwargs={'id':encoder.encode_hex(analysis.id)})
|
||||
return HttpResponseRedirect(url)
|
||||
except IntegrityError:
|
||||
except IntegrityError: # pragma: no cover
|
||||
messages.error(request,'You cannot save two video analysis with the same YouTube video and Workout. Redirecting to your existing analysis')
|
||||
analysis = VideoAnalysis.objects.filter(workout=w,video_id=video_id)
|
||||
if analysis:
|
||||
@@ -577,7 +577,7 @@ def addmanual_view(request,raceid=0):
|
||||
if form.is_valid() and metricsform.is_valid():
|
||||
# Get values from form
|
||||
name = form.cleaned_data['name']
|
||||
if name == '':
|
||||
if name == '': # pragma: no cover
|
||||
name = 'Manual Entry'
|
||||
date = form.cleaned_data['date']
|
||||
starttime = form.cleaned_data['starttime']
|
||||
@@ -590,7 +590,7 @@ def addmanual_view(request,raceid=0):
|
||||
rpe = form.cleaned_data['rpe']
|
||||
if not rpe:
|
||||
rpe = -1
|
||||
except KeyError:
|
||||
except KeyError: # pragma: no cover
|
||||
rpe = -1
|
||||
notes = form.cleaned_data['notes']
|
||||
thetimezone = form.cleaned_data['timezone']
|
||||
@@ -601,25 +601,25 @@ def addmanual_view(request,raceid=0):
|
||||
|
||||
try:
|
||||
ps = form.cleaned_data['plannedsession']
|
||||
except KeyError:
|
||||
except KeyError: # pragma: no cover
|
||||
ps = None
|
||||
|
||||
try:
|
||||
boattype = request.POST['boattype']
|
||||
except KeyError:
|
||||
except KeyError: # pragma: no cover
|
||||
boattype = '1x'
|
||||
try:
|
||||
privacy = request.POST['privacy']
|
||||
except KeyError:
|
||||
except KeyError: # pragma: no cover
|
||||
privacy = 'visible'
|
||||
try:
|
||||
rankingpiece = form.cleaned_data['rankingpiece']
|
||||
except KeyError:
|
||||
except KeyError: # pragma: no cover
|
||||
rankingpiece = False
|
||||
|
||||
try:
|
||||
duplicate = form.cleaned_data['duplicate']
|
||||
except KeyError:
|
||||
except KeyError: # pragma: no cover
|
||||
duplicate = False
|
||||
|
||||
if private:
|
||||
@@ -654,7 +654,7 @@ def addmanual_view(request,raceid=0):
|
||||
|
||||
|
||||
|
||||
if message:
|
||||
if message: # pragma: no cover
|
||||
messages.error(request,message)
|
||||
|
||||
if id:
|
||||
|
||||
Reference in New Issue
Block a user