adding rp3 sync to tests
This commit is contained in:
@@ -98,7 +98,6 @@ def mocked_myqueue(*args, **kwargs):
|
||||
return Job()
|
||||
|
||||
def mock_c2open(*args, **kwargs):
|
||||
print('mock')
|
||||
return('aap')
|
||||
|
||||
def mocked_session(*args, **kwargs):
|
||||
@@ -123,6 +122,16 @@ def mocked_session(*args, **kwargs):
|
||||
def json(self):
|
||||
return self.json_data
|
||||
|
||||
class MockContentResponse:
|
||||
def __init__(self,filename,status_code):
|
||||
with open(filename,'rb') as f:
|
||||
s = f.read()
|
||||
self.content = s
|
||||
self.status_code = status_code
|
||||
self.ok = True
|
||||
|
||||
|
||||
|
||||
return MockEngine()
|
||||
|
||||
def mocked_sqlalchemy(*args, **kwargs):
|
||||
@@ -697,6 +706,11 @@ def mocked_requests(*args, **kwargs):
|
||||
with open('rowers/tests/testdata/nk_list.json','r') as infile:
|
||||
nkworkoutlist = json.load(infile)
|
||||
|
||||
with open('rowers/tests/testdata/rp3_list.json','r') as infile:
|
||||
rp3workoutlist = json.load(infile)
|
||||
|
||||
rp3linkready = {'data': {'download': {'id': 591621, 'status': 'ready', 'link': 'https://rp3rowing-app.com/api/workouts/591621/download?type=csv'}}}
|
||||
|
||||
with open('rowers/tests/testdata/example-session-strokes-with-impeller-data.json','r') as infile:
|
||||
nkimpellerstrokedata = json.load(infile)
|
||||
|
||||
@@ -781,6 +795,15 @@ def mocked_requests(*args, **kwargs):
|
||||
def json(self):
|
||||
return self.json_data
|
||||
|
||||
class MockContentResponse:
|
||||
def __init__(self,filename,status_code):
|
||||
with open(filename,'rb') as f:
|
||||
s = f.read()
|
||||
self.content = s
|
||||
self.status_code = status_code
|
||||
self.ok = True
|
||||
|
||||
|
||||
|
||||
class MockHeaderResponse:
|
||||
def __init__(self, header_data, status_code):
|
||||
@@ -832,6 +855,9 @@ def mocked_requests(*args, **kwargs):
|
||||
if 'garmin' in args:
|
||||
return MockOAuth1Session()
|
||||
|
||||
if 'url' in kwargs:
|
||||
if 'rp3' in kwargs['url']:
|
||||
args = [kwargs['url']]
|
||||
|
||||
if not args:
|
||||
return MockSession()
|
||||
@@ -845,6 +871,7 @@ def mocked_requests(*args, **kwargs):
|
||||
uatester = re.compile('.*?mapmyfitness\.com')
|
||||
tptester = re.compile('.*?trainingpeaks\.com')
|
||||
nktester = re.compile('.*?nkrowlink\.com')
|
||||
rp3tester = re.compile('.*?rp3rowing-app\.com')
|
||||
garmintester = re.compile('.*?garmin\.com')
|
||||
|
||||
c2importregex = '.*?concept2.com\/api\/users\/me\/results\/\d+'
|
||||
@@ -865,6 +892,8 @@ def mocked_requests(*args, **kwargs):
|
||||
nkstrokesregex = '.*?nkrowlink\.com\/api\/v1\/sessions\/strokes'
|
||||
nkstrokestester = re.compile(nkstrokesregex)
|
||||
|
||||
rp3graphregex = '.*?rp3rowing-app\.com\/graphql'
|
||||
rp3graphtester = re.compile(rp3graphregex)
|
||||
|
||||
stravaathleteregex = '.*?strava\.com\/api\/v3\/athlete$'
|
||||
stravaathletetester = re.compile(stravaathleteregex)
|
||||
@@ -1052,6 +1081,33 @@ def mocked_requests(*args, **kwargs):
|
||||
return MockResponse(nkimpellerworkoutlist,200)
|
||||
return MockResponse(nkworkoutlist,200)
|
||||
|
||||
if rp3tester.match(args[0]):
|
||||
if 'token' in args[0]:
|
||||
json_data = {
|
||||
'access_token': 'TA3n1vrNjuQJWw0TdCDHnjSmrjIPULhTlejMIWqq',
|
||||
'expires_in': 604800,
|
||||
'refresh_token': 'jHJhFzCfOOKB8oyiayubhLAlxaMkG3ruC1E8YxaR'
|
||||
}
|
||||
return MockResponse(json_data,200)
|
||||
|
||||
if 'api' in args[0]:
|
||||
if '591621' in args[0]:
|
||||
return MockContentResponse('rowers/tests/testdata/rp3content.csv',200)
|
||||
|
||||
|
||||
if rp3graphtester.match(args[0]):
|
||||
if 'json' in kwargs:
|
||||
try:
|
||||
query = kwargs['json']['query']
|
||||
if 'download' in query:
|
||||
return MockResponse(rp3linkready,200)
|
||||
except KeyError:
|
||||
pass
|
||||
json_data = rp3workoutlist
|
||||
return MockResponse(json_data,200)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if stravatester.match(args[0]):
|
||||
|
||||
Reference in New Issue
Block a user