Private
Public Access
1
0

adding tests to increase coverage

This commit is contained in:
Sander Roosendaal
2019-01-02 21:54:25 +01:00
parent 128609968a
commit 76d2325797
10 changed files with 3224 additions and 16 deletions

View File

@@ -44,7 +44,7 @@ from rowers.dataprep import delete_strokedata
from redis import StrictRedis
redis_connection = StrictRedis()
@pytest.mark.django_db
#@pytest.mark.django_db
class DjangoTestCase(TestCase, MockTestCase):
def _pre_setup(self):
MockTestCase.setUp(self)
@@ -355,6 +355,7 @@ def mocked_requests(*args, **kwargs):
elif c2workoutlisttester.match(args[0]):
return MockResponse(c2workoutlist,200)
elif 'access_token' in args[0]:
print 'aap'
json_data = {
'access_token': 'TA3n1vrNjuQJWw0TdCDHnjSmrjIPULhTlejMIWqq',
'expires_in': 604800,
@@ -380,7 +381,7 @@ def mocked_requests(*args, **kwargs):
return MockResponse(None,404)
@pytest.mark.django_db
#@pytest.mark.django_db
class C2Objects(DjangoTestCase):
def setUp(self):
self.c = Client()
@@ -512,8 +513,82 @@ class C2Objects(DjangoTestCase):
res = add_workout_from_strokedata(self.u,1,data,strokedata,source='c2')
class C2ObjectsTokenExpired(DjangoTestCase):
def setUp(self):
self.c = Client()
self.u = User.objects.create_user('john',
'sander@ds.ds',
'koeinsloot')
self.u.first_name = 'John'
self.u.last_name = 'Sander'
self.u.save()
self.r = Rower.objects.create(user=self.u,gdproptin=True,
gdproptindate=timezone.now()
)
self.r.c2token = '12'
self.r.c2refreshtoken = 'ab'
self.r.tokenexpirydate = datetime.datetime.now()-datetime.timedelta(days=1)
self.r.save()
self.c.login(username='john',password='koeinsloot')
self.nu = datetime.datetime.now()
@pytest.mark.django_db
filename = 'rowers/tests/testdata/testdata.csv'
rr = rrower(hrmax=self.r.max,hrut2=self.r.ut2,
hrut1=self.r.ut1,hrat=self.r.at,
hrtr=self.r.tr,hran=self.r.an,ftp=self.r.ftp)
row = rdata(filename,rower=rr)
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)
workoutdate = row.rowdatetime.strftime('%Y-%m-%d')
workoutstarttime = row.rowdatetime.strftime('%H:%M:%S')
self.w = Workout.objects.create(
name='testworkout',workouttype='water',
user=self.r,date=self.nu.strftime('%Y-%m-%d'),
starttime=workoutstarttime,
startdatetime=row.rowdatetime,
duration=duration,distance=totaldist,
csvfilename=filename
)
@patch('rowers.c2stuff.requests.post', side_effect=mocked_requests)
@patch('rowers.c2stuff.requests.get', side_effect=mocked_requests)
def test_c2_list(self, mock_get, mock_post):
response = self.c.get('/rowers/workout/c2list',follow=True)
self.assertEqual(response.status_code,200)
@patch('rowers.c2stuff.requests.get', side_effect=mocked_requests)
def test_c2_import(self, mock_get):
response = self.c.get('/rowers/workout/c2import/12/',follow=True)
self.assertRedirects(response,
expected_url='/rowers/workout/2/edit',
status_code=302,target_status_code=200)
self.assertEqual(response.status_code, 200)
#@pytest.mark.django_db
class StravaObjects(DjangoTestCase):
def setUp(self):
self.c = Client()
@@ -552,7 +627,7 @@ class StravaObjects(DjangoTestCase):
@pytest.mark.django_db
#@pytest.mark.django_db
class STObjects(DjangoTestCase):
def setUp(self):
self.c = Client()
@@ -670,7 +745,7 @@ class STObjects(DjangoTestCase):
res = add_workout_from_data(self.u,1,data,data)
@pytest.mark.django_db
#@pytest.mark.django_db
class RunKeeperObjects(DjangoTestCase):
def setUp(self):
self.c = Client()
@@ -762,7 +837,7 @@ class RunKeeperObjects(DjangoTestCase):
@pytest.mark.django_db
#@pytest.mark.django_db
class UAObjects(DjangoTestCase):
def setUp(self):
self.c = Client()
@@ -863,7 +938,7 @@ class UAObjects(DjangoTestCase):
self.assertEqual(response.status_code, 200)
@pytest.mark.django_db
#@pytest.mark.django_db
class TPObjects(DjangoTestCase):
def setUp(self):
self.c = Client()
@@ -949,7 +1024,7 @@ class TPObjects(DjangoTestCase):
@pytest.mark.django_db
#@pytest.mark.django_db
class TestErrorPages(TestCase):
def test_error_handlers(self):
@@ -964,7 +1039,7 @@ class TestErrorPages(TestCase):
self.assertEqual(response.status_code, 500)
self.assertIn('500 Internal Server Error', unicode(response))
@pytest.mark.django_db
#@pytest.mark.django_db
class NewUserRegistrationTest(TestCase):
def setUp(self):
self.c = Client()
@@ -997,6 +1072,7 @@ class NewUserRegistrationTest(TestCase):
from django_mailbox.models import Mailbox,MessageAttachment,Message
#@pytest.mark.django_db
class AutoExportTests(TestCase):
def setUp(self):
redis_connection.publish('tasks','KILL')
@@ -1053,6 +1129,7 @@ boattype: 2x
call_command('processemail', stdout=out, testing=True)
self.assertIn('Successfully processed email attachments',out.getvalue())
#@pytest.mark.django_db
class UploadTests(TestCase):
def setUp(self):
redis_connection.publish('tasks','KILL')
@@ -1096,6 +1173,7 @@ workout run
w = Workout.objects.get(id=1)
self.assertEqual(w.workouttype,'Run')
#@pytest.mark.django_db
class EmailTests(TestCase):
def setUp(self):
redis_connection.publish('tasks','KILL')
@@ -1157,6 +1235,7 @@ workout water
self.assertIn('Successfully processed email attachments',out.getvalue())
#@pytest.mark.django_db
class WorkoutTests(TestCase):
def setUp(self):
redis_connection.publish('tasks','KILL')
@@ -1176,6 +1255,7 @@ class WorkoutTests(TestCase):
def test_checkworkoutuser(self):
self.assertEqual(checkworkoutuser(self.u,self.w),True)
#@pytest.mark.django_db
class C2Tests(TestCase):
def setUp(self):
redis_connection.publish('tasks','KILL')
@@ -1196,6 +1276,7 @@ class C2Tests(TestCase):
# should raise NoTokenError
self.assertRaises(NoTokenError)
#@pytest.mark.django_db
class DataTest(TestCase):
def setUp(self):
redis_connection.publish('tasks','KILL')
@@ -1383,6 +1464,7 @@ class DataTest(TestCase):
#@pytest.mark.django_db
class ViewTest(TestCase):
def setUp(self):
redis_connection.publish('tasks','KILL')
@@ -2143,6 +2225,7 @@ class ViewTest(TestCase):
# f_to_be_deleted = w.csvfilename
# os.remove(f_to_be_deleted+'.gz')
#@pytest.mark.django_db
class URLTests(TestCase):
def setUp(self):
redis_connection.publish('tasks','KILL')
@@ -2389,6 +2472,7 @@ class URLTests(TestCase):
msg=url+' response status code not 200')
#@pytest.mark.django_db
class subroutinetests(TestCase):
def setUp(self):
redis_connection.publish('tasks','KILL')
@@ -2414,6 +2498,7 @@ class subroutinetests(TestCase):
#@pytest.mark.django_db
class PlotTests(TestCase):
def setUp(self):
redis_connection.publish('tasks','KILL')