Compare commits

..
3 Commits
5 changed files with 69 additions and 5 deletions
+3 -1
View File
@@ -35,7 +35,9 @@ jobs:
pipenv check \
--ignore 51499 \
--ignore 52495 \
--ignore 52365
--ignore 52365 \
--ignore 59956 \
--ignore 58755
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
+1 -1
View File
@@ -1,6 +1,6 @@
[metadata]
name = tconnectsync
version = 0.9.4
version = 0.9.5
author = James Woglom
author_email = j@wogloms.net
description = Syncs Tandem t:connect pump data to Nightscout for the t:slim X2
+1 -1
View File
@@ -14,7 +14,7 @@ class ControlIQApi:
BASE_URL = 'https://tdcservices.tandemdiabetes.com/'
LOGIN_URL = 'https://tconnect.tandemdiabetes.com/login.aspx?ReturnUrl=%2f'
LAST_CONFIRMED_SOFTWARE_VERSION = 't:connect 7.15.0.1'
LAST_CONFIRMED_SOFTWARE_VERSION = 't:connect 7.16.0.1'
userGuid = None
accessToken = None
+5 -1
View File
@@ -30,10 +30,14 @@ class WebUIScraper:
return self.controliq.needs_relogin()
def _get(self, endpoint):
r = self.controliq.loginSession.get(self.BASE_URL + endpoint, headers=base_headers())
r = self.controliq.loginSession.get(self.BASE_URL + endpoint, headers=base_headers(), allow_redirects=True)
if r.status_code != 200:
raise ApiException(r.status_code, "WebUIScraper HTTP %s response: %s" % (str(r.status_code), r.text))
if 'login.aspx' in r.url:
raise ApiException(401, "WebUIScraper HTTP %s response for login page, returning 401: %s" % (str(r.status_code), r.url))
return r
+59 -1
View File
@@ -18,7 +18,7 @@ from .fake import ControlIQApi
from tconnectsync.api.controliq import ControlIQApi as RealControlIQApi
from tconnectsync.api.common import ApiException, ApiLoginException, base_headers
class TestWebUIScraper(unittest.TestCase):
class TestWebUIScraperMyDevices(unittest.TestCase):
maxDiff = None
DEVICES_HTML = """
@@ -319,6 +319,64 @@ class TestWebUIScraper(unittest.TestCase):
'guid': None
})})
REDIRECT_HTML = """<html><head><title>Object moved</title></head><body>
<h2>Object moved to <a href="/login.aspx?ReturnUrl=%2fmyaccount%2fmy_devices.aspx">here</a>.</h2>
</body></html>"""
LOGIN_HTML = """<html></html>"""
def test_relogin_when_redirected_to_login_page(self):
ciq = ControlIQApi()
ciq.needs_relogin = lambda: False
ciq.loginSession = requests.Session()
ciq.LOGIN_URL = RealControlIQApi.LOGIN_URL
ciq._email = 'EMAIL'
ciq._password = 'PASSWORD'
login_times = []
def fake_login(email, password):
self.assertEqual(email, ciq._email)
self.assertEqual(password, ciq._password)
login_times.append(1)
return True
ciq.login = fake_login
webui = WebUIScraper(ciq)
ciq.login(ciq._email, ciq._password)
self.assertEqual(len(login_times), 1)
with requests_mock.Mocker() as m:
m.get('https://tconnect.tandemdiabetes.com/myaccount/my_devices.aspx',
request_headers=base_headers(),
status_code=302,
headers={'Location': 'https://tconnect.tandemdiabetes.com/login.aspx?ReturnUrl=%2fmyaccount%2fmy_devices.aspx'},
text=self.REDIRECT_HTML)
m.get('https://tconnect.tandemdiabetes.com/login.aspx?ReturnUrl=%2fmyaccount%2fmy_devices.aspx',
request_headers=base_headers(),
status_code=200,
text=self.LOGIN_HTML)
self.assertRaises(ApiException, webui.my_devices)
self.assertEqual(len(login_times), 2)
with requests_mock.Mocker() as m:
m.get('https://tconnect.tandemdiabetes.com/myaccount/my_devices.aspx',
request_headers=base_headers(),
text=self.DEVICES_HTML)
devices = webui.my_devices()
self.assertEqual(len(login_times), 2)
class TestWebUIScraperPumpSettings(unittest.TestCase):
maxDiff = None
PUMP_SETTINGS_HTML = """
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">