mocked all c2stuff except workout export
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
from __future__ import print_function
|
||||
#from __future__ import print_function
|
||||
from bs4 import BeautifulSoup
|
||||
import re
|
||||
|
||||
@@ -52,9 +52,7 @@ class DjangoTestCase(TestCase, MockTestCase):
|
||||
MockTestCase.tearDown(self)
|
||||
delete_strokedata(1)
|
||||
|
||||
# Create your tests here.
|
||||
|
||||
def mocked_requests_get(*args, **kwargs):
|
||||
def mocked_requests(*args, **kwargs):
|
||||
with open('rowers/testdata/c2jsonworkoutdata.txt','r') as infile:
|
||||
c2workoutdata = json.load(infile)
|
||||
|
||||
@@ -71,11 +69,58 @@ def mocked_requests_get(*args, **kwargs):
|
||||
def json(self):
|
||||
return self.json_data
|
||||
|
||||
if 'log.concept2.com/' in args[0]:
|
||||
if 'strokes' in args[0]:
|
||||
class MockSession:
|
||||
def send(self,prepped):
|
||||
json_data = {
|
||||
'access_token': 'TA3n1vrNjuQJWw0TdCDHnjSmrjIPULhTlejMIWqq',
|
||||
'expires_in': 604800,
|
||||
'refresh_token': 'jHJhFzCfOOKB8oyiayubhLAlxaMkG3ruC1E8YxaR'
|
||||
}
|
||||
|
||||
return MockResponse(json_data,200)
|
||||
|
||||
if not args:
|
||||
return MockSession()
|
||||
|
||||
c2tester = re.compile('.*?log\.concept2\.com')
|
||||
|
||||
c2importregex = '.*?concept2.com\/api\/users\/me\/results\/\d+'
|
||||
c2importtester = re.compile(c2importregex)
|
||||
|
||||
c2strokesregex = '.*?concept2.com\/api\/users\/me\/results\/\d+\/strokes'
|
||||
c2strokestester = re.compile(c2strokesregex)
|
||||
|
||||
c2workoutlistregex = '.*?concept2\.com\/api\/users\/me\/results\?page=\d'
|
||||
c2workoutlisttester = re.compile(c2workoutlistregex)
|
||||
|
||||
if c2tester.match(args[0]):
|
||||
if c2strokestester.match(args[0]):
|
||||
return MockResponse(c2strokedata,200)
|
||||
elif 'page' in args[0]:
|
||||
elif c2importtester.match(args[0]):
|
||||
return MockResponse(c2workoutdata,200)
|
||||
elif c2workoutlisttester(args[0]):
|
||||
return MockResponse(c2workoutlist,200)
|
||||
elif 'access_token' in args[0]:
|
||||
json_data = {
|
||||
'access_token': 'TA3n1vrNjuQJWw0TdCDHnjSmrjIPULhTlejMIWqq',
|
||||
'expires_in': 604800,
|
||||
'refresh_token': 'jHJhFzCfOOKB8oyiayubhLAlxaMkG3ruC1E8YxaR'
|
||||
}
|
||||
return MockResponse(json_data,200)
|
||||
elif 'users/me' in args[0]:
|
||||
json_data = {
|
||||
'data': {
|
||||
'username': 'john',
|
||||
'id': 1234,
|
||||
}
|
||||
}
|
||||
return MockResponse(json_data,200)
|
||||
elif 'results' in args[0]:
|
||||
json_data = {
|
||||
'data': {
|
||||
'id': 1223,
|
||||
}
|
||||
}
|
||||
else:
|
||||
return MockResponse(c2workoutdata,200)
|
||||
|
||||
@@ -100,15 +145,30 @@ class C2Objects(DjangoTestCase):
|
||||
self.r.tokenexpirydate = datetime.datetime.now()+datetime.timedelta(days=1)
|
||||
self.r.save()
|
||||
self.c.login(username='john',password='koeinsloot')
|
||||
|
||||
@patch('rowers.c2stuff.requests.Session', side_effect=mocked_requests)
|
||||
def test_c2_callback(self, mock_post):
|
||||
response = self.c.get('/call_back?code=dsdoij232s',follow=True)
|
||||
|
||||
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
|
||||
@patch('rowers.c2stuff.Session', side_effect=mocked_requests)
|
||||
def test_c2_token_refresh(self, mock_post):
|
||||
response = self.c.get('/rowers/me/c2refresh/',follow=True)
|
||||
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
|
||||
|
||||
@patch('rowers.c2stuff.requests.get', side_effect=mocked_requests_get)
|
||||
@patch('rowers.c2stuff.requests.post', side_effect=mocked_requests)
|
||||
def test_c2_list(self, mock_get):
|
||||
response = self.c.get('/rowers/workout/c2list',follow=True)
|
||||
|
||||
self.assertEqual(response.status_code,200)
|
||||
|
||||
@patch('rowers.c2stuff.requests.get', side_effect=mocked_requests_get)
|
||||
@patch('rowers.c2stuff.requests.get', side_effect=mocked_requests)
|
||||
def test_c2_import(self, mock_get):
|
||||
|
||||
response = self.c.get('/rowers/workout/c2import/12/',follow=True)
|
||||
|
||||
Reference in New Issue
Block a user