API

Validation

Module to provide helper function for JSON schema validation.

class ska_ser_xray.validation.ValidatedData(json_file, json_schema, model)

Class to access JSON data provided from a json file.

This automatically validates the JSON schema (see …) of the file and proxies to its data model.

ska_ser_xray.validation.validated_json_object(json_file, schema, model)

Return a validate instance of the given model.

Parameters
  • json_file (Path) – the JSON file containing the object data

  • schema (Union[str, bytes]) – the JSON schema for the object

  • model (Any) – the python data model for the object

Return type

Any

Returns

the instance of the data model

Raises

ValueError – error on schema non-conformance

Auto-generated data models from json schemas.

{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "definitions": {
    "tag": {
      "type": "object",
      "properties": {
        "name": {
          "type": "string"
        },
        "line": {
          "type": "integer"
        }
      },
      "required": ["name"]
    },
    "feature": {
      "type": "object",
      "properties": {
        "uri": {
          "type": "string"
        },
        "keyword": {
          "type": "string"
        },
        "name": {
          "type": "string"
        },
        "tags": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/tag"
          }
        },
        "elements": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/element"
          }
        }
      },
      "required": ["name", "uri"]
    },
    "element": {
      "type": "object",
      "properties": {
        "keyword": {
          "type": "string"
        },
        "type": {
          "type": "string"
        },
        "id": {
          "type": "string"
        },
        "line": {
          "type": "integer"
        },
        "name": {
          "type": "string"
        },
        "tags": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/tag"
          }
        },
        "steps": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/step"
          }
        }
      },
      "required": ["type", "line", "name"]
    },
    "step": {
      "type": "object",
      "properties": {
        "keyword": {
          "type": "string"
        },
        "line": {
          "type": "integer"
        },
        "name": {
          "type": "string"
        },
        "hidden": {
          "type": "boolean"
        },
        "result": {
          "type": "object",
          "properties": {
            "status": {
              "type": "string",
              "enum": [
                "passed", "Passed", "PASSED",
                "failed", "Failed", "FAILED",
                "undefined", "Undefined", "UNDEFINED",
                "skipped", "Skipped", "SKIPPED",
                "pending", "Pending", "PENDING",
                "ambiguous", "Ambiguous", "AMBIGUOUS"
              ]
            },
            "duration": {
              "type": "number"
            },
            "error_message": {
              "type": "string"
            }
          },
          "required": ["status"],
          "if": {
            "properties": { "status": { "pattern": "^(?:f|F)(?:ailed|AILED)$" } }
          },
          "then": {
            "required": ["error_message"]
          }
        }
      },
      "required": ["keyword"],
      "if": {
        "not": {
          "properties": { "hidden": { "const": true } },
          "required": ["hidden"]
        }
      },
      "then": {
        "required": ["line"]
      }


    }
  },
  "type": "array",
  "items": {
    "$ref": "#/definitions/feature"
  }
}

JSON data objects

This module implements access to the metadata provided for JIRA issues.

class ska_ser_xray.execution_configuration_data.ExecutionConfigurationData(json_file)

Class to access JIRA/xray metadata provided from a json file.

This automatically validates the JSON schema (see …) of the file and proxies to its data model.

property chart_info: Path

Get the Path to the helm chart.

This is matching the configuration to the environment (variables) given to the process.

Return type

Path

Returns

the name project Id string

property description: str

Get the description for the test execution.

This is matching the configuration to the environment (variables) given to the process.

Return type

str

Returns

the description representation for JIRA

property env_variables: List[Tuple[str, str]]

Get the a list of environment variables.

This is matching the configuration to the environment (variables) given to the process.

Return type

List[Tuple[str, str]]

Returns

list of (env_name, env_value) tuples

get_test_plans(report_tags)

Get the test plan (ids) matching the given report_tags.

Parameters

report_tags (Set[str]) – a list of unique JIRA issue id tags from the test report.

Return type

List[str]

Returns

a list of tags matching the configuration data

property labels: List[str]

Get the list of labels.

This is matching the configuration from the environment (variables) given to the process.

Return type

List[str]

Returns

list of JIRA version numbers, e.g. the git branch

property name: str

Get the name for the test execution.

This is matching the configuration to the environment (variables) given to the process.

Return type

str

Returns

the name representation for JIRA

property project_id: str

Get the JIRA project Id for the test execution.

Return type

str

Returns

the name project Id string

property summary: str

Get a summary of metadata for the JIRA execution.

Return type

str

Returns

multi-line string of info

property test_environments: List[str]

Get the list of test environments.

This is matching the configuration from the environment (variables) given to the process.

Return type

List[str]

Returns

list of Test environments, e.g. “[PI15]”

property test_report_path: Path

Get the path to the pytest report (JSON) file.

Return type

Path

Returns

path to file

property versions: List[str]

Get the list of versions.

This is matching the configuration from the environment (variables) given to the process.

Return type

List[str]

Returns

list of JIRA version numbers, e.g. “[PI15]”

ska_ser_xray.execution_configuration_data.evaluate_from_env(spec)

Evaluate against os.environ settings.

Parameters

spec (Any) – data entry to evaluate

Return type

str

Returns

derived value

ska_ser_xray.execution_configuration_data.evaluate_from_tags(spec, tags)

Evaluate against given tags.

Parameters
  • spec (Any) – data entry to evaluate

  • tags (Set[str]) – a list of tags to match against

Return type

str

Returns

derived value

This module implements access to the pytest report data for JIRA issues.

class ska_ser_xray.report_data.ReportData(json_file)

Class to access pytest test report data from a JSON file.

This automatically validates the JSON schema (see …) of the file and proxies to its data model.

get_formatted_dates()

Get the start/end dates for the test report as ISO formatted string.

Return type

Tuple[str, ...]

Returns

a tuple of start and end time stamps

get_start_end_dates()

Get the start and end dates for the test report.

Return type

Tuple[datetime, datetime]

Returns

a tuple of start and end datetime objects

property keywords: Set[str]

Get unique keywords from all tests.

Return type

Set[str]

Returns

set of keywords

This module implements access to the cucumber results for JIRA issues.

class ska_ser_xray.cucumber_data.CucumberData(json_file)

Class to access cucumber JSON data provided from a json file.

This automatically validates the JSON schema (see …) of the file and proxies to its data model.

property tags: Set[str]

Return a set of exclusively owned tags found in each test.

In other words return the tags which each test share with all others.

Return type

Set[str]

Returns

A set of exclusively owned tags

This module implements access to the JIRA issue update data.

class ska_ser_xray.jira_info_data.JiraInfoData(**kwargs)

Simplified access class for JiraInfo.

JIRA/XRAY upload

Utilities to handle xray multipart uploads.

ska_ser_xray.upload.upload_multipart.get_info(test_exec_path, test_results_path)

Assemble and return dictionary for multipart xray info field.

Parameters
  • test_exec_path (Path) – path to test execution

  • test_results_path (Path) – path to test results file

Return type

Part

Returns

Part data

ska_ser_xray.upload.upload_multipart.upload_multipart(host, token, results_file, test_exec_desc_file, skip_upload=False)

Perform a multipart upload.

Parameters
  • host (str) – hostname to upload to

  • token (str) – the authentication token

  • results_file (Path) – the json test results file

  • test_exec_desc_file (Path) – the test execution config file

  • skip_upload (bool) – generate info but don’t upload

Return type

Optional[MultiPartResults]

Returns

the response items from call

Module to create JIRA endpoint connections.

class ska_ser_xray.upload.multipart_connection.Connection(host, token)

JIRA connection object.

push_multipart(*parts, skip_upload=False)

Push results to JIRA.

Parameters
  • parts (Part) – the json “files” to upload

  • skip_upload (bool) – to have a dry run only

Raises

UploadError – if anything goes wrong

Return type

MultiPartResults

Returns

status report from JIRA

class ska_ser_xray.upload.multipart_connection.MultiPartResults(**data)

Model to capture upload results.

class ska_ser_xray.upload.multipart_connection.Part(**data)

Model to pass a part of multipart data.

exception ska_ser_xray.upload.multipart_connection.UploadError

Exception to raise when upload fails.