Skip to content

Commit

Permalink
Add required link types and test them
Browse files Browse the repository at this point in the history
  • Loading branch information
e-backmark-ericsson committed Jan 3, 2024
1 parent b7c6d6b commit d33d470
Show file tree
Hide file tree
Showing 14 changed files with 133 additions and 29 deletions.
6 changes: 6 additions & 0 deletions definitions/EiffelActivityCanceledEvent/3.2.1.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 6 additions & 0 deletions definitions/EiffelActivityStartedEvent/4.3.1.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
7 changes: 7 additions & 0 deletions definitions/EiffelArtifactDeployedEvent/0.1.1.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 6 additions & 0 deletions definitions/EiffelArtifactPublishedEvent/3.3.1.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
7 changes: 7 additions & 0 deletions definitions/EiffelArtifactReusedEvent/3.2.1.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 6 additions & 0 deletions definitions/EiffelConfidenceLevelModifiedEvent/3.4.1.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 6 additions & 0 deletions definitions/EiffelIssueVerifiedEvent/4.3.2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 6 additions & 0 deletions definitions/EiffelTestCaseCanceledEvent/3.2.1.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 6 additions & 0 deletions definitions/EiffelTestCaseFinishedEvent/3.3.2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 6 additions & 0 deletions definitions/EiffelTestCaseStartedEvent/3.3.1.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 6 additions & 0 deletions definitions/EiffelTestCaseTriggeredEvent/3.5.2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 6 additions & 0 deletions definitions/EiffelTestSuiteFinishedEvent/3.3.2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
86 changes: 58 additions & 28 deletions test_definitions.py
Original file line number Diff line number Diff line change
@@ -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");
Expand All @@ -13,42 +13,39 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import logging
import pathlib

import pytest

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", [])
if entry.get("version") == event_version
], 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:
Expand All @@ -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)
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d33d470

Please sign in to comment.