Add HUB tests

pull/4484/head
Glenn Jocher 1 year ago
parent f2f4aa5c9e
commit 6143f590ec
  1. 7
      tests/test_python.py
  2. 4
      ultralytics/hub/__init__.py
  3. 24
      ultralytics/hub/auth.py

@ -407,3 +407,10 @@ def test_nn_modules_block():
C3TR(c1, c2)(x)
C3Ghost(c1, c2)(x)
BottleneckCSP(c1, c2)(x)
def test_hub():
from ultralytics.hub import export_fmts_hub, logout
export_fmts_hub()
logout()

@ -5,7 +5,7 @@ import requests
from ultralytics.data.utils import HUBDatasetStats
from ultralytics.hub.auth import Auth
from ultralytics.hub.utils import HUB_API_ROOT, HUB_WEB_ROOT, PREFIX
from ultralytics.utils import LOGGER, SETTINGS, USER_CONFIG_DIR, yaml_save
from ultralytics.utils import LOGGER, SETTINGS
def login(api_key=''):
@ -37,7 +37,7 @@ def logout():
```
"""
SETTINGS['api_key'] = ''
yaml_save(USER_CONFIG_DIR / 'settings.yaml', SETTINGS)
SETTINGS.save()
LOGGER.info(f"{PREFIX}logged out ✅. To log in again, use 'yolo hub login'.")

@ -73,8 +73,7 @@ class Auth:
bool: True if authentication is successful, False otherwise.
"""
try:
header = self.get_auth_header()
if header:
if header := self.get_auth_header():
r = requests.post(f'{HUB_API_ROOT}/v1/auth', headers=header)
if not r.json().get('success', False):
raise ConnectionError('Unable to authenticate.')
@ -117,23 +116,4 @@ class Auth:
return {'authorization': f'Bearer {self.id_token}'}
elif self.api_key:
return {'x-api-key': self.api_key}
else:
return None
def get_state(self) -> bool:
"""
Get the authentication state.
Returns:
bool: True if either id_token or API key is set, False otherwise.
"""
return self.id_token or self.api_key
def set_api_key(self, key: str):
"""
Set the API key for authentication.
Args:
key (str): The API key string.
"""
self.api_key = key
# else returns None

Loading…
Cancel
Save