API

Models

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"
  }
}
class ska_ser_xray.models.junit.Error(*, type_value=None, message=None, content=<factory>)
class ska_ser_xray.models.junit.Failure(*, type_value=None, message=None, content=<factory>)
class ska_ser_xray.models.junit.Properties(*, property=<factory>)
class ska_ser_xray.models.junit.Property(*, name, value)
class ska_ser_xray.models.junit.Skipped(*, message=None)
class ska_ser_xray.models.junit.SystemErr(*, value='')
class ska_ser_xray.models.junit.SystemOut(*, value='')
class ska_ser_xray.models.junit.Testcase(*, properties=None, skipped=None, error=None, failure=<factory>, system_out=<factory>, system_err=<factory>, name, assertions=None, time, classname=None, status=None)
class ska_ser_xray.models.junit.Testsuite(*, properties=None, testcase=<factory>, system_out=None, system_err=None, tests, failures, errors, skipped=None, time, name, timestamp, hostname)
class ska_ser_xray.models.junit.Testsuites(*, testsuite=<factory>)

Module containing information about the test result.

class ska_ser_xray.test_result_info.TestFramework(value)

Supported test frameworks.

class ska_ser_xray.test_result_info.TestResultInfo(**data)

Model to capture test result information.

Data objects from JSON

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.

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.

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.

Returns:

list of (env_name, env_value) tuples

get_customissue_mapping()

Get the mapping from human readable to JIRA customissue_id.

Return type:

Dict[str, str]

Returns:

a dictionary of name mapping

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 issuetype_id: int

Get the issuetype id to work with.

Returns:

id of XRAY issue type (e.g. for Test Execution)

property jira_default_url: str

Get the JIRA host from configuration.

Returns:

host URL

property labels: List[str]

Get the list of labels.

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

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.

Returns:

the name representation for JIRA

property project_id: str

Get the JIRA project Id for the test execution.

Returns:

the name project Id string

property summary: str

Get a summary of metadata for the JIRA execution.

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.

Returns:

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

property test_report_path: Path

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

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.

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 JIRA issue update data.

class ska_ser_xray.jira_info_data.FieldModel(**data)

Inner field model for JIRA json message.

classmethod rename_fields(values)

Rename model fields on-the-fly.

This allows having JIRA custom fields on a project base. An empty replacement field in _mapping removes the field.

Parameters:

values (Dict[str, Any]) – the original fields

Return type:

Dict[str, Any]

Returns:

the updated fields

class ska_ser_xray.jira_info_data.JiraInfoData(data, mapping)

Simplified access class for JiraInfo.

json()

Replace on-the-fly mapped keys in the output json.

Return type:

str

Returns:

json string with replaced customfield names.

class ska_ser_xray.jira_info_data.JiraInfoModel(**data)

The model for the JIRA Test Execution info.

JIRA/XRAY upload

Utilities to handle xray multipart uploads.

class ska_ser_xray.upload.upload_multipart.CucumberUploader(connection)

Uploader that imports Cucumber test results into JIRA.

upload(test_result_info, jira_info, skip_upload=False)

Upload the given test results.

Parameters:
  • test_result_info (TestResultInfo) – information about the test result

  • jira_info (JiraInfoData) – JIRA info data

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

Return type:

Optional[MultiPartResults]

Returns:

the response items from call

class ska_ser_xray.upload.upload_multipart.JUnitXmlUploader(connection)

Uploader that imports JUnit XML test results into JIRA.

upload(test_result_info, jira_info, skip_upload=False)

Upload the given test results.

Parameters:
  • test_result_info (TestResultInfo) – information about the test result

  • jira_info (JiraInfoData) – JIRA info data

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

Return type:

Optional[MultiPartResults]

Returns:

the response items from call

class ska_ser_xray.upload.upload_multipart.RobotUploader(connection)

Uploader that imports Robot Framework test results into JIRA.

upload(test_result_info, jira_info, skip_upload=False)

Upload the given test results.

Parameters:
  • test_result_info (TestResultInfo) – information about the test result

  • jira_info (JiraInfoData) – JIRA info data

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

Return type:

Optional[MultiPartResults]

Returns:

the response items from call

class ska_ser_xray.upload.upload_multipart.Uploader

Abstract base class for test result uploaders.

abstract upload(test_result_info, jira_info, skip_upload=False)

Upload the given test results.

Parameters:
  • test_result_info (TestResultInfo) – information about the test result

  • jira_info (JiraInfoData) – JIRA info data

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

Return type:

Optional[MultiPartResults]

Returns:

the response items from call

ska_ser_xray.upload.upload_multipart.get_uploader(test_framework, connection)

Get the uploader for the given test framework.

Parameters:
  • test_framework (TestFramework) – the test framework to construct the uploader for

  • connection (Connection) – the JIRA connection to use for the upload

Return type:

Uploader

Returns:

Uploader

Module to create JIRA endpoint connections.

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

JIRA connection object.

push_multipart(endpoint, *parts, skip_upload=False)

Push results to JIRA.

Parameters:
  • endpoint (str) – the endpoint to push to

  • 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.

Cucumber support

Module to parse test result information from Cucumber results.

ska_ser_xray.cucumber.get_test_result_info.get_test_result_info(results_file, exec_config_data)

Get the test result information from a Cucumber results file.

Parameters:
Return type:

TestResultInfo

Returns:

test result information.

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

class ska_ser_xray.cucumber.pytest_report_data.PytestReportData(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_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.

Returns:

set of keywords

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

class ska_ser_xray.cucumber.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.

Returns:

A set of exclusively owned tags

Robot Framework support

Module to parse test result information from Robot Framework results.

class ska_ser_xray.robot.get_test_result_info.ExecutionInfoCollector

Collect execution information about the test result.

end_suite(suite)

Visit each suite to determine the lowest starttime and highest endtime.

Parameters:

suite (TestSuite) – the suite being visited

Return type:

None

end_test(test)

Visit each test to determine the lowest starttime and highest endtime.

Parameters:

test (TestCase) – the test being visited

Return type:

None

property end_time: datetime

Get the end time in the local timezone.

Returns:

end time

property start_time: datetime

Get the start time in the local timezone.

Returns:

start time

class ska_ser_xray.robot.get_test_result_info.TestTagCollector

Collect tags shared by all tests in the suite.

end_test(test)

Visit each test to collect its tags.

Parameters:

test (TestCase) – the test being visited

Return type:

None

ska_ser_xray.robot.get_test_result_info.get_test_result_info(results_file)

Get the test result information from a Robot Framework results file.

Parameters:

results_file (Path) – Path to the Robot Framework output file

Return type:

TestResultInfo

Returns:

test result information.

Pytest JUnit support

Module to parse test result information from pytest results.

class ska_ser_xray.pytest.get_test_result_info.ExecutionInfoCollector

Collect execution information about the test suites.

collect(suite)

Collect execution info from the given test suite.

Parameters:

suite (Testsuite) – test suite

Return type:

None

property end_time: datetime

Get the end time in the local timezone.

Returns:

end time

property start_time: datetime

Get the start time in the local timezone.

Returns:

start time

class ska_ser_xray.pytest.get_test_result_info.TestPlanTagCollector

Collect test plan tags from the test suites.

collect(suite)

Collect test plan tags from the given test suite.

Parameters:

suite (Testsuite) – test suite

Return type:

None

property tags: Set[str]

Property to retrieve collected test plan tags.

Returns:

set of tags

ska_ser_xray.pytest.get_test_result_info.get_test_result_info(results_file)

Get the test result information from a Pytest Junit XML report.

Parameters:

results_file (Path) – Path to the Pytest Junit XML report

Return type:

TestResultInfo

Returns:

test result information.