Private
Public Access
1
0

working NK sync tests

This commit is contained in:
Sander Roosendaal
2021-04-16 17:13:45 +02:00
parent 2ee31d6fc3
commit 8f81c5fc92
7 changed files with 265 additions and 181 deletions

View File

@@ -165,6 +165,70 @@ def mocked_sqlalchemy(*args, **kwargs):
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
class DjangoTestCase(TestCase): #, MockTestCase):
def _pre_setup(self):
@@ -801,6 +865,7 @@ def mocked_requests(*args, **kwargs):
nkstrokesregex = '.*?nkrowlink\.com\/api\/v1\/sessions\/strokes'
nkstrokestester = re.compile(nkstrokesregex)
stravaathleteregex = '.*?strava\.com\/api\/v3\/athlete$'
stravaathletetester = re.compile(stravaathleteregex)
@@ -967,7 +1032,6 @@ def mocked_requests(*args, **kwargs):
if nktester.match(args[0]):
if 'token' in args[0]:
json_data = {
'access_token': 'TA3n1vrNjuQJWw0TdCDHnjSmrjIPULhTlejMIWqq',
@@ -977,6 +1041,7 @@ def mocked_requests(*args, **kwargs):
return MockResponse(json_data,200)
if nkstrokestester.match(args[0]):
params = kwargs.pop('params',{})
if 'sessionIds' in params and params['sessionIds'] == '404':
return MockResponse(nkimpellerstrokedata, 200)
return MockResponse(nkstrokedata,200)