Private
Public Access
1
0

first attempt at mocking otwcp

This commit is contained in:
Sander Roosendaal
2019-01-12 17:04:28 +01:00
parent 36349eede7
commit 7a815924f5
13 changed files with 13353 additions and 2 deletions

View File

@@ -26,6 +26,10 @@ 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
@@ -57,7 +61,83 @@ class SessionFactory(factory.DjangoModelFactory):
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_rankingpieces(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)
class CPChartTest(TestCase):
def setUp(self):
self.u = UserFactory()
@@ -102,7 +182,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
)