Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pmbrull committed Jan 5, 2024
1 parent 4c434e7 commit 194d948
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 27 deletions.
16 changes: 0 additions & 16 deletions ingestion/examples/sample_data/tests/testSuites.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@
],
"resolutions": {
"sequenceOne": [
{
"testCaseResolutionStatusType": "New",
"severity": "Severity1"
},
{
"testCaseResolutionStatusType": "Ack",
"severity": "Severity1"
Expand Down Expand Up @@ -108,10 +104,6 @@
],
"resolutions": {
"sequenceOne": [
{
"testCaseResolutionStatusType": "New",
"severity": "Severity1"
},
{
"testCaseResolutionStatusType": "Ack",
"severity": "Severity1"
Expand Down Expand Up @@ -186,10 +178,6 @@
],
"resolutions": {
"sequenceOne": [
{
"testCaseResolutionStatusType": "New",
"severity": "Severity1"
},
{
"testCaseResolutionStatusType": "Ack",
"severity": "Severity1"
Expand Down Expand Up @@ -264,10 +252,6 @@
],
"resolutions": {
"sequenceOne": [
{
"testCaseResolutionStatusType": "New",
"severity": "Severity1"
},
{
"testCaseResolutionStatusType": "Ack",
"severity": "Severity1"
Expand Down
9 changes: 9 additions & 0 deletions ingestion/src/metadata/ingestion/models/tests_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
from pydantic import BaseModel

from metadata.generated.schema.api.tests.createTestCase import CreateTestCaseRequest
from metadata.generated.schema.api.tests.createTestCaseResolutionStatus import (
CreateTestCaseResolutionStatus,
)
from metadata.generated.schema.api.tests.createTestSuite import CreateTestSuiteRequest
from metadata.generated.schema.tests.basic import TestCaseResult
from metadata.generated.schema.tests.testCase import TestCase
Expand All @@ -38,3 +41,9 @@ class OMetaTestCaseSample(BaseModel):
class OMetaTestCaseResultsSample(BaseModel):
test_case_results: TestCaseResult
test_case_name: str


class OMetaTestCaseResolutionStatus(BaseModel):
"""For sample data"""

test_case_resolution: CreateTestCaseResolutionStatus
13 changes: 13 additions & 0 deletions ingestion/src/metadata/ingestion/sink/metadata_rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@
from metadata.generated.schema.entity.teams.user import User
from metadata.generated.schema.tests.basic import TestCaseResult
from metadata.generated.schema.tests.testCase import TestCase
from metadata.generated.schema.tests.testCaseResolutionStatus import (
TestCaseResolutionStatus,
)
from metadata.generated.schema.tests.testSuite import TestSuite
from metadata.generated.schema.type.schema import Topic
from metadata.ingestion.api.models import Either, Entity, StackTraceError
Expand All @@ -67,6 +70,7 @@
from metadata.ingestion.models.search_index_data import OMetaIndexSampleData
from metadata.ingestion.models.tests_data import (
OMetaLogicalTestSuiteSample,
OMetaTestCaseResolutionStatus,
OMetaTestCaseResultsSample,
OMetaTestCaseSample,
OMetaTestSuiteSample,
Expand Down Expand Up @@ -411,6 +415,15 @@ def write_test_case_results(self, record: TestCaseResultResponse):
)
return Either(right=res)

@_run_dispatch.register
def write_test_case_resolution_status(
self, record: OMetaTestCaseResolutionStatus
) -> TestCaseResolutionStatus:
"""For sample data"""
res = self.metadata.create_test_case_resolution(record.test_case_resolution)

return Either(right=res)

@_run_dispatch.register
def write_data_insight_sample(
self, record: OMetaDataInsightSample
Expand Down
17 changes: 15 additions & 2 deletions ingestion/src/metadata/ingestion/source/database/sample_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@
from metadata.ingestion.models.profile_data import OMetaTableProfileSampleData
from metadata.ingestion.models.tests_data import (
OMetaLogicalTestSuiteSample,
OMetaTestCaseResolutionStatus,
OMetaTestCaseResultsSample,
OMetaTestCaseSample,
OMetaTestSuiteSample,
Expand Down Expand Up @@ -566,6 +567,7 @@ def _iter(self, *_, **__) -> Iterable[Entity]:
yield from self.ingest_test_suite()
yield from self.ingest_test_case()
yield from self.ingest_test_case_results()
yield from self.ingest_incidents()
yield from self.ingest_logical_test_suite()
yield from self.ingest_data_insights()
yield from self.ingest_life_cycle()
Expand Down Expand Up @@ -1408,6 +1410,15 @@ def ingest_test_case(self) -> Iterable[Either[OMetaTestCaseSample]]:
)
yield Either(right=test_case_req)

def ingest_incidents(self) -> Iterable[Either[OMetaTestCaseResolutionStatus]]:
"""
Ingest incidents after the first test failures have been added.
The test failure already creates the incident with NEW, so we
start always from ACK in the sample flows.
"""
for test_suite in self.tests_suites["tests"]:
for test_case in test_suite["testCases"]:
test_case_fqn = f"{entity_link.get_table_or_column_fqn(test_case['entityLink'])}.{test_case['name']}"

for _, resolutions in test_case["resolutions"].items():
Expand Down Expand Up @@ -1449,8 +1460,10 @@ def ingest_test_case(self) -> Iterable[Either[OMetaTestCaseSample]]:
testCaseFailureComment="Resolution comment",
)

self.metadata.create_test_case_resolution(
create_test_case_resolution
yield Either(
right=OMetaTestCaseResolutionStatus(
test_case_resolution=create_test_case_resolution
)
)

def ingest_test_case_results(self) -> Iterable[Either[OMetaTestCaseResultsSample]]:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,9 @@ private void validatePatchFields(

public Boolean unresolvedIncident(TestCaseResolutionStatus incident) {
return incident != null
&& incident.getTestCaseResolutionStatusType() != TestCaseResolutionStatusTypes.Resolved;
&& !incident
.getTestCaseResolutionStatusType()
.equals(TestCaseResolutionStatusTypes.Resolved);
}

private Thread getIncidentTask(TestCaseResolutionStatus incident) {
Expand Down Expand Up @@ -151,13 +153,10 @@ public TestCaseResolutionStatus createNewRecord(
recordEntity.setStateId(UUID.randomUUID());
}

if (lastIncident != null) {
// if we have an ongoing incident, set the stateId if the new record to be created
recordEntity.setStateId(
Boolean.TRUE.equals(unresolvedIncident(recordEntity))
? lastIncident.getStateId()
: recordEntity.getStateId());

// if we have an ongoing incident, set the stateId if the new record to be created
// and validate the flow
if (Boolean.TRUE.equals(unresolvedIncident(lastIncident))) {
recordEntity.setStateId(lastIncident.getStateId());
validateStatus(
lastIncident.getTestCaseResolutionStatusType(),
recordEntity.getTestCaseResolutionStatusType());
Expand All @@ -169,7 +168,7 @@ public TestCaseResolutionStatus createNewRecord(
case New -> {
// If there is already an unresolved incident, return it without doing any
// further logic.
if (lastIncident != null) {
if (Boolean.TRUE.equals(unresolvedIncident(lastIncident))) {
return getLatestRecord(lastIncident.getTestCaseReference().getFullyQualifiedName());
}
openNewTask(recordEntity);
Expand Down

0 comments on commit 194d948

Please sign in to comment.