more coverage related
This commit is contained in:
@@ -817,7 +817,7 @@ def mocked_requests(*args, **kwargs):
|
||||
self.status_code = status_code
|
||||
self.ok = True
|
||||
|
||||
class MockOAuth1Session():
|
||||
class MockOAuth1Session:
|
||||
def __init__(self,*args, **kwargs):
|
||||
pass
|
||||
|
||||
@@ -851,18 +851,46 @@ def mocked_requests(*args, **kwargs):
|
||||
|
||||
return MockResponse(json_data,200)
|
||||
|
||||
|
||||
if 'garmin' in args:
|
||||
return MockOAuth1Session()
|
||||
|
||||
if 'url' in kwargs:
|
||||
if 'rp3' in kwargs['url']:
|
||||
args = [kwargs['url']]
|
||||
if "tofit" in kwargs['url']:
|
||||
args = [kwargs['url']]
|
||||
|
||||
if not args:
|
||||
return MockSession()
|
||||
|
||||
|
||||
if "tofit" in args[0]:
|
||||
jsonresponse = {
|
||||
'name': '',
|
||||
'sport': 'rowing',
|
||||
'filename': '/home/sander/python/rowsandall/media/630a9e78-6d34-4eb3-8d53-4c02b2e95fff.fit',
|
||||
'steps': [
|
||||
{
|
||||
'wkt_step_name': '0',
|
||||
'stepId': 0,
|
||||
'durationType': 'Distance',
|
||||
'durationValue': 100000,
|
||||
'intensity': 'Active'
|
||||
},
|
||||
{
|
||||
'wkt_step_name': '1',
|
||||
'stepId': 1,
|
||||
'durationType': 'RepeatUntilStepsCmplt',
|
||||
'targetValue': 4,
|
||||
'durationValue': 0
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
return MockResponse(jsonresponse,200)
|
||||
|
||||
|
||||
polartester = re.compile('.*?polaraccesslink\.com')
|
||||
c2tester = re.compile('.*?log\.concept2\.com')
|
||||
stravatester = re.compile('.*?strava\.com')
|
||||
@@ -1171,3 +1199,22 @@ class MockEmailMessage:
|
||||
|
||||
def send(self):
|
||||
return 1
|
||||
|
||||
class MockResponse:
|
||||
def __init__(self, json_data, status_code):
|
||||
self.json_data = json_data
|
||||
self.status_code = status_code
|
||||
self.ok = True
|
||||
|
||||
def json(self):
|
||||
return self.json_data
|
||||
|
||||
class MockOAuth1Session:
|
||||
def __init__(self,*args, **kwargs):
|
||||
pass
|
||||
|
||||
def get(*args,**kwargs):
|
||||
return MockStreamResponse('rowers/tests/testdata/3x250m.fit',200)
|
||||
|
||||
def post(*args, **kwargs):
|
||||
return MockResponse({},200)
|
||||
|
||||
@@ -8,12 +8,14 @@ from .statements import *
|
||||
nu = datetime.datetime.now()
|
||||
|
||||
from rowers.utils import allmonths,allsundays
|
||||
from rowers import garmin_stuff
|
||||
|
||||
import rowers.plannedsessions as plannedsessions
|
||||
from django.db import transaction
|
||||
|
||||
from rowers.views.workoutviews import plannedsession_compare_view
|
||||
from rowers.opaque import encoder
|
||||
from django.utils.crypto import get_random_string
|
||||
|
||||
@override_settings(TESTING=True)
|
||||
class TrainingPlanTest(TestCase):
|
||||
@@ -93,7 +95,7 @@ class TrainingPlanTest(TestCase):
|
||||
for url in urls:
|
||||
if 'macrocycle' in url and 'delete' not in url:
|
||||
macrourl = url
|
||||
print(macrourl)
|
||||
|
||||
response = self.c.get(macrourl)
|
||||
self.assertEqual(response.status_code,200)
|
||||
|
||||
@@ -121,7 +123,7 @@ class TrainingPlanTest(TestCase):
|
||||
|
||||
for url in urls:
|
||||
if 'planbymonths' in url:
|
||||
print(url)
|
||||
|
||||
response = self.c.get(url,follow=True)
|
||||
self.assertEqual(response.status_code,200)
|
||||
|
||||
@@ -1872,6 +1874,29 @@ description: ""
|
||||
response = self.c.post(urlshare,form_data)
|
||||
self.assertEqual(response.status_code,200)
|
||||
|
||||
key = ShareKey.objects.create(pk=get_random_string(40),
|
||||
expiration_seconds=60,
|
||||
location=url
|
||||
)
|
||||
key.save()
|
||||
|
||||
url = '/rowers/access/'+key.token
|
||||
|
||||
response = self.c.get(url,follow=True)
|
||||
self.assertEqual(response.status_code,200)
|
||||
|
||||
@patch('rowers.garmin_stuff.requests.post', side_effect=mocked_requests)
|
||||
@patch('rowers.utils.requests.post', side_effect=mocked_requests)
|
||||
@patch('rowers.garmin_stuff.OAuth1Session', side_effect=MockOAuth1Session)
|
||||
def test_plannedsession_steps(self,mockpost,mock_post,MockOAuth1Session):
|
||||
self.ps_trimp.interval_string = '4x1000m'
|
||||
self.ps_trimp.save()
|
||||
|
||||
stepsdict = self.ps_trimp.steps['steps']
|
||||
self.assertEqual(len(stepsdict),2)
|
||||
|
||||
response = garmin_stuff.ps_to_garmin(self.ps_trimp,self.r)
|
||||
self.assertEqual(response.status_code,200)
|
||||
|
||||
|
||||
def test_plannedsessions_dateform_view(self):
|
||||
|
||||
Reference in New Issue
Block a user