testing erg ranking view
This commit is contained in:
245
rowers/tests/test_cpchart.py
Normal file
245
rowers/tests/test_cpchart.py
Normal file
@@ -0,0 +1,245 @@
|
||||
|
||||
from statements import *
|
||||
|
||||
filename = 'rowers/tests/testdata/testdata.csv'
|
||||
|
||||
row = rdata(filename)
|
||||
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)
|
||||
duration = datetime.time(hour=hours,minute=minutes,second=seconds)
|
||||
|
||||
workoutdate = row.rowdatetime.strftime('%Y-%m-%d')
|
||||
workoutstarttime = row.rowdatetime.strftime('%H:%M:%S')
|
||||
|
||||
nu = datetime.datetime.now()
|
||||
|
||||
from rowers.tasks import handle_getagegrouprecords
|
||||
|
||||
from rowers.utils import calculate_age
|
||||
|
||||
class UserFactory(factory.DjangoModelFactory):
|
||||
class Meta:
|
||||
model = User
|
||||
|
||||
email = faker.email()
|
||||
username = faker.profile()['username']
|
||||
|
||||
first_name = faker.name().split(' ')[0]
|
||||
last_name = faker.name().split(' ')[0]
|
||||
|
||||
class WorkoutFactory(factory.DjangoModelFactory):
|
||||
class Meta:
|
||||
model = Workout
|
||||
|
||||
name = factory.LazyAttribute(lambda _: faker.word())
|
||||
notes = faker.text()
|
||||
startdatetime = row.rowdatetime
|
||||
starttime = workoutstarttime
|
||||
workouttype='water'
|
||||
date=timezone.now().date()
|
||||
duration=duration
|
||||
distance=totaldist
|
||||
csvfilename=filename
|
||||
rankingpiece = False
|
||||
|
||||
class SessionFactory(factory.DjangoModelFactory):
|
||||
class Meta:
|
||||
model = PlannedSession
|
||||
|
||||
name = factory.LazyAttribute(lambda _: faker.word())
|
||||
comment = faker.text()
|
||||
|
||||
class CPChartTest(TestCase):
|
||||
def setUp(self):
|
||||
self.u = UserFactory()
|
||||
|
||||
self.r = Rower.objects.create(user=self.u,
|
||||
birthdate=faker.profile()['birthdate'],
|
||||
gdproptin=True,sex='male',
|
||||
weightcategory='hwt',
|
||||
gdproptindate=timezone.now(),
|
||||
rowerplan='coach')
|
||||
|
||||
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()
|
||||
|
||||
recordsdf = pd.read_csv('rowers/tests/worldrecords.csv',encoding='utf-8')
|
||||
|
||||
for i in range(len(recordsdf)):
|
||||
record = C2WorldClassAgePerformance(
|
||||
name = recordsdf.ix[i,'name'],
|
||||
age = recordsdf.ix[i,'age'],
|
||||
distance = recordsdf.ix[i,'distance'],
|
||||
duration = recordsdf.ix[i,'duration'],
|
||||
power = recordsdf.ix[i,'power'],
|
||||
season = recordsdf.ix[i,'season'],
|
||||
sex = recordsdf.ix[i,'sex'],
|
||||
weightcategory = recordsdf.ix[i,'weightcategory'],
|
||||
)
|
||||
|
||||
record.save()
|
||||
|
||||
def test_analytics_page(self):
|
||||
login = self.c.login(username=self.u.username,password=self.password)
|
||||
self.assertTrue(login)
|
||||
|
||||
url = '/rowers/analysis/'
|
||||
|
||||
response = self.c.get(url)
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
@patch('rowers.dataprep.create_engine')
|
||||
def test_addmanual(self, mocked_sqlalchemy):
|
||||
login = self.c.login(username=self.u.username,password=self.password)
|
||||
self.assertTrue(login)
|
||||
|
||||
|
||||
form_data = {
|
||||
'name': faker.word(),
|
||||
'date': nu.date(),
|
||||
'starttime': '10:01:43',
|
||||
'timezone': 'UTC',
|
||||
'duration': '00:02:00.0',
|
||||
'distance': 500,
|
||||
'workouttype': 'rower',
|
||||
'boattype': '1x',
|
||||
'weightcategory': 'hwt',
|
||||
'adaptiveclass': 'None',
|
||||
'notes': faker.text(),
|
||||
'rankingpiece': True,
|
||||
'duplicate': False,
|
||||
'avghr': '160',
|
||||
'avgpwr': 0,
|
||||
'avgspm': 40,
|
||||
}
|
||||
|
||||
form = MetricsForm(form_data)
|
||||
self.assertTrue(form.is_valid)
|
||||
|
||||
form = WorkoutForm(form_data)
|
||||
self.assertTrue(form.is_valid)
|
||||
|
||||
|
||||
url = '/rowers/workout/addmanual/'
|
||||
response = self.c.get(url)
|
||||
|
||||
self.assertEqual(response.status_code,200)
|
||||
|
||||
response = self.c.post(url, form_data, follow=True)
|
||||
self.assertEqual(response.status_code,200)
|
||||
|
||||
workout_expected_id = 6
|
||||
|
||||
self.assertRedirects(response,
|
||||
expected_url='/rowers/workout/{id}/edit/'.format(
|
||||
id=workout_expected_id),
|
||||
status_code=302,target_status_code=200)
|
||||
|
||||
# add some tests of complex form data (no hr, no spm, zero spm, etc)
|
||||
|
||||
@patch('rowers.dataprepnodjango.create_engine')
|
||||
def test_agerecords(self, mock_sqlalchemy):
|
||||
# update_records(url='rowers/tests/c2worldrecords.html',verbose=False)
|
||||
|
||||
r = self.u.rower
|
||||
age = calculate_age(r.birthdate)
|
||||
|
||||
wcdurations = []
|
||||
wcpower = []
|
||||
durations = [1,4,30,60]
|
||||
distances = [100,500,1000,2000,5000,6000,10000,21097,42195]
|
||||
|
||||
df = pd.DataFrame(
|
||||
list(
|
||||
C2WorldClassAgePerformance.objects.filter(
|
||||
sex=r.sex,
|
||||
weightcategory=r.weightcategory
|
||||
).values()
|
||||
)
|
||||
)
|
||||
|
||||
jsondf = df.to_json()
|
||||
|
||||
result = handle_getagegrouprecords(
|
||||
jsondf,distances,durations,age,r.sex,r.weightcategory)
|
||||
|
||||
self.assertEqual(result,1)
|
||||
|
||||
|
||||
@patch('rowers.dataprep.fetchcperg')
|
||||
@patch('rowers.dataprep.create_engine')
|
||||
def test_rankingpieces(self, mocked_fetchcperg, mocked_sqlalchemy):
|
||||
url = '/rowers/ote-bests2/'
|
||||
|
||||
login = self.c.login(username=self.u.username,password=self.password)
|
||||
self.assertTrue(login)
|
||||
|
||||
# update_records(url='rowers/tests/c2worldrecords.html',verbose=False)
|
||||
|
||||
form_data = {
|
||||
'name': faker.word(),
|
||||
'date': nu.date(),
|
||||
'timezone': 'UTC',
|
||||
'duration': '00:02:00.0',
|
||||
'starttime': '10:01:43',
|
||||
'distance': 500,
|
||||
'workouttype': 'rower',
|
||||
'boattype': '1x',
|
||||
'weightcategory': 'hwt',
|
||||
'adaptiveclass': 'None',
|
||||
'notes': faker.text(),
|
||||
'rankingpiece': True,
|
||||
'duplicate': False,
|
||||
'avghr': '160',
|
||||
'avgpwr': 0,
|
||||
'avgspm': 40,
|
||||
}
|
||||
|
||||
url2 = '/rowers/workout/addmanual/'
|
||||
|
||||
response = self.c.post(url2, form_data, follow=True)
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
form_data['distance'] = 100
|
||||
form_data['duration'] = '00:00:18.5'
|
||||
|
||||
response = self.c.post(url2, form_data, follow=True)
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
form_data['distance'] = 2000
|
||||
form_data['duration'] = '00:06:56.5'
|
||||
response = self.c.post(url2, form_data, follow=True)
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
form_data['distance'] = 5000
|
||||
form_data['duration'] = '00:20:48.0'
|
||||
response = self.c.post(url2, form_data, follow=True)
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
form_data['distance'] = 6000
|
||||
form_data['duration'] = '00:22:17.6'
|
||||
response = self.c.post(url2, form_data, follow=True)
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
form_data['distance'] = 10000
|
||||
form_data['duration'] = '00:38:16.5'
|
||||
response = self.c.post(url2, form_data, follow=True)
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
response = self.c.get(url)
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user