xtesting.core.testcase module

Define the parent class of all Xtesting TestCases.

class xtesting.core.testcase.TestCase(**kwargs)

Bases: object

Base model for single test case.

EX_OK = 0

everything is OK

EX_PUBLISH_ARTIFACTS_ERROR = 66

publish_artifacts() failed

EX_PUSH_TO_DB_ERROR = 69

push_to_db() failed

EX_RUN_ERROR = 70

run() failed

EX_TESTCASE_FAILED = 68

results are false

EX_TESTCASE_SKIPPED = 67

requirements are unmet

check_requirements()

Check the requirements of the test case.

It can be overriden on purpose.

clean()

Clean the resources.

It can be overriden if resources must be deleted after running the test case.

dir_results = '/var/lib/xtesting/results'
get_duration()

Return the duration of the test case.

Returns:
duration if start_time and stop_time are set “XX:XX” otherwise.
headers = {'Content-Type': 'application/json'}
is_successful()

Interpret the result of the test case.

It allows getting the result of TestCase. It completes run() which only returns the execution status.

It can be overriden if checking result is not suitable.

Returns:
TestCase.EX_OK if result is ‘PASS’. TestCase.EX_TESTCASE_SKIPPED if test case is skipped. TestCase.EX_TESTCASE_FAILED otherwise.
publish_artifacts()

Push the artifacts to the S3 repository.

It allows publishing the artifacts.

It could be overriden if the common implementation is not suitable.

The credentials must be configured before publishing the artifacts:

  • fill ~/.aws/credentials or ~/.boto,
  • set AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY in env.

The next vars must be set in env:

Returns:
TestCase.EX_OK if artifacts were published to repository. TestCase.EX_PUBLISH_ARTIFACTS_ERROR otherwise.
push_to_db()

Push the results of the test case to the DB.

It allows publishing the results and checking the status.

It could be overriden if the common implementation is not suitable.

The following attributes must be set before pushing the results to DB:

  • project_name,
  • case_name,
  • result,
  • start_time,
  • stop_time.

The next vars must be set in env:

  • TEST_DB_URL,
  • INSTALLER_TYPE,
  • DEPLOY_SCENARIO,
  • NODE_NAME,
  • BUILD_TAG.
Returns:
TestCase.EX_OK if results were pushed to DB. TestCase.EX_PUSH_TO_DB_ERROR otherwise.
run(**kwargs)

Run the test case.

It allows running TestCase and getting its execution status.

The subclasses must override the default implementation which is false on purpose.

The new implementation must set the following attributes to push the results to DB:

  • result,
  • start_time,
  • stop_time.
Args:
kwargs: Arbitrary keyword arguments.