-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactored project routers to encapsulate db interaction a ProjectSto…
…re dependency
- Loading branch information
1 parent
039a92e
commit 069219e
Showing
7 changed files
with
205 additions
and
84 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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
from .client import * # noqa: F403, F401 | ||
from .database import * # noqa: F403, F401 | ||
from .overrides import * # noqa: F403, F401 |
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,52 @@ | ||
import uuid | ||
|
||
import pytest | ||
from api.app import app | ||
from api.auth.users import current_active_user | ||
from api.routers.projects import ProjectStore, ReadProject | ||
from fastapi import HTTPException, status | ||
|
||
|
||
class ProjectDictStore: | ||
projects: dict[uuid.UUID, ReadProject] = {} | ||
|
||
async def get(self, project_id): | ||
try: | ||
return self.projects[project_id] | ||
except KeyError: | ||
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND) | ||
|
||
async def get_all(self): | ||
return self.projects.values() | ||
|
||
async def create(self, project): | ||
project_id = uuid.uuid4() | ||
project_entry = ReadProject(**project.model_dump(), id=project_id) | ||
self.projects[project_id] = project_entry | ||
return project_entry | ||
|
||
async def update(self, project_id, project): | ||
project_entry = await self.get(project_id) | ||
project_entry.title = project.title | ||
project_entry.summary = project.summary | ||
project_entry.status = project.status | ||
return project_entry | ||
|
||
async def delete(self, project_id): | ||
await self.get(project_id) | ||
del self.projects[project_id] | ||
return None | ||
|
||
|
||
@pytest.fixture | ||
def override_project_store(): | ||
app.dependency_overrides[ProjectStore] = ProjectDictStore | ||
yield | ||
del app.dependency_overrides[ProjectStore] | ||
|
||
|
||
@pytest.fixture | ||
def override_active_user(): | ||
app.dependency_overrides[current_active_user] = lambda: {} | ||
yield | ||
del app.dependency_overrides[current_active_user] |
Oops, something went wrong.