-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_providers.py
More file actions
36 lines (24 loc) · 1.05 KB
/
Copy pathtest_providers.py
File metadata and controls
36 lines (24 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import re
from typing import cast
import pytest
import responses
from niquests import AsyncSession
from niquests.cookies import RequestsCookieJar
from tilebox.storage.providers import _asf_login
pytestmark = pytest.mark.usefixtures("responses_mock")
ASF_LOGIN_URL = "https://urs.earthdata.nasa.gov/oauth/authorize"
@pytest.mark.asyncio
async def test_asf_login() -> None:
responses.add(responses.GET, ASF_LOGIN_URL, headers={"Set-Cookie": "logged_in=yes"})
client = await _asf_login(("username", "password"))
cookies = cast(RequestsCookieJar, client.cookies)
assert isinstance(client, AsyncSession)
assert "asf_search" in str(client.headers["Client-Id"])
assert client.auth == ("username", "password")
assert cookies["logged_in"] == "yes"
await client.close()
@pytest.mark.asyncio
async def test_asf_login_invalid_auth() -> None:
responses.add(responses.GET, ASF_LOGIN_URL, status=401)
with pytest.raises(ValueError, match=re.escape("Invalid username or password.")):
await _asf_login(("username", "password"))