Private
Public Access
1
0

Merge branch 'feature/coverage' into develop

This commit is contained in:
Sander Roosendaal
2019-01-21 16:28:28 +01:00
14 changed files with 14522 additions and 2 deletions

View File

@@ -3,6 +3,134 @@ from statements import *
nu = datetime.datetime.now()
from rowers.tasks import handle_getagegrouprecords
from rowers.utils import calculate_age
import rowers.dataprep as dataprep
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 OTWCPChartTest(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')
r = self.u.rower
age = calculate_age(r.birthdate)
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()
self.lastdate = datetime.date(year=1970,month=1,day=1)
for filename in os.listdir(u'rowers/tests/testdata/otwcp'):
a2 = 'rowers/tests/testdata/otwcp/temp/'+filename
try:
copyfile(u'rowers/tests/testdata/otwcp/'+filename,a2)
row = rdata(a2)
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')
w = Workout.objects.create(name=faker.word(),
workouttype='water',
user = self.r,
starttime = workoutstarttime,
date = workoutdate,
duration = duration,
distance = totaldist,
csvfilename = a2,
rankingpiece = True)
w.save()
if row.rowdatetime.date() > self.lastdate:
self.lastdate = row.rowdatetime.date()
except:
pass
def tearDown(self):
for filename in os.listdir('rowers/tests/testdata/otwcp/temp'):
path = os.path.join('rowers/tests/testdata/otwcp/temp/',filename)
if not os.path.isdir(path):
try:
os.remove(path)
except (IOError,WindowsError):
pass
@patch('rowers.dataprep.getsmallrowdata_db',side_effect=mocked_cpraw)
@patch('rowers.dataprep.getcpdata_sql',side_effect=mocked_getcpdata_sql)
def test_otwrankingpieces(self, mocked_cpraw,mocked_getcpdata_sql):
workouts = Workout.objects.filter(workouttype='water',
rankingpiece=True,user=self.r)
delta, cpvalue, avgpower = dataprep.fetchcp(self.r,workouts)
@patch('rowers.dataprep.getsmallrowdata_db',side_effect=mocked_cpraw)
@patch('rowers.dataprep.getcpdata_sql',side_effect=mocked_getcpdata_sql)
def test_otwrankingpieces(self, mocked_cpraw,mocked_getcpdata_sql):
login = self.c.login(username=self.u.username,password=self.password)
self.assertTrue(login)
url = '/rowers/otw-bests/'
response = self.c.get(url)
self.assertEqual(response.status_code, 200)
class CPChartTest(TestCase):
def setUp(self):
self.u = UserFactory()
@@ -47,7 +175,7 @@ class CPChartTest(TestCase):
perf = CalcAgePerformance(
age = age,
duration = perfsdf.ix[i,'duration'],
power = perfsdf.ix[i,'power'],
power = perfsdf.ix[i,'power'],
sex = r.sex,
weightcategory = r.weightcategory
)
@@ -145,6 +273,15 @@ class CPChartTest(TestCase):
jsondf,distances,durations,age,r.sex,r.weightcategory)
self.assertEqual(result,1)
url = '/rowers/agegrouprecords/{sex}/{weightc}/2000m/'.format(
sex = r.sex,
weightc = r.weightcategory)
print url
response = self.c.get(url)
self.assertEqual(response.status_code,200)
@patch('rowers.dataprep.fetchcperg', side_effect = mocked_fetchcperg)