-
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 missing field from repr * Add support for environment issues to the backend * Require issue url be github, jira, or launchpad * Add is_confirmed to environment issue * Include environment issues in seed_script * Fix seed script * Environment issues frontend * Minor improvements * Some code improvements * Add non-blocking provider preloader * Refactor loading providers to a widget * Fix missing event log expandable
- Loading branch information
Showing
34 changed files
with
980 additions
and
170 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
backend/migrations/versions/2024_09_16_1052-505b96fd7731_add_environmentissue_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,33 @@ | ||
"""Add EnvironmentIssue table | ||
Revision ID: 505b96fd7731 | ||
Revises: ba6550a03bc8 | ||
Create Date: 2024-09-16 10:52:25.226261+00:00 | ||
""" | ||
import sqlalchemy as sa | ||
from alembic import op | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = "505b96fd7731" | ||
down_revision = "ba6550a03bc8" | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade() -> None: | ||
op.create_table( | ||
"environment_issue", | ||
sa.Column("environment_name", sa.String(), nullable=False), | ||
sa.Column("url", sa.String(), nullable=False), | ||
sa.Column("description", sa.String(), nullable=False), | ||
sa.Column("is_confirmed", sa.Boolean(), 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("environment_issue_pkey")), | ||
) | ||
|
||
|
||
def downgrade() -> None: | ||
op.drop_table("environment_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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
PREVIOUS_TEST_RESULT_COUNT = 10 | ||
|
||
VALID_ISSUE_HOSTS = {"github.com", "warthogs.atlassian.net", "bugs.launchpad.net"} |
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=["environments"]) | ||
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,31 @@ | ||
from datetime import datetime | ||
|
||
from pydantic import BaseModel, HttpUrl, field_validator | ||
|
||
from test_observer.common.constants import VALID_ISSUE_HOSTS | ||
|
||
|
||
class EnvironmentReportedIssueRequest(BaseModel): | ||
environment_name: str | ||
description: str | ||
url: HttpUrl | ||
is_confirmed: bool | ||
|
||
@field_validator("url") | ||
@classmethod | ||
def url_host_must_be_allowed( | ||
cls: type["EnvironmentReportedIssueRequest"], url: HttpUrl | ||
) -> HttpUrl: | ||
if url.host not in VALID_ISSUE_HOSTS: | ||
raise ValueError(f"Issue url must belong to one of {VALID_ISSUE_HOSTS}") | ||
return url | ||
|
||
|
||
class EnvironmentReportedIssueResponse(BaseModel): | ||
id: int | ||
environment_name: str | ||
description: str | ||
url: HttpUrl | ||
is_confirmed: bool | ||
created_at: datetime | ||
updated_at: datetime |
52 changes: 52 additions & 0 deletions
52
backend/test_observer/controllers/environments/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,52 @@ | ||
from fastapi import APIRouter, Depends | ||
from sqlalchemy import select | ||
from sqlalchemy.orm import Session | ||
|
||
from test_observer.data_access.models import EnvironmentIssue | ||
from test_observer.data_access.setup import get_db | ||
|
||
from .models import EnvironmentReportedIssueRequest, EnvironmentReportedIssueResponse | ||
|
||
router = APIRouter() | ||
|
||
endpoint = "/reported-issues" | ||
|
||
|
||
@router.get(endpoint, response_model=list[EnvironmentReportedIssueResponse]) | ||
def get_reported_issues(db: Session = Depends(get_db)): | ||
return db.execute(select(EnvironmentIssue)).scalars() | ||
|
||
|
||
@router.post(endpoint, response_model=EnvironmentReportedIssueResponse) | ||
def create_reported_issue( | ||
request: EnvironmentReportedIssueRequest, db: Session = Depends(get_db) | ||
): | ||
issue = EnvironmentIssue( | ||
environment_name=request.environment_name, | ||
url=request.url, | ||
description=request.description, | ||
is_confirmed=request.is_confirmed, | ||
) | ||
db.add(issue) | ||
db.commit() | ||
|
||
return issue | ||
|
||
|
||
@router.put(endpoint + "/{issue_id}", response_model=EnvironmentReportedIssueResponse) | ||
def update_reported_issue( | ||
issue_id: int, | ||
request: EnvironmentReportedIssueRequest, | ||
db: Session = Depends(get_db), | ||
): | ||
issue = db.get(EnvironmentIssue, 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(EnvironmentIssue, 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
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,8 @@ | ||
from httpx import Response | ||
|
||
|
||
def assert_fails_validation(response: Response, field: str, type: str) -> None: | ||
assert response.status_code == 422 | ||
problem = response.json()["detail"][0] | ||
assert problem["type"] == type | ||
assert problem["loc"] == ["body", field] |
Oops, something went wrong.