Private
Public Access
1
0

some coverage related changes, new tests

This commit is contained in:
Sander Roosendaal
2021-04-09 17:30:15 +02:00
parent 5b3eddbf9f
commit 8d6f4db4b1
2 changed files with 50 additions and 14 deletions

View File

@@ -12,6 +12,42 @@ nu = datetime.datetime.now()
# interactive plots # interactive plots
from rowers import interactiveplots from rowers import interactiveplots
from rowers import dataprep 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): class DataPrepTests(TestCase):
def setUp(self): def setUp(self):

View File

@@ -17,7 +17,7 @@ import rowers.utils as utils
from urllib.parse import urlparse, parse_qs from urllib.parse import urlparse, parse_qs
from json.decoder import JSONDecodeError 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.int64): return int(o)
if isinstance(o, numpy.int32): return int(o) if isinstance(o, numpy.int32): return int(o)
raise TypeError raise TypeError
@@ -52,7 +52,7 @@ def get_video_id(url):
return query.path.split('/')[2] return query.path.split('/')[2]
elif 'youtu.be' in query.hostname: elif 'youtu.be' in query.hostname:
return query.path[1:] return query.path[1:]
else: else: # pragma: no cover
raise ValueError raise ValueError
# Show a video compared with data # Show a video compared with data
@@ -60,7 +60,7 @@ def workout_video_view_mini(request,id=''):
try: try:
id = encoder.decode_hex(id) id = encoder.decode_hex(id)
analysis = VideoAnalysis.objects.get(id=id) analysis = VideoAnalysis.objects.get(id=id)
except VideoAnalysis.DoesNotExist: except VideoAnalysis.DoesNotExist: # pragma: no cover
raise Http404("Video Analysis does not exist") raise Http404("Video Analysis does not exist")
w = analysis.workout w = analysis.workout
@@ -173,7 +173,7 @@ def workout_video_view(request,id=''):
try: try:
id = encoder.decode_hex(id) id = encoder.decode_hex(id)
analysis = VideoAnalysis.objects.get(id=id) analysis = VideoAnalysis.objects.get(id=id)
except VideoAnalysis.DoesNotExist: except VideoAnalysis.DoesNotExist: # pragma: no cover
raise Http404("Video Analysis does not exist") raise Http404("Video Analysis does not exist")
w = analysis.workout w = analysis.workout
@@ -199,7 +199,7 @@ def workout_video_view(request,id=''):
video_id = form.cleaned_data['url'] video_id = form.cleaned_data['url']
try: try:
video_id = get_video_id(form.cleaned_data['url']) video_id = get_video_id(form.cleaned_data['url'])
except (TypeError,ValueError): except (TypeError,ValueError): # pragma: no cover
pass pass
delay = form.cleaned_data['delay'] delay = form.cleaned_data['delay']
metricsgroups = metricsform.cleaned_data['groups'] metricsgroups = metricsform.cleaned_data['groups']
@@ -314,7 +314,7 @@ def workout_video_create_view(request,id=0):
url = reverse('workout_video_view', url = reverse('workout_video_view',
kwargs={'id':encoder.encode_hex(analysis.id)}) kwargs={'id':encoder.encode_hex(analysis.id)})
return HttpResponseRedirect(url) 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') 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) analysis = VideoAnalysis.objects.filter(workout=w,video_id=video_id)
if analysis: if analysis:
@@ -577,7 +577,7 @@ def addmanual_view(request,raceid=0):
if form.is_valid() and metricsform.is_valid(): if form.is_valid() and metricsform.is_valid():
# Get values from form # Get values from form
name = form.cleaned_data['name'] name = form.cleaned_data['name']
if name == '': if name == '': # pragma: no cover
name = 'Manual Entry' name = 'Manual Entry'
date = form.cleaned_data['date'] date = form.cleaned_data['date']
starttime = form.cleaned_data['starttime'] starttime = form.cleaned_data['starttime']
@@ -590,7 +590,7 @@ def addmanual_view(request,raceid=0):
rpe = form.cleaned_data['rpe'] rpe = form.cleaned_data['rpe']
if not rpe: if not rpe:
rpe = -1 rpe = -1
except KeyError: except KeyError: # pragma: no cover
rpe = -1 rpe = -1
notes = form.cleaned_data['notes'] notes = form.cleaned_data['notes']
thetimezone = form.cleaned_data['timezone'] thetimezone = form.cleaned_data['timezone']
@@ -601,25 +601,25 @@ def addmanual_view(request,raceid=0):
try: try:
ps = form.cleaned_data['plannedsession'] ps = form.cleaned_data['plannedsession']
except KeyError: except KeyError: # pragma: no cover
ps = None ps = None
try: try:
boattype = request.POST['boattype'] boattype = request.POST['boattype']
except KeyError: except KeyError: # pragma: no cover
boattype = '1x' boattype = '1x'
try: try:
privacy = request.POST['privacy'] privacy = request.POST['privacy']
except KeyError: except KeyError: # pragma: no cover
privacy = 'visible' privacy = 'visible'
try: try:
rankingpiece = form.cleaned_data['rankingpiece'] rankingpiece = form.cleaned_data['rankingpiece']
except KeyError: except KeyError: # pragma: no cover
rankingpiece = False rankingpiece = False
try: try:
duplicate = form.cleaned_data['duplicate'] duplicate = form.cleaned_data['duplicate']
except KeyError: except KeyError: # pragma: no cover
duplicate = False duplicate = False
if private: if private:
@@ -654,7 +654,7 @@ def addmanual_view(request,raceid=0):
if message: if message: # pragma: no cover
messages.error(request,message) messages.error(request,message)
if id: if id: