mocking strava/polar/c2 connection in email tests
This commit is contained in:
@@ -60,8 +60,12 @@ def mocked_requests(*args, **kwargs):
|
|||||||
with open('rowers/testdata/c2jsonstrokedata.txt','r') as infile:
|
with open('rowers/testdata/c2jsonstrokedata.txt','r') as infile:
|
||||||
c2strokedata = json.load(infile)
|
c2strokedata = json.load(infile)
|
||||||
|
|
||||||
|
polar_json = {
|
||||||
|
'available-user-data': []
|
||||||
|
}
|
||||||
|
|
||||||
c2workoutlist = json.load(open('rowers/testdata/c2workoutlist.txt'))
|
c2workoutlist = json.load(open('rowers/testdata/c2workoutlist.txt'))
|
||||||
|
|
||||||
c2uploadjson = {
|
c2uploadjson = {
|
||||||
"data": {
|
"data": {
|
||||||
"id": 339,
|
"id": 339,
|
||||||
@@ -152,6 +156,7 @@ def mocked_requests(*args, **kwargs):
|
|||||||
if not args:
|
if not args:
|
||||||
return MockSession()
|
return MockSession()
|
||||||
|
|
||||||
|
polartester = re.compile('.*?polaraccesslink\.com')
|
||||||
c2tester = re.compile('.*?log\.concept2\.com')
|
c2tester = re.compile('.*?log\.concept2\.com')
|
||||||
stravatester = re.compile('.*?strava\.com')
|
stravatester = re.compile('.*?strava\.com')
|
||||||
sttester = re.compile('.*?sporttracks\.mobi')
|
sttester = re.compile('.*?sporttracks\.mobi')
|
||||||
@@ -214,6 +219,10 @@ def mocked_requests(*args, **kwargs):
|
|||||||
tpuploadregex = '.*?trainingpeaks\.com\/v1\/file'
|
tpuploadregex = '.*?trainingpeaks\.com\/v1\/file'
|
||||||
tpuploadtester = re.compile(tpuploadregex)
|
tpuploadtester = re.compile(tpuploadregex)
|
||||||
|
|
||||||
|
if polartester.match(args[0]):
|
||||||
|
json_data = polar_json
|
||||||
|
return MockResponse(json_data,200)
|
||||||
|
|
||||||
if tptester.match(args[0]):
|
if tptester.match(args[0]):
|
||||||
if 'token' in args[0]:
|
if 'token' in args[0]:
|
||||||
json_data = {
|
json_data = {
|
||||||
@@ -1068,8 +1077,8 @@ boattype: 4x
|
|||||||
if not os.path.isdir(path):
|
if not os.path.isdir(path):
|
||||||
os.remove(path)
|
os.remove(path)
|
||||||
|
|
||||||
@patch('rowers.c2stuff.requests.get', side_effect=mocked_requests)
|
@patch('requests.get', side_effect=mocked_requests)
|
||||||
def test_emailprocessing(self):
|
def test_emailprocessing(self, mock_get):
|
||||||
out = StringIO()
|
out = StringIO()
|
||||||
call_command('processemail', stdout=out,testing=True)
|
call_command('processemail', stdout=out,testing=True)
|
||||||
self.assertIn('Successfully processed email attachments',out.getvalue())
|
self.assertIn('Successfully processed email attachments',out.getvalue())
|
||||||
|
|||||||
Reference in New Issue
Block a user