Private
Public Access
1
0

next step polar

This commit is contained in:
Sander Roosendaal
2022-01-21 15:41:00 +01:00
parent f9dbdfefca
commit ae6e2f55b0
5 changed files with 131 additions and 45 deletions

View File

@@ -768,6 +768,25 @@ def mocked_requests(*args, **kwargs):
]
}
polar_user_data = {
"polar-user-id": 475,
"member-id": "i09u9ujj",
"registration-date": "2011-10-14T12:50:37.000Z",
"first-name": "Eka",
"last-name": "Toka",
"birthdate": "1985-09-06",
"gender": "MALE",
"weight": 66,
"height": 170,
"field": [
{
"value": "2",
"index": 0,
"name": "number-of-children"
}
]
}
polar_exercise_dict = {
"id": 1937529874,
"upload-time": "2008-10-13T10:40:02Z",
@@ -1042,6 +1061,9 @@ def mocked_requests(*args, **kwargs):
polartcxregex = r'.*?polaraccesslink\.com\/.*\/(\d+)\/tcx'
polartcxtester = re.compile(polartcxregex)
polaruserregex = r'.*?polaraccesslink\.com\/.*\/users$'
polarusertester = re.compile(polaruserregex)
polarnotificationregex = r'.*polaraccesslink\.com\/.*\/notifications'
polarnotificationtester = re.compile(polarnotificationregex)
@@ -1142,7 +1164,7 @@ def mocked_requests(*args, **kwargs):
json_data = {
'access_token':'aap',
'expires_in':31535999,
'x_user_id':1,
'x_user_id':475,
}
return MockResponse(json_data,200)
@@ -1163,6 +1185,9 @@ def mocked_requests(*args, **kwargs):
]
}
return MockResponse(json_data,200)
elif polarusertester.match(args[0]):
json_data = polar_user_data
return MockResponse(json_data,200)
elif polartcxtester.match(args[0]):
filename = 'rowers/tests/testdata/polar_response.tcx'
return MockContentResponse(filename,200)

View File

@@ -776,6 +776,7 @@ class PolarObjects(DjangoTestCase):
self.r.polarrefreshtoken = '123'
self.r.polaruserid = 475
self.r.rowerplan = 'pro'
self.r.polar_auto_import = True
self.r.polartokenexpirydate = arrow.get(datetime.datetime.now()+datetime.timedelta(days=100)).datetime
@@ -840,6 +841,17 @@ class PolarObjects(DjangoTestCase):
response = polarstuff.get_all_new_workouts(data)
self.assertEqual(response,1)
@patch('rowers.polarstuff.requests.post', side_effect=mocked_requests)
@patch('rowers.polarstuff.requests.get', side_effect=mocked_requests)
def test_polar_get_workout(self, mock_get, mock_post):
transaction_id = 240522162
id = 1937529874
response = polarstuff.get_polar_workout(self.u, id, transaction_id)
self.assertEqual(len(response),14836)
#@pytest.mark.django_db
@override_settings(TESTING=True)
class RP3Objects(DjangoTestCase):

BIN
rowers/tests/testdata/testdata.tcx.gz vendored Normal file

Binary file not shown.