diff --git a/osfv_cli/README.md b/osfv_cli/README.md index d53e09e..2eb5994 100644 --- a/osfv_cli/README.md +++ b/osfv_cli/README.md @@ -275,3 +275,34 @@ unset SSH_AUTH_SOCK You can test local changes by running `poetry shell` first. Then, all `osfv_cli` calls will use the local files in repository, not installed package. + +## Tests + +OSFV CLI tests can be found in the `test` directory. +The tests are written in [Robot Framework](https://robotframework.org/), + +### Dependencies + +Enter development shell with test dependencies: + +```shell +poetry install --with test +poetry shell +``` + +### Required configs + +To test some functionalities related to SnipeIT, it is required to +use a configuration of a second SnipeIT user. The configuration +should be located at `~/.osfv-robot/snipeit.yaml`. +The API key and User ID must be valid, and different +from the one at `~/.osfv/snipeit.yaml`. +For details on SnipeIT configuration see [Customize the configuration](#customize-the-configuration). + +### Running tests + +When all the prerequisites are met, the test can be run: + +```shell +robot test +``` diff --git a/osfv_cli/pyproject.toml b/osfv_cli/pyproject.toml index 169ba11..7e54eb5 100644 --- a/osfv_cli/pyproject.toml +++ b/osfv_cli/pyproject.toml @@ -10,7 +10,7 @@ robotframework = "^7.2" [tool.poetry] name = "osfv" -version = "0.5.14" +version = "0.6.0" description = "Open Source Firmware Validation Command Line Interface Tool" authors = ["Maciej Pijanowski "] include = ["src/models/*.yml"] diff --git a/osfv_cli/src/osfv/libs/snipeit_api.py b/osfv_cli/src/osfv/libs/snipeit_api.py index 93ab27b..f3c2342 100644 --- a/osfv_cli/src/osfv/libs/snipeit_api.py +++ b/osfv_cli/src/osfv/libs/snipeit_api.py @@ -42,6 +42,8 @@ def __init__(self): "Authorization": f"Bearer {self.cfg_api_token}", } self.session = self._init_session() + self.all_assets = None + self.assets_cache = {} SNIPEIT_CONFIG_FILE_PATH = os.getenv( "SNIPEIT_CONFIG_FILE_PATH", os.path.expanduser("~/.osfv/snipeit.yml") @@ -175,6 +177,8 @@ def get_all_assets(self): Returns: list: A list of dictionaries, where each dictionary represents an asset. """ + if self.all_assets is not None: + return self.all_assets page = 1 all_assets = [] @@ -191,7 +195,9 @@ def get_all_assets(self): else: print(f"Error retrieving assets: {data}") break - + self.all_assets = all_assets + for asset in all_assets: + self.assets_cache[asset["id"]] = (success, asset) return all_assets def __retieve_custom_field_value(self, custom_fields, expected_field_name): @@ -484,7 +490,11 @@ def get_asset(self, asset_id): Returns: success status with a response object from server. """ - return self._request_get(f"{self.cfg_api_url}/hardware/{asset_id}") + if asset_id not in self.assets_cache: + self.assets_cache[asset_id] = self._request_get( + f"{self.cfg_api_url}/hardware/{asset_id}" + ) + return self.assets_cache[asset_id] def get_asset_model_name(self, asset_id): """ diff --git a/osfv_cli/src/osfv/rf/rte_robot.py b/osfv_cli/src/osfv/rf/rte_robot.py index b02c9d6..95fb1a4 100644 --- a/osfv_cli/src/osfv/rf/rte_robot.py +++ b/osfv_cli/src/osfv/rf/rte_robot.py @@ -4,7 +4,7 @@ from osfv.libs.rte import RTE from osfv.libs.snipeit_api import SnipeIT from osfv.libs.sonoff_api import SonoffDevice -from robot.api.deco import keyword +from robot.api.deco import keyword, library model_dict = { "odroid-h4-plus": "H4-PLUS", @@ -41,6 +41,7 @@ } +@library(scope="GLOBAL") class RobotRTE: def __init__(self, rte_ip, snipeit: bool, sonoff_ip=None, config=None): self.rte_ip = rte_ip