working NK sync tests
This commit is contained in:
@@ -696,7 +696,7 @@ def updatecpdata_sql(rower_id,delta,cp,table='cpdata',distance=pd.Series([]),deb
|
|||||||
engine = create_engine(database_url, echo=False)
|
engine = create_engine(database_url, echo=False)
|
||||||
|
|
||||||
|
|
||||||
with engine.connect() as conn, conn.begin():
|
with engine.connect() as conn, conn.begin():
|
||||||
df.to_sql(table, engine, if_exists='append', index=False)
|
df.to_sql(table, engine, if_exists='append', index=False)
|
||||||
conn.close()
|
conn.close()
|
||||||
engine.dispose()
|
engine.dispose()
|
||||||
|
|||||||
318
rowers/tasks.py
318
rowers/tasks.py
File diff suppressed because it is too large
Load Diff
@@ -165,6 +165,70 @@ def mocked_sqlalchemy(*args, **kwargs):
|
|||||||
|
|
||||||
return MockEngine()
|
return MockEngine()
|
||||||
|
|
||||||
|
from rowers import courses
|
||||||
|
|
||||||
|
def mocked_sqlalchemy_courses(*args, **kwargs):
|
||||||
|
# return object with method
|
||||||
|
cs = courses.kmltocourse('rowers/tests/testdata/thyro.kml')
|
||||||
|
course = cs[0]
|
||||||
|
cname = course['name']
|
||||||
|
cnotes = course['description']
|
||||||
|
polygons = course['polygons']
|
||||||
|
|
||||||
|
lijst = []
|
||||||
|
i=0
|
||||||
|
for polygon in polygons:
|
||||||
|
lijst.append((i,polygon['name']))
|
||||||
|
i = i+1
|
||||||
|
|
||||||
|
puntenlijst = []
|
||||||
|
i = 0
|
||||||
|
for p in polygons[0]['points']:
|
||||||
|
puntenlijst.append((i,p['latitude'],p['longitude']))
|
||||||
|
i = i+1
|
||||||
|
|
||||||
|
|
||||||
|
class MockEngine:
|
||||||
|
def connect(self):
|
||||||
|
return MockConnection()
|
||||||
|
|
||||||
|
def dispose(self):
|
||||||
|
return True
|
||||||
|
|
||||||
|
def raw_connection(self):
|
||||||
|
return True
|
||||||
|
|
||||||
|
class QueryResultPolygons:
|
||||||
|
def fetchall(self):
|
||||||
|
return lijst
|
||||||
|
|
||||||
|
class QueryResultPoints:
|
||||||
|
def fetchall(self):
|
||||||
|
return puntenlijst
|
||||||
|
|
||||||
|
class MockConnection:
|
||||||
|
def begin(self):
|
||||||
|
return True
|
||||||
|
|
||||||
|
def execute(self,query):
|
||||||
|
if 'latitude' in query:
|
||||||
|
return QueryResultPoints()
|
||||||
|
if 'polygon' in query:
|
||||||
|
return QueryResultPolygons()
|
||||||
|
return True
|
||||||
|
|
||||||
|
def close(self):
|
||||||
|
return True
|
||||||
|
|
||||||
|
def __exit__(self, *args, **kwargs):
|
||||||
|
return True
|
||||||
|
|
||||||
|
def __enter__(self, *args, **kwargs):
|
||||||
|
return True
|
||||||
|
|
||||||
|
return MockEngine()
|
||||||
|
|
||||||
|
|
||||||
#@pytest.mark.django_db
|
#@pytest.mark.django_db
|
||||||
class DjangoTestCase(TestCase): #, MockTestCase):
|
class DjangoTestCase(TestCase): #, MockTestCase):
|
||||||
def _pre_setup(self):
|
def _pre_setup(self):
|
||||||
@@ -801,6 +865,7 @@ def mocked_requests(*args, **kwargs):
|
|||||||
nkstrokesregex = '.*?nkrowlink\.com\/api\/v1\/sessions\/strokes'
|
nkstrokesregex = '.*?nkrowlink\.com\/api\/v1\/sessions\/strokes'
|
||||||
nkstrokestester = re.compile(nkstrokesregex)
|
nkstrokestester = re.compile(nkstrokesregex)
|
||||||
|
|
||||||
|
|
||||||
stravaathleteregex = '.*?strava\.com\/api\/v3\/athlete$'
|
stravaathleteregex = '.*?strava\.com\/api\/v3\/athlete$'
|
||||||
stravaathletetester = re.compile(stravaathleteregex)
|
stravaathletetester = re.compile(stravaathleteregex)
|
||||||
|
|
||||||
@@ -967,7 +1032,6 @@ def mocked_requests(*args, **kwargs):
|
|||||||
|
|
||||||
|
|
||||||
if nktester.match(args[0]):
|
if nktester.match(args[0]):
|
||||||
|
|
||||||
if 'token' in args[0]:
|
if 'token' in args[0]:
|
||||||
json_data = {
|
json_data = {
|
||||||
'access_token': 'TA3n1vrNjuQJWw0TdCDHnjSmrjIPULhTlejMIWqq',
|
'access_token': 'TA3n1vrNjuQJWw0TdCDHnjSmrjIPULhTlejMIWqq',
|
||||||
@@ -977,6 +1041,7 @@ def mocked_requests(*args, **kwargs):
|
|||||||
return MockResponse(json_data,200)
|
return MockResponse(json_data,200)
|
||||||
if nkstrokestester.match(args[0]):
|
if nkstrokestester.match(args[0]):
|
||||||
params = kwargs.pop('params',{})
|
params = kwargs.pop('params',{})
|
||||||
|
|
||||||
if 'sessionIds' in params and params['sessionIds'] == '404':
|
if 'sessionIds' in params and params['sessionIds'] == '404':
|
||||||
return MockResponse(nkimpellerstrokedata, 200)
|
return MockResponse(nkimpellerstrokedata, 200)
|
||||||
return MockResponse(nkstrokedata,200)
|
return MockResponse(nkstrokedata,200)
|
||||||
|
|||||||
@@ -10,6 +10,8 @@ import pandas as pd
|
|||||||
nu = datetime.datetime.now()
|
nu = datetime.datetime.now()
|
||||||
from rowers import tasks
|
from rowers import tasks
|
||||||
|
|
||||||
|
import rowers.courses as courses
|
||||||
|
|
||||||
|
|
||||||
class fakejob:
|
class fakejob:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
@@ -53,6 +55,15 @@ class AsyncTaskTests(TestCase):
|
|||||||
workouttype = 'water',
|
workouttype = 'water',
|
||||||
)
|
)
|
||||||
|
|
||||||
|
cs = courses.kmltocourse('rowers/tests/testdata/thyro.kml')
|
||||||
|
course = cs[0]
|
||||||
|
cname = course['name']
|
||||||
|
cnotes = course['description']
|
||||||
|
polygons = course['polygons']
|
||||||
|
self.ThyroBaantje = courses.createcourse(self.r,cname,polygons,notes=cnotes)
|
||||||
|
self.ThyroBaantje.save()
|
||||||
|
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
for workout in self.user_workouts:
|
for workout in self.user_workouts:
|
||||||
try:
|
try:
|
||||||
@@ -68,6 +79,13 @@ class AsyncTaskTests(TestCase):
|
|||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def test_polygons(self):
|
||||||
|
polygons = GeoPolygon.objects.all()
|
||||||
|
polygon = polygons[0]
|
||||||
|
obj = (polygon.id,polygon.name)
|
||||||
|
path = tasks.polygon_to_path(obj)
|
||||||
|
self.assertEqual(len(path),4)
|
||||||
|
|
||||||
def test_summaryfromsplitdata(self):
|
def test_summaryfromsplitdata(self):
|
||||||
splitdata = [
|
splitdata = [
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -432,24 +432,20 @@ class NKObjects(DjangoTestCase):
|
|||||||
|
|
||||||
self.assertEqual(response.status_code,200)
|
self.assertEqual(response.status_code,200)
|
||||||
|
|
||||||
@patch('rowers.nkimportutils.requests.session', side_effect=mocked_session)
|
@patch('rowers.tasks.requests.get', side_effect=mocked_requests)
|
||||||
@patch('rowers.tasks.requests.get', side_effects=mocked_requests)
|
def test_handle_nk_get_workouts(self, mock_get):
|
||||||
def test_handle_nk_get_workouts(self, mocked_session, mock_get):
|
|
||||||
with open('rowers/tests/testdata/nk_list.json','r') as f:
|
with open('rowers/tests/testdata/nk_list.json','r') as f:
|
||||||
data = json.load(f)
|
data = json.load(f)
|
||||||
|
|
||||||
with open('rowers/tests/testdata/nk_strokes.json','r') as f:
|
|
||||||
strokeData = json.load(f)
|
|
||||||
|
|
||||||
alldata = {}
|
alldata = {}
|
||||||
for item in data:
|
for item in data:
|
||||||
alldata[item['id']] = item
|
alldata[item['id']] = item
|
||||||
|
|
||||||
result = rowers.nkstuff.rower_nk_token_refresh(self.u)
|
|
||||||
|
|
||||||
res = tasks.handle_nk_async_workout(
|
res = tasks.handle_nk_async_workout(
|
||||||
alldata,self.r.user.id,self.r.nktoken,469,0,'UTC'
|
alldata,self.r.user.id,self.r.nktoken,469,0,'UTC'
|
||||||
)
|
)
|
||||||
|
self.assertTrue(res>0)
|
||||||
|
|
||||||
|
|
||||||
@patch('rowers.nkstuff.requests.get', side_effect=mocked_requests)
|
@patch('rowers.nkstuff.requests.get', side_effect=mocked_requests)
|
||||||
@@ -570,21 +566,6 @@ class StravaObjects(DjangoTestCase):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
# @patch('rowers.stravastuff.requests.post', side_effect=mocked_requests)
|
|
||||||
# @patch('rowers.views.stravastuff.handle_stravaexport')
|
|
||||||
#@patch('rowers.dataprep.getsmallrowdata_db')
|
|
||||||
#def test_strava_upload(self, mock_post,MockStravalibClient,
|
|
||||||
# mocked_getsmallrowdata_db):
|
|
||||||
# def test_strava_upload(self,mock_post, mocked_stravaexport):
|
|
||||||
# response = self.c.get('/rowers/workout/1/stravauploadw/')
|
|
||||||
|
|
||||||
# self.assertRedirects(response,
|
|
||||||
# expected_url = '/rowers/workout/1/edit/',
|
|
||||||
# status_code=302,target_status_code=200)
|
|
||||||
|
|
||||||
# self.assertEqual(response.url, '/rowers/workout/1/edit/')
|
|
||||||
# self.assertEqual(response.status_code, 302)
|
|
||||||
|
|
||||||
@patch('rowers.stravastuff.requests.get', side_effect=mocked_requests)
|
@patch('rowers.stravastuff.requests.get', side_effect=mocked_requests)
|
||||||
@patch('rowers.stravastuff.requests.post', side_effect=mocked_requests)
|
@patch('rowers.stravastuff.requests.post', side_effect=mocked_requests)
|
||||||
def test_strava_list(self, mock_get, mockpost):
|
def test_strava_list(self, mock_get, mockpost):
|
||||||
|
|||||||
@@ -729,6 +729,20 @@ class ChallengesTest(TestCase):
|
|||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
|
|
||||||
|
@patch('rowers.tasks.create_engine', side_effect=mocked_sqlalchemy_courses)
|
||||||
|
def notest_virtualevent_check_view(self,mocked_sqlalchemy_courses):
|
||||||
|
|
||||||
|
res = tasks.handle_check_race_course(
|
||||||
|
self.wthyro.csvfilename,
|
||||||
|
self.wthyro.id,
|
||||||
|
self.ThyroBaantje.id,
|
||||||
|
self.result.id,
|
||||||
|
self.wthyro.user.user.email,
|
||||||
|
self.wthyro.user.user.first_name,
|
||||||
|
mode='coursetest',
|
||||||
|
)
|
||||||
|
|
||||||
|
self.assertEqual(res,1)
|
||||||
|
|
||||||
|
|
||||||
# add boat
|
# add boat
|
||||||
|
|||||||
@@ -4978,7 +4978,7 @@ def workout_upload_view(request,
|
|||||||
},
|
},
|
||||||
raceid=0):
|
raceid=0):
|
||||||
|
|
||||||
is_ajax = request_is_ajax
|
is_ajax = request_is_ajax(request)
|
||||||
if settings.TESTING:
|
if settings.TESTING:
|
||||||
is_ajax = False
|
is_ajax = False
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user