nk regressions
This commit is contained in:
@@ -52,6 +52,8 @@ class EmailUpload(TestCase):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@patch('rowers.dataprep.create_engine')
|
@patch('rowers.dataprep.create_engine')
|
||||||
@patch('rowers.dataprep.getsmallrowdata_db',side_effect=mocked_getsmallrowdata_db)
|
@patch('rowers.dataprep.getsmallrowdata_db',side_effect=mocked_getsmallrowdata_db)
|
||||||
def test_uploadapi(self,mocked_sqlalchemy,mocked_getsmallrowdata_db):
|
def test_uploadapi(self,mocked_sqlalchemy,mocked_getsmallrowdata_db):
|
||||||
@@ -105,12 +107,41 @@ class EmailUpload(TestCase):
|
|||||||
self.assertEqual(response.status_code,400)
|
self.assertEqual(response.status_code,400)
|
||||||
|
|
||||||
|
|
||||||
|
@patch('rowers.dataprep.create_engine')
|
||||||
|
@patch('rowers.dataprep.getsmallrowdata_db',side_effect=mocked_getsmallrowdata_db)
|
||||||
|
def test_uploadapi2(self,mocked_sqlalchemy,mocked_getsmallrowdata_db):
|
||||||
|
form_data = {"secret": settings.UPLOAD_SERVICE_SECRET,
|
||||||
|
"user": 1,
|
||||||
|
"file": 'media/mailbox_attachments/colin3.csv',
|
||||||
|
"title": "JustGo-17256M",
|
||||||
|
"workouttype": "water",
|
||||||
|
"boattype": "1x",
|
||||||
|
"nkid": 1206081,
|
||||||
|
"inboard": 0.86,
|
||||||
|
"oarlength": 2.84,
|
||||||
|
"summary": "Workout Summary - JustGo-17256M\n--|Total|--Total---|--Avg--|-Avg-|-Avg--|-Avg-|-Max-|-Avg\n--|Dist-|--Time----|-Pace--|-Pwr-|-SPM--|-HR--|-HR--|-DPS\n--|17256|01:29:09.0|02:35.2|100.9| 16.5 |125.0|138.0|12.4\nWorkout Details\n#-|SDist|-Split-|-SPace-|-Pwr-|-SPM--|-AvgHR-|DPS-\n01|17256|29:09.0|02:35.2| 100 | 16.5 | 125.0 |12.4\n",
|
||||||
|
"oarlockfirmware": "001.01",
|
||||||
|
"elapsedTime": 5349.0,
|
||||||
|
"totalDistance": 17256.13,
|
||||||
|
"useImpeller": False,
|
||||||
|
"seatNumber": 1
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
url = reverse('workout_upload_api')
|
||||||
|
response = self.c.post(url,json.dumps(form_data),HTTP_HOST='127.0.0.1:4533',
|
||||||
|
content_type='application/json')
|
||||||
|
self.assertEqual(response.status_code,200)
|
||||||
|
|
||||||
|
# should also test if workout is created
|
||||||
|
w = Workout.objects.get(id=1)
|
||||||
|
self.assertEqual(len(w.summary),324)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@patch('rowers.dataprep.create_engine')
|
@patch('rowers.dataprep.create_engine')
|
||||||
@patch('rowers.dataprep.getsmallrowdata_db',side_effect=mocked_getsmallrowdata_db)
|
@patch('rowers.dataprep.getsmallrowdata_db',side_effect=mocked_getsmallrowdata_db)
|
||||||
def test_uploadapi2(self,mocked_sqlalchemy,mocked_getsmallrowdata_db):
|
def test_uploadapi3(self,mocked_sqlalchemy,mocked_getsmallrowdata_db):
|
||||||
with transaction.atomic():
|
with transaction.atomic():
|
||||||
form_data = {
|
form_data = {
|
||||||
'title': 'test',
|
'title': 'test',
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ from rowers.integrations import *
|
|||||||
from django.db import transaction
|
from django.db import transaction
|
||||||
import rowers.garmin_stuff as gs
|
import rowers.garmin_stuff as gs
|
||||||
import rowers.integrations.strava as strava
|
import rowers.integrations.strava as strava
|
||||||
|
from rowers.nkimportutils import *
|
||||||
|
|
||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
@override_settings(TESTING=True)
|
@override_settings(TESTING=True)
|
||||||
@@ -718,6 +719,52 @@ class NKObjects(DjangoTestCase):
|
|||||||
csvfilename=filename
|
csvfilename=filename
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@patch('rowers.dataprep.create_engine')
|
||||||
|
@patch('rowers.dataprep.getsmallrowdata_db',side_effect=mocked_getsmallrowdata_db)
|
||||||
|
def test_nk_intervals(self,mocked_sqlalchemy,mocked_getsmallrowdata_db):
|
||||||
|
with open('rowers/tests/testdata/carlos_workout.json','r') as f:
|
||||||
|
workoutdata = json.load(f)
|
||||||
|
with open('rowers/tests/testdata/carlos_strokes.json','r') as f:
|
||||||
|
strokedata = json.load(f)
|
||||||
|
|
||||||
|
df = strokeDataToDf(strokedata, seatIndex=1)
|
||||||
|
csvfilename = 'media/test_nk.csv.gz'
|
||||||
|
df.to_csv(csvfilename, index_label='index',compression='gzip')
|
||||||
|
|
||||||
|
summary = get_nk_allstats(workoutdata, df)
|
||||||
|
self.assertEqual(len(summary),324)
|
||||||
|
|
||||||
|
form_data = {"secret": settings.UPLOAD_SERVICE_SECRET,
|
||||||
|
"user": 1,
|
||||||
|
"file": csvfilename,
|
||||||
|
"title": "JustGo-17256M",
|
||||||
|
"workouttype": "water",
|
||||||
|
"boattype": "1x",
|
||||||
|
"nkid": 1206081,
|
||||||
|
"inboard": 0.86,
|
||||||
|
"oarlength": 2.84,
|
||||||
|
"summary": summary,
|
||||||
|
"oarlockfirmware": "001.01",
|
||||||
|
"elapsedTime": 5349.0,
|
||||||
|
"totalDistance": 17256.13,
|
||||||
|
"useImpeller": False,
|
||||||
|
"seatNumber": 1
|
||||||
|
}
|
||||||
|
|
||||||
|
url = reverse('workout_upload_api')
|
||||||
|
response = self.c.post(url,json.dumps(form_data),HTTP_HOST='127.0.0.1:4533',
|
||||||
|
content_type='application/json')
|
||||||
|
self.assertEqual(response.status_code,200)
|
||||||
|
|
||||||
|
id = int(response.json()['id'])
|
||||||
|
|
||||||
|
# should also test if workout is created
|
||||||
|
w = Workout.objects.get(id=id)
|
||||||
|
|
||||||
|
self.assertEqual(len(w.summary),324)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@patch('rowers.integrations.nk.requests.get', side_effect=mocked_requests)
|
@patch('rowers.integrations.nk.requests.get', side_effect=mocked_requests)
|
||||||
@patch('rowers.integrations.nk.requests.post', side_effect=mocked_requests)
|
@patch('rowers.integrations.nk.requests.post', side_effect=mocked_requests)
|
||||||
def test_nk_list(self, mock_get, mockpost):
|
def test_nk_list(self, mock_get, mockpost):
|
||||||
|
|||||||
@@ -5155,7 +5155,7 @@ def workout_toggle_ranking(request, id=0):
|
|||||||
|
|
||||||
@csrf_exempt
|
@csrf_exempt
|
||||||
def workout_upload_api(request):
|
def workout_upload_api(request):
|
||||||
if request.method != 'POST': # pragma: no cover
|
if request.method!= 'POST': # pragma: no cover
|
||||||
message = {'status': 'false',
|
message = {'status': 'false',
|
||||||
'message': 'this view cannot be accessed through GET'}
|
'message': 'this view cannot be accessed through GET'}
|
||||||
return JSONResponse(status=403, data=message)
|
return JSONResponse(status=403, data=message)
|
||||||
|
|||||||
Reference in New Issue
Block a user