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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
"""
Shared fixtures for the GeneNetwork integration test suite.
Base URLs default to the CD environment. Override via environment variables:
GN2_BASE_URL e.g. https://genenetwork.org (default: CD)
GN3_BASE_URL e.g. https://genenetwork.org/api3 (default: CD)
GN_AUTH_BASE_URL e.g. https://auth.genenetwork.org (default: CD)
For auth-flow tests also set:
GN_TEST_EMAIL registered test-user e-mail address
GN_TEST_PASSWORD password for GN_TEST_EMAIL
GN_OAUTH2_CLIENT_ID OAuth2 client UUID
GN_OAUTH2_CLIENT_SECRET OAuth2 client secret
"""
import os
import pytest
import requests
_GN2_DEFAULT = "https://cd.genenetwork.org"
_GN3_DEFAULT = "https://cd.genenetwork.org/api3"
_GN_AUTH_DEFAULT = "https://auth-cd.genenetwork.org"
@pytest.fixture(scope="session")
def gn2_url() -> str:
return os.environ.get("GN2_BASE_URL", _GN2_DEFAULT).rstrip("/")
@pytest.fixture(scope="session")
def gn3_url() -> str:
return os.environ.get("GN3_BASE_URL", _GN3_DEFAULT).rstrip("/")
@pytest.fixture(scope="session")
def gn_auth_url() -> str:
return os.environ.get("GN_AUTH_BASE_URL", _GN_AUTH_DEFAULT).rstrip("/")
@pytest.fixture(scope="session")
def http() -> requests.Session:
"""Shared requests.Session; sets a conservative timeout for all calls."""
with requests.Session() as session:
session.headers.update({"Accept": "application/json"})
yield session
# ---------------------------------------------------------------------------
# Auth-flow helpers (Phase 2 tests)
# ---------------------------------------------------------------------------
@pytest.fixture(scope="session")
def oauth2_credentials():
"""Returns (email, password, client_id, client_secret) or skips the test."""
email = os.environ.get("GN_TEST_EMAIL")
password = os.environ.get("GN_TEST_PASSWORD")
client_id = os.environ.get("GN_OAUTH2_CLIENT_ID")
client_secret = os.environ.get("GN_OAUTH2_CLIENT_SECRET")
if not all([email, password, client_id, client_secret]):
pytest.skip(
"Set GN_TEST_EMAIL, GN_TEST_PASSWORD, GN_OAUTH2_CLIENT_ID, and "
"GN_OAUTH2_CLIENT_SECRET to run auth-flow tests."
)
return email, password, client_id, client_secret
@pytest.fixture(scope="session")
def access_token(gn_auth_url, oauth2_credentials, http):
"""Obtains a Bearer token via the password grant and caches it for the session."""
email, password, client_id, client_secret = oauth2_credentials
resp = http.post(
f"{gn_auth_url}/auth/token",
json={
"grant_type": "password",
"username": email,
"password": password,
"scope": "profile group resource",
"client_id": client_id,
"client_secret": client_secret,
},
timeout=30,
)
assert resp.status_code == 200, f"Token request failed: {resp.text}"
data = resp.json()
assert "access_token" in data
return data["access_token"]
|