Skip to content

Commit

Permalink
Rename historic to previous
Browse files Browse the repository at this point in the history
  • Loading branch information
andrejvelichkovski committed Jan 11, 2024
1 parent b27f2c2 commit f285aef
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 37 deletions.
2 changes: 1 addition & 1 deletion backend/test_observer/common/constants.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
HISTORIC_TEST_RESULT_COUNT = 10
PREVIOUS_TEST_RESULT_COUNT = 10
12 changes: 6 additions & 6 deletions backend/test_observer/controllers/test_executions/helpers.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
from itertools import groupby
from .models import HistoricTestResult
from .models import PreviousTestResult
from test_observer.data_access.models import TestResult


def parse_historic_test_results(
historic_test_results: list[TestResult],
) -> dict[int, list[HistoricTestResult]]:
def parse_previous_test_results(
previous_test_results: list[TestResult],
) -> dict[int, list[PreviousTestResult]]:
grouped_test_cases = groupby(
historic_test_results, lambda test_result: test_result.test_case_id
previous_test_results, lambda test_result: test_result.test_case_id
)

return {
test_case_id: [
HistoricTestResult(
PreviousTestResult(
status=test_result.status,
version=test_result.test_execution.artefact_build.artefact.version,
)
Expand Down
20 changes: 10 additions & 10 deletions backend/test_observer/controllers/test_executions/logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from sqlalchemy.orm import Session, joinedload
from sqlalchemy.orm.query import RowReturningQuery

from test_observer.common.constants import HISTORIC_TEST_RESULT_COUNT
from test_observer.common.constants import PREVIOUS_TEST_RESULT_COUNT
from test_observer.data_access.models import (
Artefact,
ArtefactBuild,
Expand Down Expand Up @@ -60,13 +60,13 @@ def parse_c3_test_result_status(status: C3TestResultStatus) -> TestResultStatus:
return TestResultStatus.SKIPPED


def get_historic_artefact_builds_query(
def get_previous_artefact_builds_query(
session: Session,
artefact: Artefact,
architecture: str,
) -> RowReturningQuery:
"""
Helper method to get a query that fetches the latest Artefact Build IDs
Helper method to get a query that fetches the previous Artefact Build IDs
for given Artefact object identifiers (name, track, repo, store) and architecture.
The query only returns the latest revision build for each Artefact, in case there
Expand Down Expand Up @@ -100,13 +100,13 @@ def get_historic_artefact_builds_query(
)


def get_historic_test_executions_query(
def get_previous_test_executions_query(
session: Session,
test_execution: TestExecution,
artefact_build_query: RowReturningQuery,
) -> RowReturningQuery:
"""
Helper method to get a query that fetches the latest Test Execution IDs
Helper method to get a query that fetches the previous Test Execution IDs
for all test executions that come from the artefact_build_ids subquery.
The query returns only the test executions that belong to the same environment
Expand All @@ -130,16 +130,16 @@ def get_historic_test_executions_query(
TestExecution.id < test_execution.id,
)
.order_by(desc(TestExecution.id))
.limit(HISTORIC_TEST_RESULT_COUNT)
.limit(PREVIOUS_TEST_RESULT_COUNT)
)


def get_historic_test_results(
def get_previous_test_results(
session: Session,
test_execution: TestExecution,
) -> list[TestResult]:
"""
Helper method to get the historic test results (10 latest) for
Helper method to get the previous test results (10 latest) for
a given Test Execution object
Parameters:
Expand All @@ -151,12 +151,12 @@ def get_historic_test_results(
received as input
"""

artefact_builds_query = get_historic_artefact_builds_query(
artefact_builds_query = get_previous_artefact_builds_query(
session=session,
artefact=test_execution.artefact_build.artefact,
architecture=test_execution.artefact_build.architecture,
)
test_executions_query = get_historic_test_executions_query(
test_executions_query = get_previous_test_executions_query(
session=session,
test_execution=test_execution,
artefact_build_query=artefact_builds_query,
Expand Down
12 changes: 7 additions & 5 deletions backend/test_observer/controllers/test_executions/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
model_validator,
)

from test_observer.common.constants import PREVIOUS_TEST_RESULT_COUNT
from test_observer.data_access.models_enums import (
FamilyName,
TestExecutionReviewDecision,
Expand Down Expand Up @@ -125,7 +126,7 @@ def validate_review_decision(
return review_decision


class HistoricTestResult(BaseModel):
class PreviousTestResult(BaseModel):
status: TestResultStatus
version: str

Expand All @@ -139,11 +140,12 @@ class TestResultDTO(BaseModel):
status: TestResultStatus
comment: str
io_log: str
historic_results: list[HistoricTestResult] = Field(
previous_results: list[PreviousTestResult] = Field(
default=[],
description=(
"The last 10 test results matched with the current test execution. "
"The items are sorted in descending order, the first historic test "
"result is the most recent, while the last one is the oldest one."
f"The last {PREVIOUS_TEST_RESULT_COUNT} test results matched with "
"the current test execution. The items are sorted in descending order, "
"the first test result is the most recent, while "
"the last one is the oldest one."
),
)
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@

from test_observer.controllers.artefacts.models import TestExecutionDTO
from test_observer.controllers.test_executions.helpers import (
parse_historic_test_results,
parse_previous_test_results,
)
from test_observer.controllers.test_executions.logic import (
compute_test_execution_status,
store_test_results,
get_historic_test_results,
get_previous_test_results,
)
from test_observer.data_access.models import (
Artefact,
Expand Down Expand Up @@ -194,13 +194,13 @@ def get_test_results(id: int, db: Session = Depends(get_db)):
if test_execution is None:
raise HTTPException(status_code=404, detail="TestExecution not found")

historic_test_results = get_historic_test_results(db, test_execution)
parsed_historic_test_results = parse_historic_test_results(historic_test_results)
previous_test_results = get_previous_test_results(db, test_execution)
parsed_previous_test_results = parse_previous_test_results(previous_test_results)

test_results: list[TestResultDTO] = []
for test_result in test_execution.test_results:
parsed_test_result = TestResultDTO.model_validate(test_result)
parsed_test_result.historic_results = parsed_historic_test_results.get(
parsed_test_result.previous_results = parsed_previous_test_results.get(
test_result.test_case_id, []
)
test_results.append(parsed_test_result)
Expand Down
18 changes: 9 additions & 9 deletions backend/tests/controllers/test_executions/test_logic.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from sqlalchemy.orm import Session

from test_observer.controllers.test_executions.logic import (
get_historic_artefact_builds_query,
get_historic_test_executions_query,
get_previous_artefact_builds_query,
get_previous_test_executions_query,
)
from test_observer.data_access.models import (
Artefact,
Expand Down Expand Up @@ -31,7 +31,7 @@ def _get_test_execution(
return test_execution


def test_get_historic_artefact_builds_query(db_session: Session):
def test_get_previous_artefact_builds_query(db_session: Session):
stage = db_session.query(Stage).filter(Stage.name == "beta").first()

artefact_one = Artefact(name="some artefact", version="1.0.0", stage=stage)
Expand All @@ -49,7 +49,7 @@ def test_get_historic_artefact_builds_query(db_session: Session):
db_session.add_all([artefact_two, artefact_build_two, artefact_build_three])
db_session.commit()

artefact_builds_query = get_historic_artefact_builds_query(
artefact_builds_query = get_previous_artefact_builds_query(
session=db_session,
artefact=artefact_one,
architecture=artefact_build_two.architecture,
Expand All @@ -61,7 +61,7 @@ def test_get_historic_artefact_builds_query(db_session: Session):
]


def test_get_historic_artefact_builds_query_returns_latest_revision_build(
def test_get_previous_artefact_builds_query_returns_latest_revision_build(
db_session: Session,
):
stage = db_session.query(Stage).filter(Stage.name == "beta").first()
Expand All @@ -82,7 +82,7 @@ def test_get_historic_artefact_builds_query_returns_latest_revision_build(
)
db_session.commit()

artefact_builds_query = get_historic_artefact_builds_query(
artefact_builds_query = get_previous_artefact_builds_query(
session=db_session,
artefact=artefact_one,
architecture=artefact_build_two.architecture,
Expand All @@ -93,7 +93,7 @@ def test_get_historic_artefact_builds_query_returns_latest_revision_build(
]


def test_get_historic_test_executions_query(db_session: Session):
def test_get_previous_test_executions_query(db_session: Session):
environment_one = Environment(name="some environment", architecture="some arch")
db_session.add(environment_one)
db_session.commit()
Expand All @@ -114,7 +114,7 @@ def test_get_historic_test_executions_query(db_session: Session):
db_session, environment_one, "https://example3"
)

artefact_build_query = get_historic_artefact_builds_query(
artefact_build_query = get_previous_artefact_builds_query(
session=db_session,
artefact=test_execution_one.artefact_build.artefact,
architecture=test_execution_one.artefact_build.architecture,
Expand All @@ -126,7 +126,7 @@ def test_get_historic_test_executions_query(db_session: Session):
test_execution_one.artefact_build_id,
]

test_execution_ids = get_historic_test_executions_query(
test_execution_ids = get_previous_test_executions_query(
session=db_session,
test_execution=test_execution_three,
artefact_build_query=artefact_build_query,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ def test_fetch_test_results(db_session: Session, test_client: TestClient):
assert json[0]["status"] == test_result_second.status.name
assert json[0]["comment"] == test_result_second.comment
assert json[0]["io_log"] == test_result_second.io_log
assert json[0]["historic_results"] == [
assert json[0]["previous_results"] == [
{
"status": test_result_first.status,
"version": artefact_first.version,
Expand Down

0 comments on commit f285aef

Please sign in to comment.