Private
Public Access
1
0

passes tests but doesn't clean up all temp

This commit is contained in:
Sander Roosendaal
2019-01-15 10:38:18 +01:00
parent 7c02366cad
commit 9cc80b9ce2
23 changed files with 777 additions and 702 deletions

View File

@@ -58,12 +58,83 @@ from django_mailbox.models import Mailbox,MessageAttachment,Message
from rowers.tests.mocks import *
from nose.tools import assert_raises
from rowers.models import *
from rowers.forms import *
from rowers.tests.mocks import *
import factory
from faker import Factory
from uuid import uuid4
faker = Factory.create()
from rowers.utils import calculate_age
from rowers.tasks import handle_getagegrouprecords
def get_random_file(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')
extension = filename[-3:]
newfilename = 'rowers/tests/testdata/temp/'+uuid4().hex[:16]+'.'+extension
copyfile(filename,newfilename)
thedict = {
'row':row,
'filename':newfilename,
'startdatetime': row.rowdatetime,
'starttime': workoutstarttime,
'date': workoutdate,
'duration':duration,
'totaldist':totaldist,
}
return thedict
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 = get_random_file()['startdatetime']
starttime = get_random_file()['starttime']
workouttype='water'
date=timezone.now().date()
duration=get_random_file()['duration']
distance=get_random_file()['totaldist']
csvfilename=get_random_file()['filename']
class SessionFactory(factory.DjangoModelFactory):
class Meta:
model = PlannedSession
name = factory.LazyAttribute(lambda _: faker.word())
comment = faker.text()