kopia lustrzana https://codeberg.org/argrento/huami-token
ci: fix error, add mifitness login test
* mifitness test can be skipped if test is executed in a limited environment (cloud machine)mi-fitness-support
rodzic
165f6c84df
commit
939482b1fa
|
@ -22,11 +22,11 @@ pipeline:
|
|||
- python -m pip install --upgrade pip
|
||||
- python -m pip install -r requirements.txt
|
||||
- pytest tests/
|
||||
secrets: [ amazfit_email, amazfit_password ]
|
||||
secrets: [ amazfit_email, amazfit_password, mifitness_email, mifitness_password ]
|
||||
|
||||
matrix:
|
||||
TAG:
|
||||
- 3.8
|
||||
- 3.9
|
||||
- 3.10
|
||||
- 3.11
|
||||
# - 3.9
|
||||
# - 3.10
|
||||
# - 3.11
|
||||
|
|
|
@ -131,7 +131,7 @@ class HuamiAmazfit:
|
|||
self.access_token = redirect_url_parameters['access'][0]
|
||||
elif self.method == "mifitness":
|
||||
print("Step 1: getting sign and callback... ", end="")
|
||||
password_hash = hashlib.md5(args.password.encode()).hexdigest().upper()
|
||||
password_hash = hashlib.md5(self.password.encode()).hexdigest().upper()
|
||||
url = urls.URLS["login_mi_fitness"]
|
||||
headers = urls.PAYLOADS["initial_login_mi_fitness"]
|
||||
headers["Cookie"] = headers["Cookie"].format(userId=self.email, deviceId="foobar")
|
||||
|
@ -142,7 +142,7 @@ class HuamiAmazfit:
|
|||
"_locale": "en_US"
|
||||
}
|
||||
|
||||
response = requests.get(url, headers=headers, params=params, timeout=1)
|
||||
response = requests.get(url, headers=headers, params=params, timeout=10)
|
||||
|
||||
sign, callback, qs = None, None, None
|
||||
if response.status_code == 200:
|
||||
|
@ -174,11 +174,17 @@ class HuamiAmazfit:
|
|||
|
||||
if response.status_code == 200:
|
||||
response_data = json.loads(response.text.replace('&&&START&&&', ''))
|
||||
error_code = str(response_data.get("code"))
|
||||
if error_code != "0":
|
||||
error_code = response_data.get("code")
|
||||
if error_code != 0:
|
||||
print("ERROR")
|
||||
raise ValueError(f"Step failed. {errors.ERRORS[error_code]}")
|
||||
|
||||
security_status = response_data.get("securityStatus")
|
||||
if security_status != 0:
|
||||
raise ValueError(f"""Additional security step """
|
||||
f"""required. Use use this url and restart script:\n"""
|
||||
f"""{response_data["notificationUrl"]}""")
|
||||
|
||||
ssecurity = response_data.get("ssecurity", "")
|
||||
psecurity = response_data.get("psecurity", "")
|
||||
passToken = response_data.get("passToken", "")
|
||||
|
@ -567,7 +573,7 @@ if __name__ == "__main__":
|
|||
print(f"\u2551 Hash: {hash_sum}")
|
||||
with requests.get(link, stream=True, timeout=10) as dl_request:
|
||||
with open(file_name, 'wb') as f:
|
||||
shutil.copyfileobj(dl_request.raw, dl_request)
|
||||
shutil.copyfileobj(dl_request.raw, f)
|
||||
else:
|
||||
print("\u2551 No updates found")
|
||||
print(footer)
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
import os
|
||||
import unittest
|
||||
from huami_token import HuamiAmazfit
|
||||
import pytest
|
||||
|
||||
class TestMifitness(unittest.TestCase):
|
||||
@pytest.mark.skipif(os.environ.get('LIMITED_ENV', '0') == '1',
|
||||
reason="Skipped due to limited environment: test can require 2FA.")
|
||||
def test_login(self) -> None:
|
||||
email: str = os.environ.get('MIFITNESS_EMAIL', '')
|
||||
password: str = os.environ.get('MIFITNESS_PASSWORD', '')
|
||||
|
||||
device = HuamiAmazfit(method="mifitness",
|
||||
email=email,
|
||||
password=password)
|
||||
access_token = device.get_access_token()
|
||||
user_id = device.login(external_token=access_token)
|
||||
print(user_id)
|
||||
|
||||
self.assertEqual(user_id,
|
||||
8205585008,
|
||||
"Unexpected user id")
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
Ładowanie…
Reference in New Issue