a few more tests
This commit is contained in:
176
rowers/tests/test_flexchart.py
Normal file
176
rowers/tests/test_flexchart.py
Normal file
@@ -0,0 +1,176 @@
|
||||
from statements import *
|
||||
|
||||
@override_settings(TESTING=True)
|
||||
class WorkoutViewTest(TestCase):
|
||||
def setUp(self):
|
||||
self.u = UserFactory()
|
||||
|
||||
self.r = Rower.objects.create(user=self.u,
|
||||
birthdate=faker.profile()['birthdate'],
|
||||
gdproptin=True,
|
||||
gdproptindate=timezone.now(),
|
||||
rowerplan='coach',
|
||||
showfavoritechartnotes=True)
|
||||
|
||||
self.c = Client()
|
||||
self.user_workouts = WorkoutFactory.create_batch(5, user=self.r)
|
||||
self.factory = RequestFactory()
|
||||
self.password = faker.word()
|
||||
self.u.set_password(self.password)
|
||||
self.u.save()
|
||||
|
||||
result = get_random_file(filename='rowers/tests/testdata/onwater2.csv')
|
||||
|
||||
self.wwater = WorkoutFactory(user=self.r,
|
||||
csvfilename=result['filename'],
|
||||
starttime=result['starttime'],
|
||||
startdatetime=result['startdatetime'],
|
||||
duration=result['duration'],
|
||||
distance=result['totaldist'],
|
||||
workouttype = 'water',
|
||||
)
|
||||
|
||||
result = get_random_file(filename='rowers/tests/testdata/quiske_in_stroke.csv')
|
||||
|
||||
self.winstroke = WorkoutFactory(user=self.r,
|
||||
csvfilename=result['filename'],
|
||||
starttime=result['starttime'],
|
||||
startdatetime=result['startdatetime'],
|
||||
duration=result['duration'],
|
||||
distance=result['totaldist'],
|
||||
workouttype = 'water',
|
||||
)
|
||||
|
||||
result = get_random_file(filename='rowers/tests/testdata/erg1.csv')
|
||||
|
||||
self.werg1 = WorkoutFactory(user=self.r,
|
||||
csvfilename=result['filename'],
|
||||
starttime=result['starttime'],
|
||||
startdatetime=result['startdatetime'],
|
||||
duration=result['duration'],
|
||||
distance=result['totaldist'],
|
||||
workouttype = 'rower',
|
||||
)
|
||||
|
||||
result = get_random_file(filename='rowers/tests/testdata/erg2.csv')
|
||||
|
||||
self.werg2 = WorkoutFactory(user=self.r,
|
||||
csvfilename=result['filename'],
|
||||
starttime=result['starttime'],
|
||||
startdatetime=result['startdatetime'],
|
||||
duration=result['duration'],
|
||||
distance=result['totaldist'],
|
||||
workouttype = 'rower',
|
||||
)
|
||||
|
||||
result = get_random_file(filename='rowers/tests/testdata/erg3.csv')
|
||||
|
||||
self.werg3 = WorkoutFactory(user=self.r,
|
||||
csvfilename=result['filename'],
|
||||
starttime=result['starttime'],
|
||||
startdatetime=result['startdatetime'],
|
||||
duration=result['duration'],
|
||||
distance=result['totaldist'],
|
||||
workouttype = 'rower',
|
||||
)
|
||||
|
||||
self.fav1 = FavoriteChart.objects.create(
|
||||
yparam1='hr',
|
||||
yparam2='spm',
|
||||
xparam='distance',
|
||||
workouttype='all',
|
||||
reststrokes=False,
|
||||
notes=faker.word(),
|
||||
user=self.r
|
||||
)
|
||||
|
||||
self.fav2 = FavoriteChart.objects.create(
|
||||
yparam1='power',
|
||||
yparam2='strokeenergy',
|
||||
xparam='distance',
|
||||
workouttype='all',
|
||||
reststrokes=False,
|
||||
notes=faker.word(),
|
||||
user=self.r
|
||||
)
|
||||
|
||||
def tearDown(self):
|
||||
pass
|
||||
|
||||
@patch('rowers.dataprep.create_engine')
|
||||
@patch('rowers.dataprep.getsmallrowdata_db')
|
||||
def test_flexchart_water(self, mocked_sqlalechemy, mocked_getsmallrowdata_db):
|
||||
login = self.c.login(username=self.u.username, password=self.password)
|
||||
self.assertTrue(login)
|
||||
|
||||
url = reverse('workout_flexchart3_view',kwargs={'id':self.wwater.id})
|
||||
|
||||
response = self.c.get(url)
|
||||
self.assertEqual(response.status_code,200)
|
||||
|
||||
# change chart
|
||||
form_data = {
|
||||
'xaxis':'time',
|
||||
'yaxis1':'hr',
|
||||
'yaxis2': 'spm'
|
||||
}
|
||||
|
||||
response = self.c.post(url,form_data)
|
||||
self.assertEqual(response.status_code,200)
|
||||
|
||||
url = reverse('workout_flexchart3_view',kwargs={
|
||||
'id':self.wwater.id,
|
||||
'xparam':'distance',
|
||||
'yparam1':'hr',
|
||||
'yparam2':'power'
|
||||
})
|
||||
|
||||
response = self.c.get(url)
|
||||
self.assertEqual(response.status_code,200)
|
||||
|
||||
form_data = {
|
||||
'workstrokesonlysave':True,
|
||||
'savefavorite':True
|
||||
}
|
||||
|
||||
response = self.c.post(url,form_data)
|
||||
self.assertEqual(response.status_code,200)
|
||||
|
||||
@patch('rowers.dataprep.create_engine')
|
||||
@patch('rowers.dataprep.getsmallrowdata_db')
|
||||
def test_flexchart_erg(self, mocked_sqlalechemy, mocked_getsmallrowdata_db):
|
||||
login = self.c.login(username=self.u.username, password=self.password)
|
||||
self.assertTrue(login)
|
||||
|
||||
url = reverse('workout_flexchart3_view',kwargs={'id':self.werg1.id})
|
||||
|
||||
response = self.c.get(url)
|
||||
self.assertEqual(response.status_code,200)
|
||||
|
||||
# change chart
|
||||
form_data = {
|
||||
'xaxis':'time',
|
||||
'yaxis1':'hr',
|
||||
'yaxis2': 'spm'
|
||||
}
|
||||
|
||||
response = self.c.post(url,form_data)
|
||||
self.assertEqual(response.status_code,200)
|
||||
|
||||
url = reverse('workout_flexchart3_view',kwargs={
|
||||
'id':self.werg1.id,
|
||||
'xparam':'distance',
|
||||
'yparam1':'hr',
|
||||
'yparam2':'power'
|
||||
})
|
||||
|
||||
response = self.c.get(url)
|
||||
self.assertEqual(response.status_code,200)
|
||||
|
||||
form_data = {
|
||||
'workstrokesonlysave':True,
|
||||
'savefavorite':True
|
||||
}
|
||||
|
||||
response = self.c.post(url,form_data)
|
||||
self.assertEqual(response.status_code,200)
|
||||
Reference in New Issue
Block a user