going through the tests
This commit is contained in:
@@ -191,7 +191,7 @@ def get_garmin_workout_list(user): # pragma: no cover
|
||||
|
||||
|
||||
def garmin_can_export_session(user):
|
||||
if user.rower.rowerplan not in ['coach', 'plan']:
|
||||
if user.rower.rowerplan != 'pro':
|
||||
return False # pragma: no cover
|
||||
result = get_garmin_permissions(user)
|
||||
if 'WORKOUT_IMPORT' in result:
|
||||
|
||||
@@ -3,7 +3,7 @@ from rowers.models import Rower, User, Workout, TombStone, PlannedSession
|
||||
from rowingdata import rowingdata
|
||||
from rowingdata import FITParser as FP
|
||||
from rowingdata.otherparsers import FitSummaryData
|
||||
from rowers.rower_rules import user_is_not_basic, user_is_coachee
|
||||
#from rowers.rower_rules import user_is_not_basic, user_is_coachee
|
||||
from rowers.dataroutines import totaltime_sec_to_string
|
||||
|
||||
from rowers import mytypes
|
||||
@@ -720,21 +720,20 @@ class IntervalsIntegration(SyncIntegration):
|
||||
def import_activities(self, event, *args, **kwargs):
|
||||
if not self.rower.intervals_auto_import:
|
||||
return 0
|
||||
if user_is_not_basic(self.rower.user) or user_is_coachee(self.rower.user):
|
||||
try:
|
||||
record = event["activity"]
|
||||
except KeyError:
|
||||
records = []
|
||||
|
||||
try:
|
||||
id = record['id']
|
||||
result = self.get_workout(id, do_async=False)
|
||||
except KeyError:
|
||||
pass
|
||||
try:
|
||||
record = event["activity"]
|
||||
except KeyError:
|
||||
records = []
|
||||
|
||||
return 1
|
||||
try:
|
||||
id = record['id']
|
||||
result = self.get_workout(id, do_async=False)
|
||||
except KeyError:
|
||||
pass
|
||||
|
||||
return 1
|
||||
|
||||
return 0
|
||||
|
||||
def delete_activities(self, event, *args, **kwargs):
|
||||
try:
|
||||
|
||||
@@ -65,7 +65,7 @@ class RojaboObjects(DjangoTestCase):
|
||||
self.r2.rojabo_refreshtoken = 'ab'
|
||||
self.r2.rojabo_tokenexpirydate = arrow.get(datetime.datetime.now()+datetime.timedelta(days=1)).datetime
|
||||
self.r2.defaulttimezone = 'Europe/Prague'
|
||||
self.r2.rowerplan = 'pro'
|
||||
self.r2.rowerplan = 'basic'
|
||||
self.r2.save()
|
||||
|
||||
self.nu = datetime.datetime.now()
|
||||
|
||||
@@ -866,7 +866,7 @@ class PermissionsViewTests(TestCase):
|
||||
status_code=302,target_status_code=200)
|
||||
|
||||
|
||||
# Create 2nd new team - should redirect to paid plans
|
||||
# Create 2nd new team - should not redirect to paid plans
|
||||
form_data = {
|
||||
'name': faker.word(),
|
||||
'notes': faker.text(),
|
||||
@@ -883,12 +883,12 @@ class PermissionsViewTests(TestCase):
|
||||
expected_url = reverse('paidplans_view')
|
||||
|
||||
response = self.c.post(url,form_data,follow=True)
|
||||
self.assertRedirects(response,
|
||||
expected_url=expected_url,
|
||||
status_code=302,target_status_code=200)
|
||||
|
||||
# check that it does not redirect and status code is 200
|
||||
self.assertEqual(response.status_code,200)
|
||||
|
||||
|
||||
## Self Coach can create planned sessions and team planned sessions
|
||||
## Pro can create planned sessions and team planned sessions
|
||||
def test_plan_create_session(self):
|
||||
login = self.c.login(username=self.uplan2.username, password=self.uplan2password)
|
||||
self.assertTrue(login)
|
||||
@@ -929,24 +929,24 @@ class PermissionsViewTests(TestCase):
|
||||
self.assertEqual(response.status_code,200)
|
||||
|
||||
|
||||
## Self Coach cannot edit on behalf of athlete
|
||||
## Team Manager cannot edit on behalf of athlete
|
||||
def test_plan_edit_athlete_settings(self):
|
||||
self.rpro.team.add(self.teampro)
|
||||
|
||||
login = self.c.login(username=self.uplan2.username, password=self.uplan2password)
|
||||
login = self.c.login(username=self.upro2.username, password=self.upro2password)
|
||||
self.assertTrue(login)
|
||||
|
||||
url = reverse('rower_prefs_view',kwargs={'userid':self.ubasic.id})
|
||||
|
||||
response = self.c.get(url)
|
||||
self.assertEqual(response.status_code,200)
|
||||
self.assertEqual(response.status_code,403)
|
||||
|
||||
## Self Coach cannot run analytics on behalf of athlete
|
||||
## Team Manager cannot run analytics on behalf of athlete
|
||||
@patch('rowers.dataprep.read_cols_df_sql', side_effect = mocked_read_df_cols_sql_multistats)
|
||||
def test_plan_edit_athlete_analysis(self,mocked_df):
|
||||
self.rpro.team.add(self.teampro)
|
||||
|
||||
login = self.c.login(username=self.uplan2.username, password=self.uplan2password)
|
||||
login = self.c.login(username=self.upro2.username, password=self.upro2password)
|
||||
self.assertTrue(login)
|
||||
|
||||
|
||||
@@ -958,22 +958,45 @@ class PermissionsViewTests(TestCase):
|
||||
|
||||
response = self.c.get(url)
|
||||
|
||||
self.assertEqual(response.status_code,200)
|
||||
self.assertEqual(response.status_code,403)
|
||||
|
||||
## Self Coach cannot upload on behalf of athlete
|
||||
## Team Manager cannot upload on behalf of athlete
|
||||
@patch('rowers.dataprep.create_engine')
|
||||
@patch('rowers.dataprep.read_data',side_effect=mocked_read_data)
|
||||
def test_plan_edit_athlete_upload(self,mocked_sqlalchemy,mocked_read_data):
|
||||
self.rpro.team.add(self.teampro)
|
||||
|
||||
login = self.c.login(username=self.uplan2.username, password=self.uplan2password)
|
||||
login = self.c.login(username=self.upro2.username, password=self.upro2password)
|
||||
self.assertTrue(login)
|
||||
|
||||
url = reverse('team_workout_upload_view')
|
||||
|
||||
# can get to the page
|
||||
response = self.c.get(url)
|
||||
self.assertEqual(response.status_code,200)
|
||||
|
||||
# cannot post the form
|
||||
filename = 'rowers/tests/testdata/testdata.csv'
|
||||
f = open(filename,'rb')
|
||||
file_data = {'file': f}
|
||||
form_data = {
|
||||
'title':'test',
|
||||
'workouttype':'rower',
|
||||
'boattype':'1x',
|
||||
'notes':'aap noot mies',
|
||||
'make_plot':False,
|
||||
'upload_to_c2':False,
|
||||
'plottype':'timeplot',
|
||||
'file': f,
|
||||
'user': self.upro.id
|
||||
}
|
||||
|
||||
response = self.c.post(url, form_data, follow=True)
|
||||
f.close()
|
||||
|
||||
# check that form errors are present in response content
|
||||
self.assertContains(response,'Select a valid choice. That choice is not one of the available choices.')
|
||||
|
||||
|
||||
## Pro can have more than one group
|
||||
def test_pro_groups_create(self):
|
||||
@@ -1007,7 +1030,7 @@ class PermissionsViewTests(TestCase):
|
||||
status_code=302,target_status_code=200)
|
||||
|
||||
|
||||
# Create 2nd new team - should redirect to paid plans
|
||||
# Create 2nd new team - should not redirect to paid plans
|
||||
form_data = {
|
||||
'name': faker.word(),
|
||||
'notes': faker.text(),
|
||||
@@ -1029,7 +1052,7 @@ class PermissionsViewTests(TestCase):
|
||||
status_code=302,target_status_code=200)
|
||||
|
||||
|
||||
## Pro cannot create planned sessions or team planned sessions
|
||||
## Pro can create planned sessions or team planned sessions
|
||||
def test_pro_create_session(self):
|
||||
login = self.c.login(username=self.upro2.username, password=self.upro2password)
|
||||
self.assertTrue(login)
|
||||
@@ -1040,48 +1063,9 @@ class PermissionsViewTests(TestCase):
|
||||
enddate = (nu+datetime.timedelta(days=3)).date()
|
||||
preferreddate = startdate
|
||||
|
||||
response = self.c.get(url,follow=True)
|
||||
response = self.c.get(url,follow=False)
|
||||
self.assertEqual(response.status_code,200)
|
||||
|
||||
expected_url = reverse('paidplans_view')
|
||||
|
||||
self.assertRedirects(response,
|
||||
expected_url=expected_url,
|
||||
status_code=302,target_status_code=200)
|
||||
|
||||
|
||||
## Pro cannot edit on behalf of athlete
|
||||
def test_pro_edit_athlete_settings(self):
|
||||
self.rpro.team.add(self.teampro)
|
||||
|
||||
login = self.c.login(username=self.upro2.username, password=self.upro2password)
|
||||
self.assertTrue(login)
|
||||
|
||||
url = reverse('rower_prefs_view',kwargs={'userid':self.ubasic.id})
|
||||
|
||||
response = self.c.get(url)
|
||||
self.assertEqual(response.status_code,403)
|
||||
|
||||
## Pro cannot run analytics on behalf of athlete
|
||||
@patch('rowers.dataprep.read_cols_df_sql', side_effect = mocked_read_df_cols_sql_multistats)
|
||||
def test_pro_edit_athlete_analysis(self,mocked_df):
|
||||
with transaction.atomic():
|
||||
self.rpro.team.add(self.teampro)
|
||||
|
||||
login = self.c.login(username=self.upro2.username, password=self.upro2password)
|
||||
self.assertTrue(login)
|
||||
|
||||
|
||||
url = reverse('analysis_new',
|
||||
kwargs={
|
||||
'userid':self.ubasic.id,
|
||||
}
|
||||
)
|
||||
|
||||
response = self.c.get(url)
|
||||
|
||||
self.assertEqual(response.status_code,403)
|
||||
|
||||
|
||||
## Basic users can see team members' workout, but not edit
|
||||
def test_basic_edit_athlete_workout(self):
|
||||
|
||||
BIN
rowers/tests/testdata/testdata.tcx.gz
vendored
BIN
rowers/tests/testdata/testdata.tcx.gz
vendored
Binary file not shown.
@@ -23,14 +23,14 @@
|
||||
24,26,addmanual_view,upload a manual workout,TRUE,302,basic,200,302,basic,200,302,coach,200,302,FALSE,FALSE,FALSE,TRUE,TRUE,
|
||||
26,28,workouts_join_view,join workouts,TRUE,302,pro,302,302,pro,403,403,coach,302,403,FALSE,TRUE,FALSE,TRUE,TRUE,
|
||||
27,29,workouts_join_select,select workouts to join,TRUE,404,pro,200,302,pro,403,403,coach,200,403,FALSE,TRUE,FALSE,TRUE,TRUE,
|
||||
29,31,analysis_new,analysis front page,TRUE,302,pro,200,302,FALSE,200,302,coach,200,302,FALSE,TRUE,FALSE,TRUE,TRUE,
|
||||
29,31,analysis_new,analysis front page,TRUE,404,pro,200,302,FALSE,200,302,coach,200,302,FALSE,TRUE,FALSE,TRUE,TRUE,
|
||||
31,33,session_jobs_view,view jobs,TRUE,302,basic,200,302,FALSE,200,302,coach,200,302,FALSE,FALSE,FALSE,TRUE,TRUE,
|
||||
32,34,session_jobs_status,view jobs,TRUE,302,basic,200,302,FALSE,200,302,coach,200,302,FALSE,FALSE,FALSE,TRUE,TRUE,
|
||||
33,35,kill_async_job,kill job,TRUE,302,basic,200,302,basic,200,302,coach,200,302,FALSE,FALSE,FALSE,FALSE,FALSE,
|
||||
34,36,post_progress,post progress,TRUE,200,basic,200,302,basic,200,302,coach,200,302,FALSE,FALSE,FALSE,FALSE,FALSE,
|
||||
35,37,graphs_view,view charts,TRUE,302,basic,200,302,basic,200,302,coach,200,302,FALSE,TRUE,FALSE,TRUE,TRUE,
|
||||
41,43,cum_flex,flex all chart,TRUE,200,basic,200,302,basic,200,302,coach,200,302,FALSE,FALSE,FALSE,FALSE,FALSE,
|
||||
42,44,analysis_view_data,redirects to analysis direct,TRUE,302,pro,200,302,pro,200,302,coach,200,302,FALSE,FALSE,FALSE,TRUE,TRUE,
|
||||
42,44,analysis_view_data,redirects to analysis direct,TRUE,404,pro,200,302,pro,200,302,coach,200,302,FALSE,FALSE,FALSE,TRUE,TRUE,
|
||||
43,47,cum_flex_data,flex all chart data (json),TRUE,200,basic,200,302,basic,200,302,coach,200,302,FALSE,FALSE,FALSE,FALSE,FALSE,
|
||||
47,53,graph_show_view,show a chart,TRUE,200,basic,200,302,basic,200,302,coach,200,302,FALSE,FALSE,FALSE,FALSE,FALSE,
|
||||
48,54,GraphDelete,delete a chart,TRUE,200,basic,200,302,basic,200,302,coach,200,302,FALSE,FALSE,FALSE,FALSE,FALSE,
|
||||
@@ -110,7 +110,7 @@
|
||||
148,188,coach_accept_coachrequest_view,Accept Coach request,TRUE,200,basic,200,302,basic,200,302,coach,200,302,FALSE,FALSE,FALSE,FALSE,FALSE,
|
||||
149,189,rower_accept_coachoffer_view,Accept Coach offer,TRUE,200,basic,200,302,basic,200,302,coach,200,302,FALSE,FALSE,FALSE,FALSE,FALSE,
|
||||
150,190,team_delete_view,Delete Team,TRUE,200,basic,200,302,basic,200,302,coach,200,302,FALSE,FALSE,FALSE,FALSE,FALSE,
|
||||
151,191,team_create_view,Create Team,TRUE,302,pro,302,302,FALSE,200,200,FALSE,200,302,FALSE,FALSE,FALSE,TRUE,TRUE,
|
||||
151,191,team_create_view,Create Team,TRUE,302,pro,200,302,FALSE,200,200,FALSE,200,302,FALSE,FALSE,FALSE,TRUE,TRUE,
|
||||
152,192,manager_member_drop_view,Drop member,TRUE,200,basic,200,302,basic,200,302,coach,200,302,FALSE,FALSE,FALSE,FALSE,FALSE,
|
||||
153,193,invitation_reject_view,Reject invitation,TRUE,200,basic,200,302,basic,200,302,coach,200,302,FALSE,FALSE,FALSE,FALSE,FALSE,
|
||||
154,194,invitation_revoke_view,redirects when no invitations,TRUE,200,basic,200,302,basic,200,302,coach,200,302,FALSE,FALSE,FALSE,FALSE,FALSE,
|
||||
@@ -151,11 +151,9 @@
|
||||
193,249,checkouts_view,checkout,TRUE,200,basic,200,302,basic,200,302,coach,200,302,FALSE,FALSE,FALSE,FALSE,FALSE,
|
||||
194,250,upgrade_checkouts_view,upgrade checkout,TRUE,200,basic,200,302,basic,200,302,coach,200,302,FALSE,FALSE,FALSE,FALSE,FALSE,
|
||||
195,251,downgrade_checkouts_view,downgrade checkout,TRUE,200,basic,200,302,basic,200,302,coach,200,302,FALSE,FALSE,FALSE,FALSE,FALSE,
|
||||
196,252,planrequired_view,a plan is required,TRUE,302,basic,302,302,basic,302,302,coach,302,302,FALSE,FALSE,FALSE,TRUE,TRUE,
|
||||
197,253,start_trial_view,payments,TRUE,200,basic,200,302,basic,200,302,coach,200,302,FALSE,FALSE,FALSE,FALSE,FALSE,
|
||||
198,254,start_plantrial_view,paid plans,TRUE,200,basic,200,302,basic,200,302,coach,200,302,FALSE,FALSE,FALSE,FALSE,FALSE,
|
||||
199,256,rower_register_view,register rower,TRUE,200,basic,200,302,basic,200,302,coach,200,302,FALSE,FALSE,FALSE,TRUE,TRUE,
|
||||
200,257,freecoach_register_view,register coach,TRUE,200,basic,200,302,basic,200,302,coach,200,302,FALSE,FALSE,FALSE,TRUE,TRUE,
|
||||
201,259,workout_workflow_view,workout workflow vieq,TRUE,302,basic,200,200,basic,200,200,coach,200,200,FALSE,FALSE,TRUE,TRUE,TRUE,
|
||||
202,260,workout_flexchart3_view,flex chart,TRUE,302,basic,200,403,basic,200,200,coach,200,200,FALSE,FALSE,TRUE,TRUE,TRUE,
|
||||
203,264,rower_process_testcallback,test callback,TRUE,200,basic,200,302,basic,200,302,coach,200,302,FALSE,FALSE,FALSE,FALSE,FALSE,
|
||||
@@ -178,8 +176,8 @@
|
||||
220,292,plannedsession_teamcreate_view,create planned session for team,TRUE,302,pro,200,302,FALSE,200,302,FALSE,200,302,FALSE,FALSE,FALSE,TRUE,TRUE,
|
||||
221,296,plannedsession_teamedit_view,edit planned sesssion,TRUE,200,basic,200,302,basic,200,302,coach,200,302,FALSE,FALSE,FALSE,FALSE,FALSE,
|
||||
222,298,plannedsession_create_view,create planned session ,TRUE,302,pro,200,302,FALSE,200,302,coach,200,403,FALSE,TRUE,FALSE,TRUE,TRUE,
|
||||
223,300,plannedsession_multiclone_view,clone multiple planned sessions,TRUE,302,pro,200,302,pro,403,403,coach,200,403,FALSE,TRUE,FALSE,TRUE,TRUE,
|
||||
224,302,plannedsession_multicreate_view,create multiple planned sessions,TRUE,302,pro,200,302,pro,403,403,coach,200,403,FALSE,TRUE,FALSE,TRUE,TRUE,
|
||||
223,300,plannedsession_multiclone_view,clone multiple planned sessions,TRUE,302,pro,200,302,pro,200,403,coach,200,403,FALSE,TRUE,FALSE,TRUE,TRUE,
|
||||
224,302,plannedsession_multicreate_view,create multiple planned sessions,TRUE,302,pro,200,302,pro,200,403,coach,200,403,FALSE,TRUE,FALSE,TRUE,TRUE,
|
||||
225,305,plannedsession_edit_view,edit planned sesssion,TRUE,200,basic,200,302,basic,200,302,coach,200,302,FALSE,FALSE,FALSE,FALSE,FALSE,
|
||||
226,306,plannedsession_totemplate_view,planned session to template,TRUE,200,basic,200,302,basic,200,302,coach,200,302,FALSE,FALSE,FALSE,FALSE,FALSE,
|
||||
227,307,plannedsession_compare_view,compare workouts from planned session,TRUE,200,basic,200,302,basic,200,302,coach,200,302,FALSE,FALSE,FALSE,FALSE,FALSE,
|
||||
@@ -264,5 +262,5 @@
|
||||
308,603,failed_queue_view,Other Apps views,TRUE,200,basic,200,302,basic,200,302,coach,200,302,FALSE,FALSE,FALSE,FALSE,FALSE,
|
||||
309,604,failed_queue_empty,Other Apps views,TRUE,200,basic,200,302,basic,200,302,coach,200,302,FALSE,FALSE,FALSE,FALSE,FALSE,
|
||||
310,605,failed_job_view,Other Apps views,TRUE,200,basic,200,302,basic,200,302,coach,200,302,FALSE,FALSE,TRUE,FALSE,FALSE,
|
||||
311,49,performancemanager_view,Performance Manager,TRUE,302,pro,200,302,pro,200,302,coach,200,302,FALSE,FALSE,FALSE,TRUE,TRUE,
|
||||
311,49,performancemanager_view,Performance Manager,TRUE,404,pro,200,302,pro,200,302,coach,200,302,FALSE,FALSE,FALSE,TRUE,TRUE,
|
||||
312,606,workout_flexchart_stacked_view,flex chart,TRUE,302,basic,200,403,basic,200,200,coach,200,200,FALSE,FALSE,TRUE,TRUE,TRUE,
|
||||
|
||||
|
@@ -399,8 +399,6 @@ def rower_process_nkcallback(request): # pragma: no cover
|
||||
|
||||
|
||||
@login_required()
|
||||
@permission_required('rower.is_coach', fn=get_user_by_userid, raise_exception=True)
|
||||
@permission_required('rower.is_not_freecoach', fn=get_user_by_userid, raise_exception=True)
|
||||
def workout_import_view(request, source='c2'):
|
||||
startdate, enddate = get_dates_timeperiod(
|
||||
request, defaulttimeperiod='last30')
|
||||
@@ -756,8 +754,8 @@ def plannedsession_intervalsimport_view(request, message="", userid=0):
|
||||
|
||||
|
||||
@login_required()
|
||||
@user_passes_test(isplanmember, login_url="/rowers/paidplans/",
|
||||
message="This functionality requires a Self-coach plan or higher",
|
||||
@user_passes_test(ispromember, login_url="/rowers/paidplans/",
|
||||
message="This functionality requires a Pro plan or higher",
|
||||
redirect_field_name=None)
|
||||
@permission_required('plannedsession.add_session', fn=get_user_by_userid, raise_exception=True)
|
||||
def workout_rojaboimport_view(request, message="", userid=0): # pragma: no cover
|
||||
|
||||
@@ -5776,7 +5776,6 @@ def team_workout_upload_view(request, userid=0, message="",
|
||||
id, jobid = uploads.make_plot(r, w, f1, f2, plottype, t)
|
||||
|
||||
else:
|
||||
|
||||
response = render(request,
|
||||
'team_document_form.html',
|
||||
{'form': form,
|
||||
|
||||
Reference in New Issue
Block a user