-
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.
Add is_researcher boolean flag to User
- add empty `/researcher/auth` endpoint to test researcher authentification
- Loading branch information
Showing
8 changed files
with
87 additions
and
6 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 | ||
|
@@ -123,6 +124,19 @@ def admin(): | |
email="[email protected]", | ||
is_active=True, | ||
is_superuser=True, | ||
is_researcher=False, | ||
is_verified=True, | ||
) | ||
|
||
|
||
@pytest.fixture | ||
def research(): | ||
UserRead( | ||
id=2, | ||
email="[email protected]", | ||
is_active=True, | ||
is_superuser=False, | ||
is_researcher=True, | ||
is_verified=True, | ||
) | ||
|
||
|
@@ -134,6 +148,7 @@ def user(): | |
email="[email protected]", | ||
is_active=True, | ||
is_superuser=False, | ||
is_researcher=False, | ||
is_verified=True, | ||
) | ||
|
||
|
@@ -156,6 +171,17 @@ def user_client( | |
app.dependency_overrides.clear() | ||
|
||
|
||
@pytest.fixture | ||
def research_client( | ||
app: FastAPI, static_dir: pathlib.Path, session: Session, research: UserRead | ||
): | ||
app.dependency_overrides[get_session] = lambda: session | ||
app.dependency_overrides[current_active_researcher] = lambda: research | ||
client = TestClient(app) | ||
yield client | ||
app.dependency_overrides.clear() | ||
|
||
|
||
@pytest.fixture | ||
def admin_client( | ||
app: FastAPI, static_dir: pathlib.Path, session: Session, admin: UserRead | ||
|
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 |