diff --git a/src/hf_hydrodata/gridded.py b/src/hf_hydrodata/gridded.py index 3d94cf7..109e42d 100644 --- a/src/hf_hydrodata/gridded.py +++ b/src/hf_hydrodata/gridded.py @@ -796,6 +796,8 @@ def _validate_user(): email, pin = get_registered_api_pin() url_security = f"{HYDRODATA_URL}/api/api_pins?pin={pin}&email={email}" response = requests.get(url_security, timeout=15) + if not response.status_code == 200: + raise ValueError(f"No registered PIN for email '{email}' and PIN {pin}. See documentation to register with a URL.") json_string = response.content.decode("utf-8") jwt_json = json.loads(json_string) jwt_token = jwt_json["jwt_token"] diff --git a/tests/hf_hydrodata/test_gridded.py b/tests/hf_hydrodata/test_gridded.py index eb2ed24..1d808dd 100644 --- a/tests/hf_hydrodata/test_gridded.py +++ b/tests/hf_hydrodata/test_gridded.py @@ -21,11 +21,11 @@ class MockResponse: def __init__(self): self.headers = {} self.status_code = 200 - self.content = b"test content" + self.content = b'{"email": "dummy@email.com", "jwt_token":"foo"}' self.checksum = "" -def mock_requests_get(url, timeout): +def mock_requests_get(url, headers=None, timeout=5): """Create a mock streaming response.""" response = MockResponse()