added a simple analysis test but should be altered
This commit is contained in:
@@ -33,6 +33,7 @@ from bs4 import BeautifulSoup
|
||||
from rowers.ownapistuff import *
|
||||
from rowers.views.apiviews import *
|
||||
from rowers.teams import add_member, add_coach
|
||||
from rowers.views.analysisviews import histodata
|
||||
|
||||
class TeamFactory(factory.DjangoModelFactory):
|
||||
class Meta:
|
||||
@@ -303,7 +304,97 @@ class StravaPrivacy(TestCase):
|
||||
w = ws[0]
|
||||
self.assertEqual(w.workoutsource,'strava')
|
||||
self.assertEqual(w.privacy,'hidden')
|
||||
|
||||
|
||||
|
||||
# test some analysis, should only use the workouts with workoutsource != strava
|
||||
@patch('rowers.dataprep.read_data', side_effect=mocked_read_data)
|
||||
def test_workouts_analysis(self, mocked_read_data):
|
||||
login = self.c.login(username=self.u.username, password=self.password)
|
||||
self.assertTrue(login)
|
||||
|
||||
url = '/rowers/history/'
|
||||
response = self.c.get(url)
|
||||
self.assertEqual(response.status_code,200)
|
||||
|
||||
url = '/rowers/history/data/'
|
||||
response = self.c.get(url)
|
||||
self.assertEqual(response.status_code,200)
|
||||
# response.json() has a key "script" with a javascript script
|
||||
# check if this is correct
|
||||
self.assertTrue('script' in response.json())
|
||||
|
||||
# now check histogram
|
||||
startdate = (self.user_workouts[0].startdatetime-datetime.timedelta(days=3)).date()
|
||||
enddate = (self.user_workouts[0].startdatetime+datetime.timedelta(days=3)).date()
|
||||
|
||||
# make sure the dates are not naive
|
||||
try:
|
||||
startdate = pytz.utc.localize(startdate)
|
||||
except (ValueError, AttributeError):
|
||||
pass
|
||||
try:
|
||||
enddate = pytz.utc.localize(enddate)
|
||||
except (ValueError, AttributeError):
|
||||
pass
|
||||
|
||||
form_data = {
|
||||
'function':'histo',
|
||||
'xparam':'hr',
|
||||
'plotfield':'spm',
|
||||
'yparam':'pace',
|
||||
'groupby':'spm',
|
||||
'palette':'monochrome_blue',
|
||||
'xaxis':'time',
|
||||
'yaxis1':'power',
|
||||
'yaxis2':'hr',
|
||||
'startdate':startdate,
|
||||
'enddate':enddate,
|
||||
'plottype':'scatter',
|
||||
'spmmin':15,
|
||||
'spmmax':55,
|
||||
'workmin':0,
|
||||
'workmax':1500,
|
||||
'includereststrokes':False,
|
||||
'modality':'all',
|
||||
'waterboattype':['1x','2x','4x'],
|
||||
'userid':self.u.id,
|
||||
'workouts':[w.id for w in Workout.objects.filter(user=self.r)],
|
||||
}
|
||||
|
||||
form = AnalysisChoiceForm(form_data)
|
||||
optionsform = AnalysisOptionsForm(form_data)
|
||||
dateform = DateRangeForm(form_data)
|
||||
|
||||
result = form.is_valid()
|
||||
if not result:
|
||||
print(form.errors)
|
||||
|
||||
self.assertTrue(form.is_valid())
|
||||
self.assertTrue(optionsform.is_valid())
|
||||
self.assertTrue(dateform.is_valid())
|
||||
|
||||
response = self.c.post('/rowers/user-analysis-select/',form_data)
|
||||
|
||||
self.assertEqual(response.status_code,200)
|
||||
|
||||
# get data from histodata function
|
||||
ws = Workout.objects.filter(user=self.r)
|
||||
|
||||
script, div = histodata(ws,form_data)
|
||||
# script has a line starting with 'data = [ ... ]'
|
||||
# we need to get that line
|
||||
data = [line for line in script.split('\n') if line.startswith('data = [')][0]
|
||||
# the line should be a list of float values
|
||||
self.assertTrue(data.startswith('data = ['))
|
||||
self.assertTrue(data.endswith(']'))
|
||||
# count the number of commas between the brackets
|
||||
self.assertEqual(data.count(','),1377)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# try and fail to submit a workout with workoutsource = strava to a challenge
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user