-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test case issue reporting (#207)
* Add test case reported issues * Add put and delete endpoints * Return template_id with test results * Add test case name to test case issues * Allow filtering issues by case name * Add some reported issues to seed script * Merge migrations * Add some reported issues to seed script * typo Co-authored-by: Nadzeya H <[email protected]> * Capitalize error message Co-authored-by: Nadzeya H <[email protected]> --------- Co-authored-by: Nadzeya H <[email protected]>
- Loading branch information
Showing
10 changed files
with
382 additions
and
3 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
backend/migrations/versions/2024_08_30_1303-ba6550a03bc8_add_testcaseissue_table.py
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,47 @@ | ||
"""Add TestCaseIssue table | ||
Revision ID: ba6550a03bc8 | ||
Revises: 2745d4e5bc72 | ||
Create Date: 2024-08-30 13:03:39.864116+00:00 | ||
""" | ||
import sqlalchemy as sa | ||
from alembic import op | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = "ba6550a03bc8" | ||
down_revision = "2745d4e5bc72" | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade() -> None: | ||
op.create_table( | ||
"test_case_issue", | ||
sa.Column("template_id", sa.String(), nullable=False), | ||
sa.Column("case_name", sa.String(), nullable=False), | ||
sa.Column("url", sa.String(), nullable=False), | ||
sa.Column("description", sa.String(), nullable=False), | ||
sa.Column("id", sa.Integer(), autoincrement=True, nullable=False), | ||
sa.Column("created_at", sa.DateTime(), nullable=False), | ||
sa.Column("updated_at", sa.DateTime(), nullable=False), | ||
sa.PrimaryKeyConstraint("id", name=op.f("test_case_issue_pkey")), | ||
) | ||
op.create_index( | ||
op.f("test_case_issue_case_name_ix"), | ||
"test_case_issue", | ||
["case_name"], | ||
unique=False, | ||
) | ||
op.create_index( | ||
op.f("test_case_issue_template_id_ix"), | ||
"test_case_issue", | ||
["template_id"], | ||
unique=False, | ||
) | ||
|
||
|
||
def downgrade() -> None: | ||
op.drop_index(op.f("test_case_issue_template_id_ix"), table_name="test_case_issue") | ||
op.drop_index(op.f("test_case_issue_case_name_ix"), table_name="test_case_issue") | ||
op.drop_table("test_case_issue") |
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,6 @@ | ||
from fastapi import APIRouter | ||
|
||
from . import reported_issues | ||
|
||
router = APIRouter(tags=["test-cases"]) | ||
router.include_router(reported_issues.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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from datetime import datetime | ||
|
||
from pydantic import BaseModel, HttpUrl, model_validator | ||
|
||
|
||
class ReportedIssueRequest(BaseModel): | ||
template_id: str = "" | ||
case_name: str = "" | ||
description: str | ||
url: HttpUrl | ||
|
||
@model_validator(mode="after") | ||
def check_a_or_b(self): | ||
if not self.case_name and not self.template_id: | ||
raise ValueError("Either case_name or template_id is required") | ||
return self | ||
|
||
|
||
class ReportedIssueResponse(BaseModel): | ||
id: int | ||
template_id: str = "" | ||
case_name: str = "" | ||
description: str | ||
url: HttpUrl | ||
created_at: datetime | ||
updated_at: datetime |
58 changes: 58 additions & 0 deletions
58
backend/test_observer/controllers/test_cases/reported_issues.py
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,58 @@ | ||
from fastapi import APIRouter, Depends | ||
from sqlalchemy import select | ||
from sqlalchemy.orm import Session | ||
|
||
from test_observer.data_access.models import TestCaseIssue | ||
from test_observer.data_access.setup import get_db | ||
|
||
from .models import ReportedIssueRequest, ReportedIssueResponse | ||
|
||
router = APIRouter() | ||
|
||
|
||
endpoint = "/reported-issues" | ||
|
||
|
||
@router.get(endpoint, response_model=list[ReportedIssueResponse]) | ||
def get_reported_issues( | ||
template_id: str | None = None, | ||
case_name: str | None = None, | ||
db: Session = Depends(get_db), | ||
): | ||
stmt = select(TestCaseIssue) | ||
if template_id: | ||
stmt = stmt.where(TestCaseIssue.template_id == template_id) | ||
if case_name: | ||
stmt = stmt.where(TestCaseIssue.case_name == case_name) | ||
return db.execute(stmt).scalars() | ||
|
||
|
||
@router.post(endpoint, response_model=ReportedIssueResponse) | ||
def create_reported_issue(request: ReportedIssueRequest, db: Session = Depends(get_db)): | ||
issue = TestCaseIssue( | ||
template_id=request.template_id, | ||
url=request.url, | ||
description=request.description, | ||
case_name=request.case_name, | ||
) | ||
db.add(issue) | ||
db.commit() | ||
|
||
return issue | ||
|
||
|
||
@router.put(endpoint + "/{issue_id}", response_model=ReportedIssueResponse) | ||
def update_reported_issue( | ||
issue_id: int, request: ReportedIssueRequest, db: Session = Depends(get_db) | ||
): | ||
issue = db.get(TestCaseIssue, issue_id) | ||
for field in request.model_fields: | ||
setattr(issue, field, getattr(request, field)) | ||
db.commit() | ||
return issue | ||
|
||
|
||
@router.delete(endpoint + "/{issue_id}") | ||
def delete_reported_issue(issue_id: int, db: Session = Depends(get_db)): | ||
db.delete(db.get(TestCaseIssue, issue_id)) | ||
db.commit() |
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 |
---|---|---|
|
@@ -18,10 +18,10 @@ | |
# Omar Selo <[email protected]> | ||
|
||
|
||
from datetime import datetime | ||
from enum import Enum | ||
from typing import Annotated | ||
|
||
from datetime import datetime | ||
from pydantic import ( | ||
AliasPath, | ||
BaseModel, | ||
|
@@ -143,6 +143,7 @@ class TestResultDTO(BaseModel): | |
id: int | ||
name: str = Field(validation_alias=AliasPath("test_case", "name")) | ||
category: str = Field(validation_alias=AliasPath("test_case", "category")) | ||
template_id: str = Field(validation_alias=AliasPath("test_case", "template_id")) | ||
status: TestResultStatus | ||
comment: str | ||
io_log: 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
Oops, something went wrong.