-
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.
* Add delet route to achievements * Add tests for delete route * Change scope for delete route * Test fix (with potential bug) * Test fix for delete route * Fix test delete route * Fix doc in delete route * Fix test format * Fix response for delete route * Minor syntax fix
- Loading branch information
Showing
4 changed files
with
65 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
from pydantic import BaseModel, ConfigDict | ||
|
||
|
||
class Base(BaseModel): | ||
def __repr__(self) -> str: | ||
attrs = [] | ||
for k, v in self.__class__.model_json_schema().items(): | ||
attrs.append(f"{k}={v}") | ||
return "{}({})".format(self.__class__.__name__, ', '.join(attrs)) | ||
|
||
model_config = ConfigDict(from_attributes=True) | ||
|
||
|
||
class StatusResponseModel(Base): | ||
status: str | ||
message: str | ||
ru: str |
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,9 +1,26 @@ | ||
import pytest | ||
from fastapi.testclient import TestClient | ||
from sqlalchemy import create_engine | ||
from sqlalchemy.orm import sessionmaker | ||
|
||
from achievement_api.routes.base import app | ||
from achievement_api.settings import get_settings | ||
|
||
|
||
@pytest.fixture | ||
def client(): | ||
yield TestClient(app) | ||
|
||
|
||
@pytest.fixture(scope='session') | ||
def dbsession(): | ||
settings = get_settings() | ||
engine = create_engine(str(settings.DB_DSN)) | ||
TestingSessionLocal = sessionmaker(bind=engine) | ||
yield TestingSessionLocal() | ||
|
||
|
||
@pytest.fixture | ||
def achievement_id(client): | ||
post_response = client.post("/achievement", json={"name": "test name", "description": "test description"}) | ||
yield post_response.json()["id"] |
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,18 @@ | ||
import pytest | ||
|
||
from achievement_api.models.achievement import Achievement | ||
|
||
|
||
@pytest.mark.authenticated("achievements.achievement.create", "achievements.achievement.delete") | ||
def test_delete_existed(client, dbsession, achievement_id): | ||
delete_response = client.delete(f"/achievement/{achievement_id}") | ||
assert delete_response.status_code == 200 | ||
query = dbsession.get(Achievement, achievement_id) | ||
assert query is None | ||
|
||
|
||
@pytest.mark.authenticated("achievements.achievement.delete") | ||
def test_delete_unexisted(client): | ||
unexisted_id = -1 | ||
response = client.delete(f"/achievement/{unexisted_id}") | ||
assert response.status_code == 404 |