-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #93 from ssciwr/add_researcher_flag_to_user
Add is_researcher boolean flag to User
- Loading branch information
Showing
8 changed files
with
100 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
from __future__ import annotations | ||
|
||
from fastapi import APIRouter | ||
|
||
from ..dependencies import ResearchDep | ||
|
||
|
||
def create_router() -> APIRouter: | ||
router = APIRouter( | ||
prefix="/research", tags=["research"], dependencies=[ResearchDep] | ||
) | ||
|
||
@router.get("/auth/") | ||
def auth(): | ||
return {"ok": True} | ||
|
||
return router |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
from fastapi import FastAPI | ||
from fastapi.testclient import TestClient | ||
from mondey_backend import settings | ||
from mondey_backend.dependencies import current_active_researcher | ||
from mondey_backend.dependencies import current_active_superuser | ||
from mondey_backend.dependencies import current_active_user | ||
from mondey_backend.dependencies import get_session | ||
|
@@ -117,23 +118,37 @@ def session(static_dir: pathlib.Path): | |
|
||
|
||
@pytest.fixture | ||
def admin(): | ||
def active_admin_user(): | ||
UserRead( | ||
id=1, | ||
id=3, | ||
email="[email protected]", | ||
is_active=True, | ||
is_superuser=True, | ||
is_researcher=False, | ||
is_verified=True, | ||
) | ||
|
||
|
||
@pytest.fixture | ||
def user(): | ||
def active_research_user(): | ||
UserRead( | ||
id=2, | ||
email="[email protected]", | ||
is_active=True, | ||
is_superuser=False, | ||
is_researcher=True, | ||
is_verified=True, | ||
) | ||
|
||
|
||
@pytest.fixture | ||
def active_user(): | ||
UserRead( | ||
id=1, | ||
email="[email protected]", | ||
is_active=True, | ||
is_superuser=False, | ||
is_researcher=False, | ||
is_verified=True, | ||
) | ||
|
||
|
@@ -147,21 +162,38 @@ def app(static_dir: pathlib.Path): | |
|
||
@pytest.fixture | ||
def user_client( | ||
app: FastAPI, static_dir: pathlib.Path, session: Session, user: UserRead | ||
app: FastAPI, static_dir: pathlib.Path, session: Session, active_user: UserRead | ||
): | ||
app.dependency_overrides[get_session] = lambda: session | ||
app.dependency_overrides[current_active_user] = lambda: active_user | ||
client = TestClient(app) | ||
yield client | ||
app.dependency_overrides.clear() | ||
|
||
|
||
@pytest.fixture | ||
def research_client( | ||
app: FastAPI, | ||
static_dir: pathlib.Path, | ||
session: Session, | ||
active_research_user: UserRead, | ||
): | ||
app.dependency_overrides[get_session] = lambda: session | ||
app.dependency_overrides[current_active_user] = lambda: user | ||
app.dependency_overrides[current_active_researcher] = lambda: active_research_user | ||
client = TestClient(app) | ||
yield client | ||
app.dependency_overrides.clear() | ||
|
||
|
||
@pytest.fixture | ||
def admin_client( | ||
app: FastAPI, static_dir: pathlib.Path, session: Session, admin: UserRead | ||
app: FastAPI, | ||
static_dir: pathlib.Path, | ||
session: Session, | ||
active_admin_user: UserRead, | ||
): | ||
app.dependency_overrides[get_session] = lambda: session | ||
app.dependency_overrides[current_active_superuser] = lambda: admin | ||
app.dependency_overrides[current_active_superuser] = lambda: active_admin_user | ||
client = TestClient(app) | ||
yield client | ||
app.dependency_overrides.clear() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from fastapi.testclient import TestClient | ||
|
||
|
||
def test_auth_invalid_user(user_client: TestClient): | ||
response = user_client.get("/research/auth/") | ||
assert response.status_code == 401 | ||
|
||
|
||
def test_auth(research_client: TestClient): | ||
response = research_client.get("/research/auth/") | ||
assert response.status_code == 200 |