added first strava test
This commit is contained in:
1
rowers/testdata/stravaworkoutlist.txt
vendored
Normal file
1
rowers/testdata/stravaworkoutlist.txt
vendored
Normal file
File diff suppressed because one or more lines are too long
@@ -60,6 +60,7 @@ def mocked_requests(*args, **kwargs):
|
|||||||
c2strokedata = json.load(infile)
|
c2strokedata = json.load(infile)
|
||||||
|
|
||||||
c2workoutlist = json.load(open('rowers/testdata/c2workoutlist.txt'))
|
c2workoutlist = json.load(open('rowers/testdata/c2workoutlist.txt'))
|
||||||
|
stravaworkoutlist = json.load(open('rowers/testdata/stravaworkoutlist.txt'))
|
||||||
|
|
||||||
class MockResponse:
|
class MockResponse:
|
||||||
def __init__(self, json_data, status_code):
|
def __init__(self, json_data, status_code):
|
||||||
@@ -88,6 +89,7 @@ def mocked_requests(*args, **kwargs):
|
|||||||
return MockSession()
|
return MockSession()
|
||||||
|
|
||||||
c2tester = re.compile('.*?log\.concept2\.com')
|
c2tester = re.compile('.*?log\.concept2\.com')
|
||||||
|
stravatester = re.compile('.*?strava\.com')
|
||||||
|
|
||||||
c2importregex = '.*?concept2.com\/api\/users\/me\/results\/\d+'
|
c2importregex = '.*?concept2.com\/api\/users\/me\/results\/\d+'
|
||||||
c2importtester = re.compile(c2importregex)
|
c2importtester = re.compile(c2importregex)
|
||||||
@@ -98,6 +100,13 @@ def mocked_requests(*args, **kwargs):
|
|||||||
c2workoutlistregex = '.*?concept2\.com\/api\/users\/me\/results\?page=\d'
|
c2workoutlistregex = '.*?concept2\.com\/api\/users\/me\/results\?page=\d'
|
||||||
c2workoutlisttester = re.compile(c2workoutlistregex)
|
c2workoutlisttester = re.compile(c2workoutlistregex)
|
||||||
|
|
||||||
|
stravaworkoutlistregex = '.*?strava\.com\/api\/v3\/athlete\/activities'
|
||||||
|
stravaworkoutlisttester = re.compile(stravaworkoutlistregex)
|
||||||
|
|
||||||
|
if stravatester.match(args[0]):
|
||||||
|
if stravaworkoutlisttester.match(args[0]):
|
||||||
|
return MockResponse(stravaworkoutlist,200)
|
||||||
|
|
||||||
if c2tester.match(args[0]):
|
if c2tester.match(args[0]):
|
||||||
if c2strokestester.match(args[0]):
|
if c2strokestester.match(args[0]):
|
||||||
return MockResponse(c2strokedata,200)
|
return MockResponse(c2strokedata,200)
|
||||||
@@ -218,6 +227,32 @@ class C2Objects(DjangoTestCase):
|
|||||||
|
|
||||||
|
|
||||||
class StravaObjects(DjangoTestCase):
|
class StravaObjects(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.stravatoken = '12'
|
||||||
|
|
||||||
|
self.r.save()
|
||||||
|
self.c.login(username='john',password='koeinsloot')
|
||||||
|
|
||||||
|
@patch('rowers.stravastuff.requests.post', side_effects=mocked_requests)
|
||||||
|
def test_strava_list(self, mock_get):
|
||||||
|
response = self.c.get('/rowers/workout/stravaimport',follow=True)
|
||||||
|
|
||||||
|
self.assertEqual(response.status_code,200)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def test_strokedata(self):
|
def test_strokedata(self):
|
||||||
timejson = json.load(open('rowers/testdata/stravatimetestdata.txt','r'))
|
timejson = json.load(open('rowers/testdata/stravatimetestdata.txt','r'))
|
||||||
velojson = json.load(open('rowers/testdata/stravavelotestdata.txt','r'))
|
velojson = json.load(open('rowers/testdata/stravavelotestdata.txt','r'))
|
||||||
|
|||||||
Reference in New Issue
Block a user