more or less done
This commit is contained in:
@@ -1597,13 +1597,28 @@ def add_workout_fastestrace(ws, race, r, recordid=0, doregister=False):
|
|||||||
enddatetime
|
enddatetime
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# from ws, remove any w where w.workoutsource = 'strava'. For each removal add an error "strava workout not permitted" to the errors list and if there are no workouts left, return 0, comments, errors, 0
|
||||||
|
ws2 = []
|
||||||
|
for w in ws:
|
||||||
|
if w.workoutsource != 'strava':
|
||||||
|
ws2.append(w)
|
||||||
|
else:
|
||||||
|
errors.append('Strava workouts are not permitted')
|
||||||
|
|
||||||
|
ws = ws2
|
||||||
|
|
||||||
|
if len(ws) == 0:
|
||||||
|
return result, comments, errors, 0
|
||||||
|
|
||||||
ids = [w.id for w in ws]
|
ids = [w.id for w in ws]
|
||||||
ids = list(set(ids))
|
ids = list(set(ids))
|
||||||
|
|
||||||
|
|
||||||
if len(ids) > 1 and race.sessiontype in ['test', 'coursetest', 'race', 'indoorrace', 'fastest_time', 'fastest_distance']: # pragma: no cover
|
if len(ids) > 1 and race.sessiontype in ['test', 'coursetest', 'race', 'indoorrace', 'fastest_time', 'fastest_distance']: # pragma: no cover
|
||||||
errors.append('For tests, you can only attach one workout')
|
errors.append('For tests, you can only attach one workout')
|
||||||
return result, comments, errors, 0
|
return result, comments, errors, 0
|
||||||
|
|
||||||
|
|
||||||
if r.birthdate:
|
if r.birthdate:
|
||||||
age = calculate_age(r.birthdate)
|
age = calculate_age(r.birthdate)
|
||||||
else: # pragma: no cover
|
else: # pragma: no cover
|
||||||
@@ -1759,6 +1774,19 @@ def add_workout_indoorrace(ws, race, r, recordid=0, doregister=False):
|
|||||||
enddatetime
|
enddatetime
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# from ws, remove any w where w.workoutsource = 'strava'. For each removal add an error "strava workout not permitted" to the errors list and if there are no workouts left, return 0, comments, errors, 0
|
||||||
|
ws2 = []
|
||||||
|
for w in ws:
|
||||||
|
if w.workoutsource != 'strava':
|
||||||
|
ws2.append(w)
|
||||||
|
else:
|
||||||
|
errors.append('Strava workouts are not permitted')
|
||||||
|
|
||||||
|
ws = ws2
|
||||||
|
|
||||||
|
if len(ws) == 0:
|
||||||
|
return result, comments, errors, 0
|
||||||
|
|
||||||
# check if all sessions have same date
|
# check if all sessions have same date
|
||||||
dates = [w.date for w in ws]
|
dates = [w.date for w in ws]
|
||||||
if (not all(d == dates[0] for d in dates)) and race.sessiontype not in ['challenge', 'cycletarget']: # pragma: no cover
|
if (not all(d == dates[0] for d in dates)) and race.sessiontype not in ['challenge', 'cycletarget']: # pragma: no cover
|
||||||
@@ -1906,6 +1934,19 @@ def add_workout_race(ws, race, r, splitsecond=0, recordid=0, doregister=False):
|
|||||||
enddatetime
|
enddatetime
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# from ws, remove any w where w.workoutsource = 'strava'. For each removal add an error "strava workout not permitted" to the errors list and if there are no workouts left, return 0, comments, errors, 0
|
||||||
|
ws2 = []
|
||||||
|
for w in ws:
|
||||||
|
if w.workoutsource != 'strava':
|
||||||
|
ws2.append(w)
|
||||||
|
else:
|
||||||
|
errors.append('Strava workouts are not permitted')
|
||||||
|
|
||||||
|
ws = ws2
|
||||||
|
|
||||||
|
if len(ws) == 0:
|
||||||
|
return result, comments, errors, 0
|
||||||
|
|
||||||
# check if all sessions have same date
|
# check if all sessions have same date
|
||||||
dates = [w.date for w in ws]
|
dates = [w.date for w in ws]
|
||||||
if (not all(d == dates[0] for d in dates)) and race.sessiontype not in ['challenge', 'cycletarget']: # pragma: no cover
|
if (not all(d == dates[0] for d in dates)) and race.sessiontype not in ['challenge', 'cycletarget']: # pragma: no cover
|
||||||
|
|||||||
@@ -463,6 +463,9 @@ def is_workout_user(user, workout):
|
|||||||
|
|
||||||
# check if user is in same team as owner of workout
|
# check if user is in same team as owner of workout
|
||||||
|
|
||||||
|
@rules.predicate
|
||||||
|
def workout_is_strava(workout):
|
||||||
|
return workout.workoutsource == 'strava'
|
||||||
|
|
||||||
@rules.predicate
|
@rules.predicate
|
||||||
def is_workout_team(user, workout):
|
def is_workout_team(user, workout):
|
||||||
|
|||||||
@@ -441,6 +441,12 @@ class StravaPrivacy(TestCase):
|
|||||||
|
|
||||||
self.assertEqual(response.status_code,200)
|
self.assertEqual(response.status_code,200)
|
||||||
|
|
||||||
|
# count number of workouts by counting the number of occurences of '<label for="id_workouts_xx">' in response.content where xx is a number
|
||||||
|
# print all lines of response.content that contain '<label for="id_workouts_'
|
||||||
|
#print([line for line in response.content.decode('utf-8').split('\n') if '<label for="id_workouts_' in line])
|
||||||
|
#print(form_data['workouts'])
|
||||||
|
self.assertEqual(response.content.count(b'<label for="id_workouts_'),2)
|
||||||
|
|
||||||
# get data from histodata function
|
# get data from histodata function
|
||||||
ws = Workout.objects.filter(user=self.r)
|
ws = Workout.objects.filter(user=self.r)
|
||||||
|
|
||||||
@@ -455,13 +461,6 @@ class StravaPrivacy(TestCase):
|
|||||||
self.assertEqual(data.count(','),2062)
|
self.assertEqual(data.count(','),2062)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# try and fail to submit a workout with workoutsource = strava to a challenge
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class OwnApi(TestCase):
|
class OwnApi(TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.u = UserFactory()
|
self.u = UserFactory()
|
||||||
|
|||||||
@@ -106,10 +106,26 @@ class ChallengesTest(TestCase):
|
|||||||
workouttype = 'water',
|
workouttype = 'water',
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
self.wthyro.startdatetime = arrow.get(nu).datetime
|
self.wthyro.startdatetime = arrow.get(nu).datetime
|
||||||
self.wthyro.date = nu.date()
|
self.wthyro.date = nu.date()
|
||||||
self.wthyro.save()
|
self.wthyro.save()
|
||||||
|
|
||||||
|
result = get_random_file(filename='rowers/tests/testdata/thyro.csv')
|
||||||
|
self.w_strava = WorkoutFactory(user=self.r,
|
||||||
|
csvfilename=result['filename'],
|
||||||
|
starttime=result['starttime'],
|
||||||
|
startdatetime=result['startdatetime'],
|
||||||
|
duration=result['duration'],
|
||||||
|
distance=result['totaldist'],
|
||||||
|
workouttype = 'water',
|
||||||
|
workoutsource = 'strava',
|
||||||
|
privacy = 'hidden',
|
||||||
|
)
|
||||||
|
self.w_strava.startdatetime = arrow.get(nu).datetime
|
||||||
|
self.w_strava.date = nu.date()
|
||||||
|
self.w_strava.save()
|
||||||
|
|
||||||
result = get_random_file(filename='rowers/tests/testdata/thyro.csv')
|
result = get_random_file(filename='rowers/tests/testdata/thyro.csv')
|
||||||
self.wthyro2 = WorkoutFactory(user=self.r2,
|
self.wthyro2 = WorkoutFactory(user=self.r2,
|
||||||
csvfilename=result['filename'],
|
csvfilename=result['filename'],
|
||||||
@@ -591,6 +607,78 @@ class ChallengesTest(TestCase):
|
|||||||
|
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
|
# repeat previous test for self.w_strava, but the response status of virtualevent_submit_result_view should be 403 and len(records) should be 0
|
||||||
|
@patch('django.contrib.gis.geoip2.GeoIP2.city', side_effect=mocked_requests)
|
||||||
|
def test_fastestrace_view_strava(self, mock_get):
|
||||||
|
login = self.c.login(username=self.u.username, password=self.password)
|
||||||
|
self.assertTrue(login)
|
||||||
|
|
||||||
|
race = self.FastestRace
|
||||||
|
|
||||||
|
if self.r.birthdate:
|
||||||
|
age = calculate_age(self.r.birthdate)
|
||||||
|
else:
|
||||||
|
age = 25
|
||||||
|
|
||||||
|
# look at event
|
||||||
|
url = reverse('virtualevent_view',kwargs={'id':race.id})
|
||||||
|
response = self.c.get(url)
|
||||||
|
self.assertEqual(response.status_code,200)
|
||||||
|
|
||||||
|
# register
|
||||||
|
url = reverse('virtualevent_register_view',kwargs={'id':race.id})
|
||||||
|
response = self.c.get(url)
|
||||||
|
self.assertEqual(response.status_code,200)
|
||||||
|
|
||||||
|
|
||||||
|
form_data = {
|
||||||
|
'teamname': 'ApeTeam',
|
||||||
|
'boatclass': 'water',
|
||||||
|
'boattype': '1x',
|
||||||
|
'weightcategory': 'hwt',
|
||||||
|
'adaptiveclass': 'None',
|
||||||
|
'age': age,
|
||||||
|
'mix': False,
|
||||||
|
'acceptsocialmedia': True,
|
||||||
|
}
|
||||||
|
form = VirtualRaceResultForm(form_data)
|
||||||
|
self.assertTrue(form.is_valid())
|
||||||
|
|
||||||
|
|
||||||
|
response = self.c.post(url,form_data,follow=True)
|
||||||
|
expected_url = reverse('virtualevent_view',kwargs={'id':race.id})
|
||||||
|
self.assertRedirects(response, expected_url=expected_url,
|
||||||
|
status_code=302,target_status_code=200)
|
||||||
|
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
|
# submit workout
|
||||||
|
url = reverse('virtualevent_submit_result_view',kwargs={'id':race.id,'workoutid':self.w_strava.id})
|
||||||
|
response = self.c.get(url)
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
|
# response.content should have a form with only one instance of <label for="id_workouts_0">
|
||||||
|
self.assertEqual(response.content.count(b'<label for="id_workouts_0">'),1)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
records = IndoorVirtualRaceResult.objects.filter(userid=self.u.id)
|
||||||
|
self.assertEqual(len(records),1)
|
||||||
|
|
||||||
|
record = records[0]
|
||||||
|
|
||||||
|
|
||||||
|
form_data = {
|
||||||
|
'workouts':[self.w_strava.id],
|
||||||
|
'record':record.id,
|
||||||
|
}
|
||||||
|
|
||||||
|
response = self.c.post(url,form_data,follow=True)
|
||||||
|
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
|
# in response.content, there should be a p with class errormessage and the text "Error in form"
|
||||||
|
self.assertTrue(b'Error in form' in response.content)
|
||||||
|
|
||||||
@patch('django.contrib.gis.geoip2.GeoIP2.city', side_effect=mocked_requests)
|
@patch('django.contrib.gis.geoip2.GeoIP2.city', side_effect=mocked_requests)
|
||||||
def test_virtualevents_view(self, mock_get):
|
def test_virtualevents_view(self, mock_get):
|
||||||
|
|||||||
BIN
rowers/tests/testdata/testdata.tcx.gz
vendored
BIN
rowers/tests/testdata/testdata.tcx.gz
vendored
Binary file not shown.
@@ -48,6 +48,9 @@ def analysis_new(request,
|
|||||||
firstworkout = get_workout(id)
|
firstworkout = get_workout(id)
|
||||||
if not is_workout_team(request.user, firstworkout): # pragma: no cover
|
if not is_workout_team(request.user, firstworkout): # pragma: no cover
|
||||||
raise PermissionDenied("You are not allowed to use this workout")
|
raise PermissionDenied("You are not allowed to use this workout")
|
||||||
|
if workout_is_strava(firstworkout):
|
||||||
|
messages.error(request, "You cannot use Strava workouts for analysis")
|
||||||
|
raise PermissionDenied("You cannot use Strava workouts for analysis")
|
||||||
firstworkoutquery = Workout.objects.filter(id=encoder.decode_hex(id))
|
firstworkoutquery = Workout.objects.filter(id=encoder.decode_hex(id))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@@ -218,6 +221,7 @@ def analysis_new(request,
|
|||||||
)
|
)
|
||||||
if firstworkout:
|
if firstworkout:
|
||||||
workouts = firstworkoutquery | workouts
|
workouts = firstworkoutquery | workouts
|
||||||
|
|
||||||
workouts = workouts.order_by(
|
workouts = workouts.order_by(
|
||||||
"-date", "-starttime"
|
"-date", "-starttime"
|
||||||
).exclude(boattype__in=negtypes)
|
).exclude(boattype__in=negtypes)
|
||||||
@@ -253,7 +257,7 @@ def analysis_new(request,
|
|||||||
else:
|
else:
|
||||||
selectedworkouts = Workout.objects.filter(id__in=ids)
|
selectedworkouts = Workout.objects.filter(id__in=ids)
|
||||||
|
|
||||||
form.fields["workouts"].queryset = workouts | selectedworkouts
|
form.fields["workouts"].queryset = (workouts | selectedworkouts).exclude(workoutsource='strava')
|
||||||
|
|
||||||
optionsform = AnalysisOptionsForm(initial={
|
optionsform = AnalysisOptionsForm(initial={
|
||||||
'modality': modality,
|
'modality': modality,
|
||||||
|
|||||||
@@ -3397,12 +3397,12 @@ def virtualevent_submit_result_view(request, id=0, workoutid=0):
|
|||||||
startdatetime__gte=startdatetime,
|
startdatetime__gte=startdatetime,
|
||||||
startdatetime__lte=enddatetime,
|
startdatetime__lte=enddatetime,
|
||||||
distance__gte=race.approximate_distance,
|
distance__gte=race.approximate_distance,
|
||||||
).order_by("-date", "-startdatetime", "id")
|
).order_by("-date", "-startdatetime", "id").exclude(workoutsource='strava')
|
||||||
|
|
||||||
if not ws: # pragma: no cover
|
if not ws: # pragma: no cover
|
||||||
messages.info(
|
messages.info(
|
||||||
request,
|
request,
|
||||||
'You have no workouts executed during the race window. Please upload a result or enter it manually.'
|
'You have no eligible workouts executed during the race window. Please upload a result or enter it manually.'
|
||||||
)
|
)
|
||||||
|
|
||||||
url = reverse('virtualevent_view',
|
url = reverse('virtualevent_view',
|
||||||
@@ -3436,6 +3436,7 @@ def virtualevent_submit_result_view(request, id=0, workoutid=0):
|
|||||||
splitsecond = 0
|
splitsecond = 0
|
||||||
recordid = w_form.cleaned_data['record']
|
recordid = w_form.cleaned_data['record']
|
||||||
else:
|
else:
|
||||||
|
messages.error(request,"Error in form")
|
||||||
selectedworkout = None
|
selectedworkout = None
|
||||||
|
|
||||||
if selectedworkout is not None:
|
if selectedworkout is not None:
|
||||||
@@ -3518,7 +3519,12 @@ def virtualevent_submit_result_view(request, id=0, workoutid=0):
|
|||||||
|
|
||||||
else:
|
else:
|
||||||
if workoutid:
|
if workoutid:
|
||||||
workoutdata['initial'] = encoder.decode_hex(workoutid)
|
try:
|
||||||
|
w = Workout.objects.get(id=workoutid)
|
||||||
|
if w.workoutsource != 'strava':
|
||||||
|
workoutdata['initial'] = encoder.decode_hex(workoutid)
|
||||||
|
except Workout.DoesNotExist:
|
||||||
|
pass
|
||||||
w_form = WorkoutRaceSelectForm(workoutdata, entries)
|
w_form = WorkoutRaceSelectForm(workoutdata, entries)
|
||||||
|
|
||||||
breadcrumbs = [
|
breadcrumbs = [
|
||||||
|
|||||||
@@ -82,7 +82,8 @@ from rowers.rower_rules import (
|
|||||||
can_add_workout_member, can_plan_user, is_paid_coach,
|
can_add_workout_member, can_plan_user, is_paid_coach,
|
||||||
can_start_trial, can_start_plantrial, can_start_coachtrial,
|
can_start_trial, can_start_plantrial, can_start_coachtrial,
|
||||||
can_plan, is_workout_team,
|
can_plan, is_workout_team,
|
||||||
is_promember,user_is_basic, is_coachtrial, is_coach
|
is_promember,user_is_basic, is_coachtrial, is_coach,
|
||||||
|
workout_is_strava
|
||||||
)
|
)
|
||||||
|
|
||||||
from django.shortcuts import render
|
from django.shortcuts import render
|
||||||
|
|||||||
Reference in New Issue
Block a user