Skip to content

Commit

Permalink
Add created at datetime to artefact and test execution responses + re…
Browse files Browse the repository at this point in the history
…moves black checks (#258)

* Adds created_at to artefact responses
* Adds created_at to test execution responses
* Removes black dependence (since black and ruff disagreed)
  • Loading branch information
mz2 authored Feb 10, 2025
1 parent 869219e commit 4e07d7a
Show file tree
Hide file tree
Showing 14 changed files with 1,848 additions and 1,649 deletions.
1 change: 0 additions & 1 deletion .github/workflows/test_backend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ jobs:
with:
poetry-version: "1.8.2"
- run: poetry install
- run: poetry run black --check test_observer tests migrations scripts tasks
- run: poetry run ruff test_observer tests migrations scripts tasks
- run: poetry run mypy .
- run: poetry run pytest
Expand Down
2 changes: 1 addition & 1 deletion backend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ This project supports [microk8s](https://microk8s.io/) development environment w

While technically not required to run the code, it helps to have dependencies installed on host system to get code completions and linting. To do that just run `$ poetry install`. Note that poetry will create a virtual environment for you, but if you want poetry to create that virtual environment inside this project's directory just run `$ poetry config virtualenvs.in-project true` before installing dependencies.

Linting is done using ruff, formatting using black and type checking using mypy. We have CI in place to make those checks, but it's probably a good idea to setup your editor to use these. Note that their settings are in `pyproject.toml`.
Linting and formatting checks are done using ruff, and type checking using mypy. We have CI in place to make those checks, but it's probably a good idea to setup your editor to use these. Note that their settings are in `pyproject.toml`.

The project uses [pre-commit](https://pre-commit.com) to auto generate OpenAPI schema file. To set it up for your working copy of the repository:

Expand Down
5 changes: 0 additions & 5 deletions backend/charm/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@ show_missing = true
minversion = "6.0"
log_cli_level = "INFO"

# Formatting tools configuration
[tool.black]
line-length = 99
target-version = ["py38"]

# Linting tools configuration
[tool.ruff]
line-length = 99
Expand Down
3,381 changes: 1,792 additions & 1,589 deletions backend/poetry.lock

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion backend/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ celery = { extras = ["redis"], version = "^5.3.6" }
aiohttp = "^3.9.4"

[tool.poetry.group.dev.dependencies]
black = "^23.1.0"
mypy = "^1.3.0"
ruff = "^0.0.270"
types-requests = "^2.31.0.1"
Expand Down
79 changes: 39 additions & 40 deletions backend/schemata/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -1561,6 +1561,11 @@
],
"title": "Due Date"
},
"created_at": {
"type": "string",
"format": "date-time",
"title": "Created At"
},
"bug_link": {
"type": "string",
"title": "Bug Link"
Expand Down Expand Up @@ -1593,6 +1598,7 @@
"status",
"assignee",
"due_date",
"created_at",
"bug_link",
"all_environment_reviews_count",
"completed_environment_reviews_count"
Expand Down Expand Up @@ -1699,12 +1705,18 @@
"properties": {
"ci_link": {
"type": "string",
"maxLength": 2083,
"minLength": 1,
"format": "uri",
"title": "Ci Link"
},
"c3_link": {
"anyOf": [
{
"type": "string"
"type": "string",
"maxLength": 2083,
"minLength": 1,
"format": "uri"
},
{
"type": "null"
Expand Down Expand Up @@ -2008,7 +2020,10 @@
"ci_link": {
"anyOf": [
{
"type": "string"
"type": "string",
"maxLength": 2083,
"minLength": 1,
"format": "uri"
},
{
"type": "null"
Expand All @@ -2022,18 +2037,11 @@
"title": "Test Plan"
},
"initial_status": {
"allOf": [
{
"$ref": "#/components/schemas/TestExecutionStatus"
}
],
"$ref": "#/components/schemas/TestExecutionStatus",
"default": "IN_PROGRESS"
},
"family": {
"type": "string",
"enum": [
"charm"
],
"const": "charm",
"title": "Family"
},
Expand Down Expand Up @@ -2091,7 +2099,10 @@
"ci_link": {
"anyOf": [
{
"type": "string"
"type": "string",
"maxLength": 2083,
"minLength": 1,
"format": "uri"
},
{
"type": "null"
Expand All @@ -2105,18 +2116,11 @@
"title": "Test Plan"
},
"initial_status": {
"allOf": [
{
"$ref": "#/components/schemas/TestExecutionStatus"
}
],
"$ref": "#/components/schemas/TestExecutionStatus",
"default": "IN_PROGRESS"
},
"family": {
"type": "string",
"enum": [
"deb"
],
"const": "deb",
"title": "Family"
},
Expand Down Expand Up @@ -2172,7 +2176,10 @@
"ci_link": {
"anyOf": [
{
"type": "string"
"type": "string",
"maxLength": 2083,
"minLength": 1,
"format": "uri"
},
{
"type": "null"
Expand All @@ -2186,18 +2193,11 @@
"title": "Test Plan"
},
"initial_status": {
"allOf": [
{
"$ref": "#/components/schemas/TestExecutionStatus"
}
],
"$ref": "#/components/schemas/TestExecutionStatus",
"default": "IN_PROGRESS"
},
"family": {
"type": "string",
"enum": [
"image"
],
"const": "image",
"title": "Family",
"default": "image"
Expand Down Expand Up @@ -2271,7 +2271,10 @@
"ci_link": {
"anyOf": [
{
"type": "string"
"type": "string",
"maxLength": 2083,
"minLength": 1,
"format": "uri"
},
{
"type": "null"
Expand All @@ -2285,18 +2288,11 @@
"title": "Test Plan"
},
"initial_status": {
"allOf": [
{
"$ref": "#/components/schemas/TestExecutionStatus"
}
],
"$ref": "#/components/schemas/TestExecutionStatus",
"default": "IN_PROGRESS"
},
"family": {
"type": "string",
"enum": [
"snap"
],
"const": "snap",
"title": "Family"
},
Expand Down Expand Up @@ -2416,6 +2412,11 @@
"type": "string",
"title": "Test Plan"
},
"created_at": {
"type": "string",
"format": "date-time",
"title": "Created At"
},
"is_rerun_requested": {
"type": "boolean",
"title": "Is Rerun Requested",
Expand All @@ -2430,6 +2431,7 @@
"environment",
"status",
"test_plan",
"created_at",
"is_rerun_requested"
],
"title": "TestExecutionResponse"
Expand Down Expand Up @@ -2483,9 +2485,6 @@
},
{
"type": "string",
"enum": [
"COMPLETED"
],
"const": "COMPLETED"
},
{
Expand Down
4 changes: 3 additions & 1 deletion backend/test_observer/controllers/artefacts/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>.


from datetime import date
from datetime import date, datetime
from typing import Any

from pydantic import (
Expand Down Expand Up @@ -63,6 +63,7 @@ class ArtefactResponse(BaseModel):
status: ArtefactStatus
assignee: UserResponse | None
due_date: date | None
created_at: datetime
bug_link: str
all_environment_reviews_count: int
completed_environment_reviews_count: int
Expand All @@ -88,6 +89,7 @@ class TestExecutionResponse(BaseModel):
status: TestExecutionStatus
rerun_request: Any = Field(exclude=True)
test_plan: str
created_at: datetime

@computed_field
def is_rerun_requested(self) -> bool:
Expand Down
1 change: 1 addition & 0 deletions backend/tests/controllers/artefacts/test_artefacts.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ def _assert_get_artefact_response(response: dict[str, Any], artefact: Artefact)
"bug_link": artefact.bug_link,
"all_environment_reviews_count": artefact.all_environment_reviews_count,
"completed_environment_reviews_count": artefact.completed_environment_reviews_count, # noqa: E501
"created_at": artefact.created_at.isoformat(),
}
if artefact.assignee:
expected["assignee"] = {
Expand Down
4 changes: 4 additions & 0 deletions backend/tests/controllers/artefacts/test_builds.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def test_get_artefact_builds(test_client: TestClient, generator: DataGenerator):
},
"is_rerun_requested": False,
"test_plan": te.test_plan,
"created_at": te.created_at.isoformat(),
}
],
}
Expand Down Expand Up @@ -82,6 +83,7 @@ def test_get_artefact_builds_sorts_test_executions_by_environment_name(
},
"is_rerun_requested": False,
"test_plan": te1.test_plan,
"created_at": te1.created_at.isoformat(),
},
{
"id": te2.id,
Expand All @@ -95,6 +97,7 @@ def test_get_artefact_builds_sorts_test_executions_by_environment_name(
},
"is_rerun_requested": False,
"test_plan": te2.test_plan,
"created_at": te2.created_at.isoformat(),
},
],
}
Expand Down Expand Up @@ -151,6 +154,7 @@ def test_get_artefact_builds_with_rerun_requested(
},
"is_rerun_requested": True,
"test_plan": te.test_plan,
"created_at": te.created_at.isoformat(),
}
],
}
Expand Down
4 changes: 4 additions & 0 deletions backend/tests/controllers/test_executions/test_reruns.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ def test_execution_to_pending_rerun(test_execution: TestExecution) -> dict:
"status": test_execution.status,
"test_plan": test_execution.test_plan,
"is_rerun_requested": bool(test_execution.rerun_request),
"created_at": test_execution.created_at.isoformat(),
},
"artefact": {
"id": test_execution.artefact_build.artefact.id,
Expand All @@ -104,6 +105,9 @@ def test_execution_to_pending_rerun(test_execution: TestExecution) -> dict:
test_execution.artefact_build.artefact.completed_environment_reviews_count
),
"family": test_execution.artefact_build.artefact.family,
"created_at": (
test_execution.artefact_build.artefact.created_at.isoformat()
),
},
"artefact_build": {
"id": test_execution.artefact_build.id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ def _assert_objects_created(
assert artefact.release == request.get("release", "")
assert artefact.sha256 == request.get("sha256", "")
assert artefact.owner == request.get("owner", "")
assert artefact.image_url == request.get("image_url", "")
assert artefact.image_url == str(request.get("image_url", ''))
assert artefact.store == request.get("store", "")
assert artefact.track == request.get("track", "")
assert artefact.series == request.get("series", "")
Expand Down
4 changes: 3 additions & 1 deletion backend/tests/data_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,9 @@ def gen_image(
sha256: str = "e71fb5681e63330445eec6fc3fe043f36"
"5289c2e595e3ceeac08fbeccfb9a957",
owner: str = "foundations",
image_url: str = "https://cdimage.ubuntu.com/noble/daily-live/20240827/noble-desktop-amd64.iso",
image_url: str = (
"https://cdimage.ubuntu.com/noble/daily-live/20240827/noble-desktop-amd64.iso"
),
created_at: datetime | None = None,
status: ArtefactStatus = ArtefactStatus.UNDECIDED,
bug_link: str = "",
Expand Down
5 changes: 0 additions & 5 deletions frontend/charm/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@ show_missing = true
minversion = "6.0"
log_cli_level = "INFO"

# Formatting tools configuration
[tool.black]
line-length = 99
target-version = ["py38"]

# Linting tools configuration
[tool.ruff]
line-length = 99
Expand Down
4 changes: 0 additions & 4 deletions frontend/charm/tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,13 @@ pass_env =
[testenv:static]
description = Apply coding style standards to code
deps =
black
ruff
commands =
black {[vars]all_path}
ruff check {[vars]all_path}

[testenv:lint]
description = Check code against coding style standards
deps =
black
ruff
codespell
commands =
Expand All @@ -44,7 +41,6 @@ commands =
# codespell {[vars]lib_path}
codespell {tox_root}
ruff check {[vars]all_path}
black --check --diff {[vars]all_path}

[testenv:unit]
description = Run unit tests
Expand Down

0 comments on commit 4e07d7a

Please sign in to comment.