Private
Public Access
1
0

faking some more sql calls

This commit is contained in:
Sander Roosendaal
2019-01-03 16:06:47 +01:00
parent 331b6c0049
commit 8ff24d3fae
3 changed files with 386 additions and 55 deletions

View File

@@ -250,7 +250,7 @@ class DataTest(TestCase):
form = RowerForm(data=form_data)
self.assertFalse(form.is_valid())
def test_painsled(self):
def test_painsled_form(self):
filename = 'rowers/tests/testdata/testdata.csv'
f = open(filename,'rb')
file_data = {'file': SimpleUploadedFile(f.name, f.read())}
@@ -263,61 +263,122 @@ class DataTest(TestCase):
form = DocumentsForm(form_data,file_data)
self.assertTrue(form.is_valid())
f.close()
class InteractiveChartTest(TestCase):
def setUp(self):
redis_connection.publish('tasks','KILL')
u = User.objects.create_user('john',
'sander@ds.ds',
'koeinsloot')
r = Rower.objects.create(user=u,gdproptin=True,
gdproptindate=timezone.now()
)
self.nu = datetime.datetime.now()
self.filename = 'rowers/tests/testdata/testdata.csv'
self.wotw = Workout.objects.create(name='testworkout',
workouttype='water',
user=r,date=self.nu.strftime('%Y-%m-%d'),
starttime=self.nu.strftime('%H:%M:%S'),
duration="0:55:00",distance=8000,
csvfilename=self.filename)
self.wote = Workout.objects.create(name='testworkout',
workouttype='Indoor Rower',
user=r,date=self.nu.strftime('%Y-%m-%d'),
starttime=self.nu.strftime('%H:%M:%S'),
duration="0:55:00",distance=8000,
csvfilename=self.filename)
@patch('rowers.dataprep.create_engine')
@patch('rowers.dataprep.read_df_sql')
def test_painsled(self, mocked_sqlalchemy, mocked_read_df_sql):
u = User.objects.get(username='john')
r = Rower.objects.get(user=u)
rr = rrower(hrmax=r.max,hrut2=r.ut2,
hrut1=r.ut1,hrat=r.at,
hrtr=r.tr,hran=r.an,ftp=r.ftp)
row = rdata(filename,rower=rr)
totaldist = row.df['cum_dist'].max()
totaltime = row.df['TimeStamp (sec)'].max()-row.df['TimeStamp (sec)'].min()
totaltime = totaltime+row.df.ix[0,' ElapsedTime (sec)']
hours = int(totaltime/3600.)
minutes = int((totaltime - 3600.*hours)/60.)
seconds = int(totaltime - 3600.*hours - 60.*minutes)
tenths = int(10*(totaltime - 3600.*hours - 60.*minutes - seconds))
duration = "%s:%s:%s.%s" % (hours,minutes,seconds,tenths)
workoutdate = row.rowdatetime.strftime('%Y-%m-%d')
workoutstarttime = row.rowdatetime.strftime('%H:%M:%S')
w = Workout.objects.create(name='testworkout',workouttype='water',
user=r,date=self.nu.strftime('%Y-%m-%d'),
starttime=workoutstarttime,
duration=duration,distance=totaldist,
csvfilename=filename)
row = rdata(self.filename,rower=rr)
fig1 = plots.mkplot(row,'test')
res = iplots.interactive_chart(w.id)
res = iplots.interactive_chart(w.id,promember=1)
res = iplots.interactive_bar_chart(w.id)
res = iplots.interactive_bar_chart(w.id,promember=1)
res = iplots.interactive_flex_chart2(w.id,promember=0,xparam='time',
yparam1='pace',yparam2='hr')
res = iplots.interactive_flex_chart2(w.id,promember=0,xparam='distance',
yparam1='pace',yparam2='hr')
res = iplots.interactive_flex_chart2(w.id,promember=0,xparam='time',
yparam1='pace',yparam2='spm')
res = iplots.interactive_flex_chart2(w.id,promember=0,xparam='distance',
yparam1='pace',yparam2='spm')
res = iplots.interactive_flex_chart2(w.id,promember=1,xparam='time',
yparam1='pace',yparam2='hr')
res = iplots.interactive_flex_chart2(w.id,promember=1,xparam='distance',
yparam1='pace',yparam2='hr')
res = iplots.interactive_flex_chart2(w.id,promember=1,xparam='time',
yparam1='pace',yparam2='spm')
res = iplots.interactive_flex_chart2(w.id,promember=1,xparam='distance',
yparam1='pace',yparam2='spm')
@patch('rowers.dataprep.create_engine')
@patch('rowers.dataprep.read_df_sql')
def test_interactive_chart1(self, mocked_sqlalchemy,mocked_read_df_sql):
res = iplots.interactive_chart(self.wote.id)
@patch('rowers.dataprep.create_engine')
@patch('rowers.dataprep.read_df_sql')
def test_interactive_chart2(self, mocked_sqlalchemy,mocked_read_df_sql):
res = iplots.interactive_chart(self.wote.id,promember=1)
@patch('rowers.dataprep.create_engine')
@patch('rowers.dataprep.read_df_sql')
def test_interactive_chart3(self, mocked_sqlalchemy,mocked_read_df_sql):
res = iplots.interactive_bar_chart(self.wote.id)
@patch('rowers.dataprep.create_engine')
@patch('rowers.dataprep.read_df_sql')
def test_interactive_chart4(self, mocked_sqlalchemy,mocked_read_df_sql):
res = iplots.interactive_bar_chart(self.wote.id,promember=1)
@patch('rowers.dataprep.create_engine')
@patch('rowers.dataprep.read_df_sql')
def test_interactive_chart5(self, mocked_sqlalchemy,mocked_read_df_sql):
res = iplots.interactive_flex_chart2(self.wote.id,promember=0,
xparam='time',
yparam1='pace',yparam2='hr')
@patch('rowers.dataprep.create_engine')
@patch('rowers.dataprep.read_df_sql')
def test_interactive_chart6(self, mocked_sqlalchemy,mocked_read_df_sql):
res = iplots.interactive_flex_chart2(self.wote.id,
promember=0,xparam='distance',
yparam1='pace',yparam2='hr')
@patch('rowers.dataprep.create_engine')
@patch('rowers.dataprep.read_df_sql')
def test_interactive_chart7(self, mocked_sqlalchemy,mocked_read_df_sql):
res = iplots.interactive_flex_chart2(self.wote.id,promember=0,
xparam='time',
yparam1='pace',yparam2='spm')
@patch('rowers.dataprep.create_engine')
@patch('rowers.dataprep.read_df_sql')
def test_interactive_chart8(self, mocked_sqlalchemy,mocked_read_df_sql):
res = iplots.interactive_flex_chart2(self.wote.id,
promember=0,xparam='distance',
yparam1='pace',yparam2='spm')
@patch('rowers.dataprep.create_engine')
@patch('rowers.dataprep.read_df_sql')
def test_interactive_chart9(self, mocked_sqlalchemy,mocked_read_df_sql):
res = iplots.interactive_flex_chart2(self.wote.id,
promember=1,xparam='time',
yparam1='pace',yparam2='hr')
@patch('rowers.dataprep.create_engine')
@patch('rowers.dataprep.read_df_sql')
def test_interactive_chart10(self, mocked_sqlalchemy,mocked_read_df_sql):
res = iplots.interactive_flex_chart2(self.wote.id,
promember=1,xparam='distance',
yparam1='pace',yparam2='hr')
@patch('rowers.dataprep.create_engine')
@patch('rowers.dataprep.read_df_sql')
def test_interactive_chart11(self, mocked_sqlalchemy,mocked_read_df_sql):
res = iplots.interactive_flex_chart2(self.wote.id,
promember=1,xparam='time',
yparam1='pace',yparam2='spm')
@patch('rowers.dataprep.create_engine')
@patch('rowers.dataprep.read_df_sql')
def test_interactive_chart12(self, mocked_sqlalchemy,mocked_read_df_sql):
res = iplots.interactive_flex_chart2(self.wote.id,promember=1,
xparam='distance',
yparam1='pace',yparam2='spm')
@@ -540,7 +601,8 @@ class ViewTest(TestCase):
@patch('rowers.dataprep.create_engine')
def test_upload_view_TCX_CN(self, mocked_sqlalchemy):
@patch('rowers.dataprep.TCXParser')
def test_upload_view_TCX_CN(self, mocked_sqlalchemy, mocked_tcx_parser):
self.c.login(username='john',password='koeinsloot')
filename = 'rowers/tests/testdata/crewnerddata.tcx'
@@ -588,7 +650,9 @@ class ViewTest(TestCase):
pass
@patch('rowers.dataprep.create_engine')
def test_upload_view_TCX_SpeedCoach2a(self, mocked_sqlalchemy):
@patch('rowers.dataprep.TCXParser')
def test_upload_view_TCX_SpeedCoach2a(self, mocked_sqlalchemy,
mocked_tcx_parser):
self.c.login(username='john',password='koeinsloot')
filename = 'rowers/tests/testdata/Speedcoach2example.csv'
@@ -623,7 +687,9 @@ class ViewTest(TestCase):
pass
@patch('rowers.dataprep.create_engine')
def test_upload_view_TCX_SpeedCoach2b(self, mocked_sqlalchemy):
@patch('rowers.dataprep.TCXParser')
def test_upload_view_TCX_SpeedCoach2b(self, mocked_sqlalchemy,
mocked_tcx_parser):
self.c.login(username='john',password='koeinsloot')
filename = 'rowers/tests/testdata/Speedcoach2example.csv'
@@ -659,8 +725,10 @@ class ViewTest(TestCase):
@patch('rowers.dataprep.create_engine')
def test_upload_view_TCX_SpeedCoach2c(self, mocked_sqlalchemy):
@patch('rowers.dataprep.create_engine')
@patch('rowers.dataprep.TCXParser')
def test_upload_view_TCX_SpeedCoach2c(self, mocked_sqlalchemy,
mocked_tcx_parser):
self.c.login(username='john',password='koeinsloot')
filename = 'rowers/tests/testdata/speedcoach3test3.csv'
@@ -770,7 +838,9 @@ class ViewTest(TestCase):
@patch('rowers.dataprep.create_engine')
def test_upload_view_TCX_NoHR(self, mocked_sqlalchemy):
@patch('rowers.dataprep.TCXParser')
def test_upload_view_TCX_NoHR(self, mocked_sqlalchemy,
mocked_tcx_parser):
self.c.login(username='john',password='koeinsloot')
filename = 'rowers/tests/testdata/NoHR.tcx'
@@ -806,7 +876,9 @@ class ViewTest(TestCase):
@patch('rowers.dataprep.create_engine')
def test_upload_view_TCX_CN(self, mocked_sqlalchemy):
@patch('rowers.dataprep.TCXParser')
def test_upload_view_TCX_CN(self, mocked_sqlalchemy,
mocked_tcx_parser):
self.c.login(username='john',password='koeinsloot')
filename = 'rowers/tests/testdata/rowinginmotionexample.tcx'
@@ -1173,8 +1245,9 @@ class PlotTests(TestCase):
'powerzones':serialize_list(r.powerzones),
}
def test_ote_plots(self):
@patch('rowers.tasks.rdata')
@patch('rowers.tasks.FigureCanvas')
def test_ote_plots(self, mocked_rowingdata, mocked_canvas):
w = self.wote
f1 = 'testdata.csv'[:-4]
timestr = strftime("%Y%m%d-%H%M%S")
@@ -1311,7 +1384,9 @@ class PlotTests(TestCase):
except WindowsError:
pass
def test_otw_plots(self):
@patch('rowers.tasks.rdata')
@patch('rowers.tasks.FigureCanvas')
def test_otw_plots(self, mocked_rowingdata, mocked_canvas):
w = self.wotw
f1 = 'testdata.csv'[:-4]
timestr = strftime("%Y%m%d-%H%M%S")