testframework.clients.ops.tester package

This module provides the tester package extension for the ops client.

class testframework.clients.ops.tester.OpsClient(tb: TestBench, default_timeout: int)

Bases: OpsBaseClient

Ops Client class for testing operations.

Also known as the β€œNo Brainer” client

This class inherits from the OpsBaseClient class and provides additional methods that are related to managing the OpsContainer in a test context

If you’re intending to write tests against a testbench with testbrain on it, we recommend using the OpsClientRecorded class, which adds the functionality of annototations in Grafana. usage:

Example

>>> from testframework.clients.ops.tester.tester_client_recorded import OpsClientRecorded
assert_response_success(response: Response) None

Asserts that the response is successful. :param response: The response object to be validated. :type response: requests.Response

Returns:

If function returns then assertion passes

Return type:

None

Raises:

AssertionError – If the response status code is not in the range of 2xx.

assert_sensor_value_matches(sensor_name: GlobalSensorName, expected: str | int)

Check if the sensor value matches the expected value.

Parameters:
  • ops_interface (OpsInterface) – The OpsInterface object used to interact with the API.

  • sensor_name (GlobalSensorName) – The name of the sensor.

  • expected (str | int) – The expected value of the sensor.

Raises:

AssertionError – If the sensor value does not match the expected value or if the API call fails.

check_battery(battery_level_lowerl: float = 30, battery_level_upperl: float = 85)

Check if the battery charge level is within the desired limits.

Parameters:
  • ops_interface (OpsInterface) – The interface object for interacting with the ops system.

  • battery_level_lowerl (float, optional) – The lower limit for the battery charge level. Defaults to 30.

  • battery_level_upperl (float, optional) – The upper limit for the battery charge level. Defaults to 85.

Raises:

AssertionError – If the validation check for the value fails.

check_errors()

Checks that no error codes are present in the system.

Parameters:

ops_interface (OpsInterface) – The interface for interacting with the system.

Raises:

AssertionError – If getting the error state from the API was not successful.

check_preconditions() None

Executes all available precondition checks. - check_properties_inverter - check_properties_battery - check_default_params - check_errors - check_battery :param ops_interface: The interface for interacting with the operations. :type ops_interface: OpsInterface

Returns:

None

check_properties_battery()

Validate battery properties in testbench with reference value

check_properties_dongle()

Validate dongle properties in testbench with reference value.

Raises:

AssertionError – If the reference data of the testbench is missing or if the serial number is not matching.

check_properties_inverter()

Checks the properties of the inverter device against the inventory data. If any of the properties do not match the inventory data, an AssertionError is raised.

Args:

Raises:

AssertionError – If any of the properties do not match the reference data.

check_value(value: float | int, comp: Comparators, expected: list[float | int], break_on_fail: bool | None = False) float

Checks value with given comparator.

Parameters:
  • value (float | int) – The value to be checked.

  • comp (Comparators) – The comparator to be used for comparison.

  • expected (List[float | int]) – The expected values for comparison.

  • break_on_fail (Optional[bool]) – If True, the test will stop immediately on failure. If False or None, the test will continue and log the failure at the end. Defaults to None.

Returns:

The original value.

Return type:

float

ensure_default_params() None

Check that default parameters are applied from Ops API and apply them if not.

This function sends a POST request to the Ops API to set the default parameters. If the API response is 200, it means that the default parameters were successfully set. If the API response is not 200, it raises an exception.

Parameters:

ops_interface (OpsInterface) – An instance of the OpsInterface class.

Raises:

AssertionError – If the API response is not 200.

get_manufacturer(actual_device_properties: list[DeviceProperties]) str

Fetches the manufacturer from the device properties.

Parameters:

actual_device_properties (list) – A list of device properties.

Returns:

The manufacturer of the device.

Return type:

str

Raises:

AssertionError – If the manufacturer is None.

run_validation_check(value, comp, expected)

Runs a validation check on the given value using the specified comparison operator and expected value.

Parameters:
  • value – The value to be validated.

  • comp – The comparison operator to be used for validation.

  • expected – The expected value or range of values for comparison.

Returns:

None

Raises:

AssertionError – If the validation check fails.

Submodules