diff --git a/definitions/EiffelActivityCanceledEvent/3.2.1.yml b/definitions/EiffelActivityCanceledEvent/3.2.1.yml index 0f0eb1df..52d978b7 100644 --- a/definitions/EiffelActivityCanceledEvent/3.2.1.yml +++ b/definitions/EiffelActivityCanceledEvent/3.2.1.yml @@ -38,6 +38,12 @@ properties: additionalProperties: false links: type: array + contains: + type: object + properties: + type: + enum: + - ACTIVITY_EXECUTION items: $ref: ../EiffelEventLink/1.1.2.yml required: diff --git a/definitions/EiffelActivityStartedEvent/4.3.1.yml b/definitions/EiffelActivityStartedEvent/4.3.1.yml index 630d0de3..8c16a06b 100644 --- a/definitions/EiffelActivityStartedEvent/4.3.1.yml +++ b/definitions/EiffelActivityStartedEvent/4.3.1.yml @@ -70,6 +70,12 @@ properties: additionalProperties: false links: type: array + contains: + type: object + properties: + type: + enum: + - ACTIVITY_EXECUTION items: $ref: ../EiffelEventLink/1.1.1.yml required: diff --git a/definitions/EiffelArtifactDeployedEvent/0.1.1.yml b/definitions/EiffelArtifactDeployedEvent/0.1.1.yml index 7d038beb..37f5ba4c 100644 --- a/definitions/EiffelArtifactDeployedEvent/0.1.1.yml +++ b/definitions/EiffelArtifactDeployedEvent/0.1.1.yml @@ -39,6 +39,13 @@ properties: additionalProperties: false links: type: array + contains: + type: object + properties: + type: + enum: + - ARTIFACT + - ENVIRONMENT items: $ref: ../EiffelEventLink/1.1.1.yml required: diff --git a/definitions/EiffelArtifactPublishedEvent/3.3.1.yml b/definitions/EiffelArtifactPublishedEvent/3.3.1.yml index 9788de59..3f9c18ee 100644 --- a/definitions/EiffelArtifactPublishedEvent/3.3.1.yml +++ b/definitions/EiffelArtifactPublishedEvent/3.3.1.yml @@ -69,6 +69,12 @@ properties: additionalProperties: false links: type: array + contains: + type: object + properties: + type: + enum: + - ARTIFACT items: $ref: ../EiffelEventLink/1.1.1.yml required: diff --git a/definitions/EiffelArtifactReusedEvent/3.2.1.yml b/definitions/EiffelArtifactReusedEvent/3.2.1.yml index c8cfb3fc..b25658fd 100644 --- a/definitions/EiffelArtifactReusedEvent/3.2.1.yml +++ b/definitions/EiffelArtifactReusedEvent/3.2.1.yml @@ -33,6 +33,13 @@ properties: additionalProperties: false links: type: array + contains: + type: object + properties: + type: + enum: + - REUSED_ARTIFACT + - COMPOSITION items: $ref: ../EiffelEventLink/1.1.1.yml required: diff --git a/definitions/EiffelConfidenceLevelModifiedEvent/3.4.1.yml b/definitions/EiffelConfidenceLevelModifiedEvent/3.4.1.yml index 909bd746..6f50d56a 100644 --- a/definitions/EiffelConfidenceLevelModifiedEvent/3.4.1.yml +++ b/definitions/EiffelConfidenceLevelModifiedEvent/3.4.1.yml @@ -73,6 +73,12 @@ properties: additionalProperties: false links: type: array + contains: + type: object + properties: + type: + enum: + - SUBJECT items: $ref: ../EiffelEventLink/1.1.1.yml required: diff --git a/definitions/EiffelIssueVerifiedEvent/4.3.2.yml b/definitions/EiffelIssueVerifiedEvent/4.3.2.yml index 91226992..ed2b2305 100644 --- a/definitions/EiffelIssueVerifiedEvent/4.3.2.yml +++ b/definitions/EiffelIssueVerifiedEvent/4.3.2.yml @@ -33,6 +33,12 @@ properties: additionalProperties: false links: type: array + contains: + type: object + properties: + type: + enum: + - IUT items: $ref: ../EiffelEventLink/1.1.1.yml required: diff --git a/definitions/EiffelTestCaseCanceledEvent/3.2.1.yml b/definitions/EiffelTestCaseCanceledEvent/3.2.1.yml index 55c6a57c..dc5f6223 100644 --- a/definitions/EiffelTestCaseCanceledEvent/3.2.1.yml +++ b/definitions/EiffelTestCaseCanceledEvent/3.2.1.yml @@ -38,6 +38,12 @@ properties: additionalProperties: false links: type: array + contains: + type: object + properties: + type: + enum: + - TEST_CASE_EXECUTION items: $ref: ../EiffelEventLink/1.1.1.yml required: diff --git a/definitions/EiffelTestCaseFinishedEvent/3.3.2.yml b/definitions/EiffelTestCaseFinishedEvent/3.3.2.yml index c5ede2e4..56205ca4 100644 --- a/definitions/EiffelTestCaseFinishedEvent/3.3.2.yml +++ b/definitions/EiffelTestCaseFinishedEvent/3.3.2.yml @@ -126,6 +126,12 @@ properties: additionalProperties: false links: type: array + contains: + type: object + properties: + type: + enum: + - TEST_CASE_EXECUTION items: $ref: ../EiffelEventLink/1.1.1.yml required: diff --git a/definitions/EiffelTestCaseStartedEvent/3.3.1.yml b/definitions/EiffelTestCaseStartedEvent/3.3.1.yml index a4bb49fe..636db5af 100644 --- a/definitions/EiffelTestCaseStartedEvent/3.3.1.yml +++ b/definitions/EiffelTestCaseStartedEvent/3.3.1.yml @@ -70,6 +70,12 @@ properties: additionalProperties: false links: type: array + contains: + type: object + properties: + type: + enum: + - TEST_CASE_EXECUTION items: $ref: ../EiffelEventLink/1.1.1.yml required: diff --git a/definitions/EiffelTestCaseTriggeredEvent/3.5.2.yml b/definitions/EiffelTestCaseTriggeredEvent/3.5.2.yml index 3c83ec79..808261cb 100644 --- a/definitions/EiffelTestCaseTriggeredEvent/3.5.2.yml +++ b/definitions/EiffelTestCaseTriggeredEvent/3.5.2.yml @@ -121,6 +121,12 @@ properties: additionalProperties: false links: type: array + contains: + type: object + properties: + type: + enum: + - IUT items: $ref: ../EiffelEventLink/1.1.1.yml required: diff --git a/definitions/EiffelTestSuiteFinishedEvent/3.3.2.yml b/definitions/EiffelTestSuiteFinishedEvent/3.3.2.yml index e4b65556..bc2ffb08 100644 --- a/definitions/EiffelTestSuiteFinishedEvent/3.3.2.yml +++ b/definitions/EiffelTestSuiteFinishedEvent/3.3.2.yml @@ -98,6 +98,12 @@ properties: additionalProperties: false links: type: array + contains: + type: object + properties: + type: + enum: + - TEST_SUITE_EXECUTION items: $ref: ../EiffelEventLink/1.1.1.yml required: diff --git a/schemas/EiffelActivityCanceledEvent/3.2.1.json b/schemas/EiffelActivityCanceledEvent/3.2.1.json index 7c086a2e..05bdef09 100644 --- a/schemas/EiffelActivityCanceledEvent/3.2.1.json +++ b/schemas/EiffelActivityCanceledEvent/3.2.1.json @@ -157,6 +157,16 @@ }, "links": { "type": "array", + "contains": { + "type": "object", + "properties": { + "type": { + "enum": [ + "ACTIVITY_EXECUTION" + ] + } + } + }, "items": { "type": "object", "properties": { diff --git a/schemas/EiffelActivityStartedEvent/4.3.1.json b/schemas/EiffelActivityStartedEvent/4.3.1.json index ff4344aa..553f39be 100644 --- a/schemas/EiffelActivityStartedEvent/4.3.1.json +++ b/schemas/EiffelActivityStartedEvent/4.3.1.json @@ -185,6 +185,16 @@ }, "links": { "type": "array", + "contains": { + "type": "object", + "properties": { + "type": { + "enum": [ + "ACTIVITY_EXECUTION" + ] + } + } + }, "items": { "type": "object", "properties": { diff --git a/schemas/EiffelArtifactDeployedEvent/0.1.1.json b/schemas/EiffelArtifactDeployedEvent/0.1.1.json index 66d44c3d..f9304889 100644 --- a/schemas/EiffelArtifactDeployedEvent/0.1.1.json +++ b/schemas/EiffelArtifactDeployedEvent/0.1.1.json @@ -160,6 +160,17 @@ }, "links": { "type": "array", + "contains": { + "type": "object", + "properties": { + "type": { + "enum": [ + "ARTIFACT", + "ENVIRONMENT" + ] + } + } + }, "items": { "type": "object", "properties": { diff --git a/schemas/EiffelArtifactPublishedEvent/3.3.1.json b/schemas/EiffelArtifactPublishedEvent/3.3.1.json index cee4e12e..4d6e0ec8 100644 --- a/schemas/EiffelArtifactPublishedEvent/3.3.1.json +++ b/schemas/EiffelArtifactPublishedEvent/3.3.1.json @@ -185,6 +185,16 @@ }, "links": { "type": "array", + "contains": { + "type": "object", + "properties": { + "type": { + "enum": [ + "ARTIFACT" + ] + } + } + }, "items": { "type": "object", "properties": { diff --git a/schemas/EiffelArtifactReusedEvent/3.2.1.json b/schemas/EiffelArtifactReusedEvent/3.2.1.json index e3161697..623059f1 100644 --- a/schemas/EiffelArtifactReusedEvent/3.2.1.json +++ b/schemas/EiffelArtifactReusedEvent/3.2.1.json @@ -154,6 +154,17 @@ }, "links": { "type": "array", + "contains": { + "type": "object", + "properties": { + "type": { + "enum": [ + "REUSED_ARTIFACT", + "COMPOSITION" + ] + } + } + }, "items": { "type": "object", "properties": { diff --git a/schemas/EiffelConfidenceLevelModifiedEvent/3.4.1.json b/schemas/EiffelConfidenceLevelModifiedEvent/3.4.1.json index 5312c4a9..974c0fe8 100644 --- a/schemas/EiffelConfidenceLevelModifiedEvent/3.4.1.json +++ b/schemas/EiffelConfidenceLevelModifiedEvent/3.4.1.json @@ -187,6 +187,16 @@ }, "links": { "type": "array", + "contains": { + "type": "object", + "properties": { + "type": { + "enum": [ + "SUBJECT" + ] + } + } + }, "items": { "type": "object", "properties": { diff --git a/schemas/EiffelIssueVerifiedEvent/4.3.2.json b/schemas/EiffelIssueVerifiedEvent/4.3.2.json index 0bf20232..e2f45463 100644 --- a/schemas/EiffelIssueVerifiedEvent/4.3.2.json +++ b/schemas/EiffelIssueVerifiedEvent/4.3.2.json @@ -154,6 +154,16 @@ }, "links": { "type": "array", + "contains": { + "type": "object", + "properties": { + "type": { + "enum": [ + "IUT" + ] + } + } + }, "items": { "type": "object", "properties": { diff --git a/schemas/EiffelTestCaseCanceledEvent/3.2.1.json b/schemas/EiffelTestCaseCanceledEvent/3.2.1.json index b6eb48ce..a8898f4e 100644 --- a/schemas/EiffelTestCaseCanceledEvent/3.2.1.json +++ b/schemas/EiffelTestCaseCanceledEvent/3.2.1.json @@ -157,6 +157,16 @@ }, "links": { "type": "array", + "contains": { + "type": "object", + "properties": { + "type": { + "enum": [ + "TEST_CASE_EXECUTION" + ] + } + } + }, "items": { "type": "object", "properties": { diff --git a/schemas/EiffelTestCaseFinishedEvent/3.3.2.json b/schemas/EiffelTestCaseFinishedEvent/3.3.2.json index 93f70f00..4bf4e06b 100644 --- a/schemas/EiffelTestCaseFinishedEvent/3.3.2.json +++ b/schemas/EiffelTestCaseFinishedEvent/3.3.2.json @@ -233,6 +233,16 @@ }, "links": { "type": "array", + "contains": { + "type": "object", + "properties": { + "type": { + "enum": [ + "TEST_CASE_EXECUTION" + ] + } + } + }, "items": { "type": "object", "properties": { diff --git a/schemas/EiffelTestCaseStartedEvent/3.3.1.json b/schemas/EiffelTestCaseStartedEvent/3.3.1.json index 1c553001..292fa57c 100644 --- a/schemas/EiffelTestCaseStartedEvent/3.3.1.json +++ b/schemas/EiffelTestCaseStartedEvent/3.3.1.json @@ -185,6 +185,16 @@ }, "links": { "type": "array", + "contains": { + "type": "object", + "properties": { + "type": { + "enum": [ + "TEST_CASE_EXECUTION" + ] + } + } + }, "items": { "type": "object", "properties": { diff --git a/schemas/EiffelTestCaseTriggeredEvent/3.5.2.json b/schemas/EiffelTestCaseTriggeredEvent/3.5.2.json index 0aad20d8..4ef39447 100644 --- a/schemas/EiffelTestCaseTriggeredEvent/3.5.2.json +++ b/schemas/EiffelTestCaseTriggeredEvent/3.5.2.json @@ -235,6 +235,16 @@ }, "links": { "type": "array", + "contains": { + "type": "object", + "properties": { + "type": { + "enum": [ + "IUT" + ] + } + } + }, "items": { "type": "object", "properties": { diff --git a/schemas/EiffelTestSuiteFinishedEvent/3.3.2.json b/schemas/EiffelTestSuiteFinishedEvent/3.3.2.json index 0696bd22..0f950881 100644 --- a/schemas/EiffelTestSuiteFinishedEvent/3.3.2.json +++ b/schemas/EiffelTestSuiteFinishedEvent/3.3.2.json @@ -209,6 +209,16 @@ }, "links": { "type": "array", + "contains": { + "type": "object", + "properties": { + "type": { + "enum": [ + "TEST_SUITE_EXECUTION" + ] + } + } + }, "items": { "type": "object", "properties": { diff --git a/test_definitions.py b/test_definitions.py index 601616b1..448002d7 100644 --- a/test_definitions.py +++ b/test_definitions.py @@ -1,4 +1,4 @@ -# Copyright 2023 Axis Communications AB and others. +# Copyright 2023-2024 Axis Communications AB and others. # For a full list of individual contributors, please see the commit history. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +import logging import pathlib import pytest @@ -20,20 +21,23 @@ import definition_loader import generate_manifest +# Set up a console logger +logger = logging.getLogger("__Logger__") +console_handler = logging.StreamHandler() +formatter = logging.Formatter( + "%(asctime)s - %(name)s - %(levelname)s - %(message)s", + datefmt="%m/%d/%Y %I:%M:%S%p", +) +console_handler.setFormatter(formatter) +logger.addHandler(console_handler) -@pytest.fixture(scope="session") -def manifest(): - return generate_manifest.Manifest("event_manifest.yml") +manifest = generate_manifest.Manifest("event_manifest.yml") -@pytest.mark.parametrize( - "event_definition_path", - pathlib.Path(".").glob("definitions/Eiffel*Event/*.yml"), -) -def test_history_table_contains_current_version(event_definition_path): - definition = definition_loader.load(event_definition_path) - event_type = event_definition_path.parent.name - event_version = event_definition_path.stem + +def do_test_history_table_contains_current_version( + event_type, event_version, definition +): assert [ entry for entry in definition.get("_history", []) @@ -41,14 +45,7 @@ def test_history_table_contains_current_version(event_definition_path): ], f"History table entry missing for {event_type} {event_version}" -@pytest.mark.parametrize( - "event_definition_path", - pathlib.Path(".").glob("definitions/Eiffel*Event/*.yml"), -) -def test_history_table_contains_valid_release(event_definition_path, manifest): - event_type = event_definition_path.parent.name - event_version = event_definition_path.stem - definition = definition_loader.load(event_definition_path) +def do_test_history_table_contains_valid_release(event_type, event_version, definition): for entry in definition.get("_history", []): edition = entry.get("introduced_in", None) if edition is not None: @@ -57,18 +54,51 @@ def test_history_table_contains_valid_release(event_definition_path, manifest): ), f"Nonexistent edition '{edition}' in history table for {event_type} {event_version}" +def do_test_history_table_matches_manifest(event_type, event_version, definition): + for entry in definition.get("_history", []): + edition = entry.get("introduced_in", None) + event_version_of_edition = entry.get("version") + if edition is not None: + assert manifest.is_in_edition( + edition, event_type, event_version_of_edition + ), f"{event_version_of_edition} not part of '{edition}' as described in history table for {event_type} {event_version}" + + +def do_test_links(event_type, event_version, definition): + schema_version = definition.get("$schema") + + # Checking for required link is only valid for event types with recent meta schemas + if "draft-04" in schema_version: + assert True + else: + contained_link_types = [] + required_link_types = [] + schema_links = definition.get("properties").get("links") + if schema_links.get("contains"): + contained_link_types = ( + schema_links.get("contains").get("properties").get("type").get("enum") + ) + links = definition.get("_links", {}) + for link in links: + if links[link]["required"]: + required_link_types.append(link) + assert ( + contained_link_types.sort() == required_link_types.sort() + ), f"Required '{required_link_types}' and contained '{contained_link_types}' link types do not match" + + @pytest.mark.parametrize( "event_definition_path", pathlib.Path(".").glob("definitions/Eiffel*Event/*.yml"), ) -def test_history_table_matches_manifest(event_definition_path, manifest): +def test_definition_file(event_definition_path): + logger.info("Definition check - %s", event_definition_path) event_type = event_definition_path.parent.name event_version = event_definition_path.stem definition = definition_loader.load(event_definition_path) - for entry in definition.get("_history", []): - edition = entry.get("introduced_in", None) - event_version_of_edition = entry.get("version") - if edition is not None: - assert manifest.is_in_edition( - edition, event_type, event_version_of_edition - ), f"{event_version_of_edition} not part of '{edition}' as describe in history table for {event_type} {event_version}" + do_test_history_table_contains_current_version( + event_type, event_version, definition + ) + do_test_history_table_contains_valid_release(event_type, event_version, definition) + do_test_history_table_matches_manifest(event_type, event_version, definition) + do_test_links(event_type, event_version, definition) diff --git a/tox.ini b/tox.ini index 05eca349..2f0b91ae 100644 --- a/tox.ini +++ b/tox.ini @@ -62,7 +62,7 @@ commands = pytest test_jsonschema.py {posargs} deps = -rrequirements.txt pytest==6.2.5 -commands = pytest --ignore=test_jsonformat.py {posargs} +commands = pytest --ignore=test_jsonformat.py --ignore=test_jsonschema.py {posargs} [testenv:validate] deps = -rrequirements.txt