Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Receive ci link at start test & rename jenkins to ci #67

Merged
merged 5 commits into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
"""Rename jenkins_link to ci_link

Revision ID: 8d8643821588
Revises: 49221114815a
Create Date: 2023-12-01 09:49:44.849714+00:00

"""
from alembic import op

# revision identifiers, used by Alembic.
revision = "8d8643821588"
down_revision = "49221114815a"
branch_labels = None
depends_on = None


def upgrade() -> None:
op.alter_column("test_execution", "jenkins_link", new_column_name="ci_link")


def downgrade() -> None:
op.alter_column("test_execution", "ci_link", new_column_name="jenkins_link")
11 changes: 10 additions & 1 deletion backend/scripts/seed_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
arch="armhf",
execution_stage="beta",
environment="rpi2",
ci_link="http://localhost",
),
StartTestExecutionRequest(
family=FamilyName.SNAP,
Expand All @@ -29,6 +30,7 @@
arch="armhf",
execution_stage="beta",
environment="rpi2",
ci_link="http://localhost",
),
StartTestExecutionRequest(
family=FamilyName.SNAP,
Expand All @@ -40,6 +42,7 @@
arch="armhf",
execution_stage="beta",
environment="rpi2",
ci_link="http://localhost",
),
StartTestExecutionRequest(
family=FamilyName.SNAP,
Expand All @@ -51,6 +54,7 @@
arch="amd64",
execution_stage="edge",
environment="dawson-i",
ci_link="http://localhost",
),
StartTestExecutionRequest(
family=FamilyName.SNAP,
Expand All @@ -62,6 +66,7 @@
arch="arm64",
execution_stage="candidate",
environment="cm3",
ci_link="http://localhost",
),
StartTestExecutionRequest(
family=FamilyName.SNAP,
Expand All @@ -73,6 +78,7 @@
arch="arm64",
execution_stage="stable",
environment="cm3",
ci_link="http://localhost",
),
StartTestExecutionRequest(
family=FamilyName.SNAP,
Expand All @@ -84,6 +90,7 @@
arch="arm64",
execution_stage="stable",
environment="dragonboard",
ci_link="http://localhost",
),
StartTestExecutionRequest(
family=FamilyName.DEB,
Expand All @@ -94,6 +101,7 @@
arch="arm64",
execution_stage="proposed",
environment="rpi400",
ci_link="http://localhost",
),
StartTestExecutionRequest(
family=FamilyName.DEB,
Expand All @@ -104,14 +112,15 @@
arch="arm64",
execution_stage="updates",
environment="rpi400",
ci_link="http://localhost",
),
]


def seed_data(client: TestClient | requests.Session):
for request in REQUESTS:
client.put(
START_TEST_EXECUTION_URL, json=request.model_dump()
START_TEST_EXECUTION_URL, json=request.model_dump(mode="json")
).raise_for_status()


Expand Down
2 changes: 1 addition & 1 deletion backend/test_observer/controllers/artefacts/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class TestExecutionDTO(BaseModel):
model_config = ConfigDict(from_attributes=True)

id: int
jenkins_link: str | None
ci_link: str | None
c3_link: str | None
environment: EnvironmentDTO
status: TestExecutionStatus
Expand Down
11 changes: 7 additions & 4 deletions backend/test_observer/controllers/test_executions/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
# Omar Selo <[email protected]>


from pydantic import BaseModel, field_serializer, model_validator
from typing import Annotated

from pydantic import BaseModel, HttpUrl, field_serializer, model_validator

from test_observer.data_access.models_enums import FamilyName, TestExecutionStatus

Expand All @@ -35,6 +37,7 @@ class StartTestExecutionRequest(BaseModel):
arch: str
execution_stage: str
environment: str
ci_link: Annotated[str, HttpUrl]

@field_serializer("family")
def serialize_dt(self, family: FamilyName):
Expand All @@ -56,6 +59,6 @@ def validate_required_fields(self) -> "StartTestExecutionRequest":


class TestExecutionsPatchRequest(BaseModel):
c3_link: str
jenkins_link: str
status: TestExecutionStatus
c3_link: HttpUrl | None
ci_link: HttpUrl | None
status: TestExecutionStatus | None
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ def start_test_execution(
},
creation_kwargs={
"status": TestExecutionStatus.IN_PROGRESS,
"ci_link": request.ci_link,
},
)
return {"id": test_execution.id}
Expand All @@ -104,8 +105,18 @@ def patch_test_execution(
request: TestExecutionsPatchRequest,
db: Session = Depends(get_db),
):
test_execution = db.query(TestExecution).filter(TestExecution.id == id).one()
test_execution.c3_link = request.c3_link
test_execution.jenkins_link = request.jenkins_link
test_execution.status = request.status
test_execution = db.get(TestExecution, id)

if test_execution is None:
raise HTTPException(status_code=404, detail="TestExecution not found")

if request.c3_link is not None:
test_execution.c3_link = str(request.c3_link)

if request.ci_link is not None:
test_execution.ci_link = str(request.ci_link)

if request.status is not None:
test_execution.status = request.status

db.commit()
6 changes: 3 additions & 3 deletions backend/test_observer/data_access/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,8 @@ class TestExecution(Base):

__tablename__ = "test_execution"

jenkins_link: Mapped[str] = mapped_column(String(200), nullable=True)
c3_link: Mapped[str] = mapped_column(String(200), nullable=True)
ci_link: Mapped[str | None] = mapped_column(String(200), nullable=True)
c3_link: Mapped[str | None] = mapped_column(String(200), nullable=True)
# Relationships
artefact_build_id: Mapped[int] = mapped_column(
ForeignKey("artefact_build.id", ondelete="CASCADE")
Expand All @@ -222,6 +222,6 @@ def __repr__(self) -> str:
"artefact_build_id",
"environment_id",
"status",
"jenkins_link",
"ci_link",
"c3_link",
)
2 changes: 1 addition & 1 deletion backend/tests/controllers/artefacts/test_artefacts.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def test_get_artefact_builds(db_session: Session, test_client: TestClient):
"test_executions": [
{
"id": test_execution.id,
"jenkins_link": test_execution.jenkins_link,
"ci_link": test_execution.ci_link,
"c3_link": test_execution.c3_link,
"status": test_execution.status.value,
"environment": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def test_creates_all_data_models(db_session: Session, test_client: TestClient):
"arch": "arm64",
"execution_stage": "beta",
"environment": "cm3",
"ci_link": "http://localhost",
},
)

Expand Down Expand Up @@ -109,6 +110,7 @@ def test_invalid_artefact_format(test_client: TestClient):
"arch": "arm64",
"execution_stage": "beta",
"environment": "cm3",
"ci_link": "http://localhost",
},
)
assert response.status_code == 422
Expand All @@ -125,6 +127,7 @@ def test_uses_existing_models(db_session: Session, test_client: TestClient):
arch="arm64",
execution_stage="beta",
environment="cm3",
ci_link="http://localhost/",
)
stage = (
db_session.query(Stage).filter(Stage.name == request.execution_stage).first()
Expand All @@ -151,7 +154,7 @@ def test_uses_existing_models(db_session: Session, test_client: TestClient):

test_execution_id = test_client.put(
"/v1/test-executions/start-test",
json=request.model_dump(),
json=request.model_dump(mode="json"),
).json()["id"]

test_execution = (
Expand All @@ -163,6 +166,7 @@ def test_uses_existing_models(db_session: Session, test_client: TestClient):
assert test_execution.artefact_build_id == artefact_build.id
assert test_execution.environment_id == environment.id
assert test_execution.status == TestExecutionStatus.IN_PROGRESS
assert test_execution.ci_link == "http://localhost/"


def test_updates_test_execution(db_session: Session, test_client: TestClient):
Expand All @@ -180,13 +184,13 @@ def test_updates_test_execution(db_session: Session, test_client: TestClient):
test_client.patch(
f"/v1/test-executions/{test_execution.id}",
json={
"jenkins_link": "some jenkins link",
"c3_link": "some c3 link",
"ci_link": "http://ci_link/",
"c3_link": "http://c3_link/",
"status": TestExecutionStatus.PASSED.name,
},
)

db_session.refresh(test_execution)
assert test_execution.jenkins_link == "some jenkins link"
assert test_execution.c3_link == "some c3 link"
assert test_execution.ci_link == "http://ci_link/"
assert test_execution.c3_link == "http://c3_link/"
assert test_execution.status == TestExecutionStatus.PASSED
2 changes: 1 addition & 1 deletion frontend/lib/models/test_execution.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ part 'test_execution.g.dart';
class TestExecution with _$TestExecution {
const factory TestExecution({
required int id,
@JsonKey(name: 'jenkins_link') required String? jenkinsLink,
@JsonKey(name: 'ci_link') required String? ciLink,
@JsonKey(name: 'c3_link') required String? c3Link,
required TestExecutionStatus status,
required Environment environment,
Expand Down
8 changes: 4 additions & 4 deletions frontend/lib/ui/dashboard/artefact_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ class _TestExecutionView extends StatelessWidget {

@override
Widget build(BuildContext context) {
final jenkinsLink = testExecution.jenkinsLink;
final ciLink = testExecution.ciLink;
final c3Link = testExecution.c3Link;

return YaruExpandable(
Expand All @@ -286,10 +286,10 @@ class _TestExecutionView extends StatelessWidget {
const Spacer(),
Row(
children: [
if (jenkinsLink != null)
if (ciLink != null)
InlineUrlText(
url: jenkinsLink,
urlText: 'Jenkins',
url: ciLink,
urlText: 'CI',
),
const SizedBox(width: Spacing.level3),
if (c3Link != null)
Expand Down