From 9b19cf26245538adefc9c64b266131dc98a2448f Mon Sep 17 00:00:00 2001 From: Omar Selo Date: Mon, 16 Sep 2024 12:38:13 +0000 Subject: [PATCH] Add is_confirmed to environment issue --- ...505b96fd7731_add_environmentissue_table.py | 1 + .../controllers/environments/models.py | 2 ++ .../environments/reported_issues.py | 1 + backend/test_observer/data_access/models.py | 1 + .../environments/test_environment_issues.py | 19 ++++++++++++++++++- 5 files changed, 23 insertions(+), 1 deletion(-) diff --git a/backend/migrations/versions/2024_09_16_1052-505b96fd7731_add_environmentissue_table.py b/backend/migrations/versions/2024_09_16_1052-505b96fd7731_add_environmentissue_table.py index 7109a602..5828bc3a 100644 --- a/backend/migrations/versions/2024_09_16_1052-505b96fd7731_add_environmentissue_table.py +++ b/backend/migrations/versions/2024_09_16_1052-505b96fd7731_add_environmentissue_table.py @@ -21,6 +21,7 @@ def upgrade() -> None: 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), diff --git a/backend/test_observer/controllers/environments/models.py b/backend/test_observer/controllers/environments/models.py index 747dd7ac..bb06aeca 100644 --- a/backend/test_observer/controllers/environments/models.py +++ b/backend/test_observer/controllers/environments/models.py @@ -9,6 +9,7 @@ class ReportedIssueRequest(BaseModel): environment_name: str description: str url: HttpUrl + is_confirmed: bool @field_validator("url") @classmethod @@ -25,5 +26,6 @@ class ReportedIssueResponse(BaseModel): environment_name: str description: str url: HttpUrl + is_confirmed: bool created_at: datetime updated_at: datetime diff --git a/backend/test_observer/controllers/environments/reported_issues.py b/backend/test_observer/controllers/environments/reported_issues.py index f169b7fe..7d586681 100644 --- a/backend/test_observer/controllers/environments/reported_issues.py +++ b/backend/test_observer/controllers/environments/reported_issues.py @@ -23,6 +23,7 @@ def create_reported_issue(request: ReportedIssueRequest, db: Session = Depends(g environment_name=request.environment_name, url=request.url, description=request.description, + is_confirmed=request.is_confirmed, ) db.add(issue) db.commit() diff --git a/backend/test_observer/data_access/models.py b/backend/test_observer/data_access/models.py index eb90fd95..ab805c82 100644 --- a/backend/test_observer/data_access/models.py +++ b/backend/test_observer/data_access/models.py @@ -490,6 +490,7 @@ class EnvironmentIssue(Base): environment_name: Mapped[str] url: Mapped[str] description: Mapped[str] + is_confirmed: Mapped[bool] def __repr__(self) -> str: return data_model_repr( diff --git a/backend/tests/controllers/environments/test_environment_issues.py b/backend/tests/controllers/environments/test_environment_issues.py index 321364c3..01ec1360 100644 --- a/backend/tests/controllers/environments/test_environment_issues.py +++ b/backend/tests/controllers/environments/test_environment_issues.py @@ -8,6 +8,7 @@ "environment_name": "template 1", "url": "https://github.com/", "description": "some description", + "is_confirmed": True, } @@ -17,7 +18,10 @@ def test_empty_get(test_client: TestClient): assert response.json() == [] -@pytest.mark.parametrize("field", ["url", "description", "environment_name"]) +@pytest.mark.parametrize( + "field", + ["url", "description", "environment_name", "is_confirmed"], +) def test_post_requires_field(test_client: TestClient, field: str): data = {k: v for k, v in valid_post_data.items() if k != field} response = test_client.post(endpoint, json=data) @@ -77,6 +81,19 @@ def test_update_description(test_client: TestClient): _assert_reported_issue(response.json()[0], issue) +def test_mark_unconfirmed(test_client: TestClient): + response = test_client.post(endpoint, json=valid_post_data) + issue = response.json() + issue["is_confirmed"] = False + response = test_client.put(f"{endpoint}/{issue['id']}", json=issue) + + assert response.status_code == 200 + _assert_reported_issue(response.json(), issue) + + response = test_client.get(endpoint) + _assert_reported_issue(response.json()[0], issue) + + def test_delete_issue(test_client: TestClient): response = test_client.post(endpoint, json=valid_post_data) issue_id = response.json()["id"]