summaryrefslogtreecommitdiffstats
path: root/tests/lib
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2023-05-11 09:25:01 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2023-06-12 05:31:22 +0000
commit7ad1d0e0af695fa7f872b740a1bb7b2897eb41bd (patch)
tree13dd59a8ea98206a8c56ffd466f59c146f9f19c7 /tests/lib
parentInitial commit. (diff)
downloadeos-downloader-7ad1d0e0af695fa7f872b740a1bb7b2897eb41bd.tar.xz
eos-downloader-7ad1d0e0af695fa7f872b740a1bb7b2897eb41bd.zip
Adding upstream version 0.8.1.upstream/0.8.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/lib')
-rw-r--r--tests/lib/__init__.py0
-rw-r--r--tests/lib/dataset.py116
-rw-r--r--tests/lib/fixtures.py69
-rw-r--r--tests/lib/helpers.py40
4 files changed, 225 insertions, 0 deletions
diff --git a/tests/lib/__init__.py b/tests/lib/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/tests/lib/__init__.py
diff --git a/tests/lib/dataset.py b/tests/lib/dataset.py
new file mode 100644
index 0000000..1286456
--- /dev/null
+++ b/tests/lib/dataset.py
@@ -0,0 +1,116 @@
+#!/usr/bin/python
+# coding: utf-8 -*-
+# pylint: disable=logger-format-interpolation
+# pylint: disable=dangerous-default-value
+# flake8: noqa: W503
+# flake8: noqa: W1202
+
+from __future__ import (absolute_import, division, print_function)
+import os
+import eos_downloader
+from eos_downloader.eos import EOSDownloader
+from eos_downloader.data import DATA_MAPPING
+
+
+# --------------------------------------------------------------- #
+# MOOCK data to use for testing
+# --------------------------------------------------------------- #
+
+# Get Auth token
+# eos_token = os.getenv('ARISTA_TOKEN')
+eos_token = os.getenv('ARISTA_TOKEN', 'invalid_token')
+eos_token_invalid = 'invalid_token'
+
+eos_dataset_valid = [
+ {
+ 'image': 'EOS',
+ 'version': '4.26.3M',
+ 'software': 'EOS',
+ 'filename': 'EOS-4.26.3M.swi',
+ 'expected_hash': 'sha512sum',
+ 'remote_path': '/support/download/EOS-USA/Active Releases/4.26/EOS-4.26.3M/EOS-4.26.3M.swi',
+ 'compute_checksum': True
+ },
+ {
+ 'image': 'EOS',
+ 'version': '4.25.6M',
+ 'software': 'EOS',
+ 'filename': 'EOS-4.25.6M.swi',
+ 'expected_hash': 'md5sum',
+ 'remote_path': '/support/download/EOS-USA/Active Releases/4.25/EOS-4.25.6M/EOS-4.25.6M.swi',
+ 'compute_checksum': True
+ },
+ {
+ 'image': 'vEOS-lab',
+ 'version': '4.25.6M',
+ 'software': 'EOS',
+ 'filename': 'vEOS-lab-4.25.6M.vmdk',
+ 'expected_hash': 'md5sum',
+ 'remote_path': '/support/download/EOS-USA/Active Releases/4.25/EOS-4.25.6M/vEOS-lab/vEOS-lab-4.25.6M.vmdk',
+ 'compute_checksum': False
+ }
+]
+
+
+eos_dataset_invalid = [
+ {
+ 'image': 'default',
+ 'version': '4.26.3M',
+ 'software': 'EOS',
+ 'filename': 'EOS-4.26.3M.swi',
+ 'expected_hash': 'sha512sum',
+ 'remote_path': '/support/download/EOS-USA/Active Releases/4.26/EOS-4.26.3M/EOS-4.26.3M.swi',
+ 'compute_checksum': True
+ }
+]
+
+eos_version = [
+ {
+ 'version': 'EOS-4.23.1F',
+ 'is_valid': True,
+ 'major': 4,
+ 'minor': 23,
+ 'patch': 1,
+ 'rtype': 'F'
+ },
+ {
+ 'version': 'EOS-4.23.0',
+ 'is_valid': True,
+ 'major': 4,
+ 'minor': 23,
+ 'patch': 0,
+ 'rtype': None
+ },
+ {
+ 'version': 'EOS-4.23',
+ 'is_valid': True,
+ 'major': 4,
+ 'minor': 23,
+ 'patch': 0,
+ 'rtype': None
+ },
+ {
+ 'version': 'EOS-4.23.1M',
+ 'is_valid': True,
+ 'major': 4,
+ 'minor': 23,
+ 'patch': 1,
+ 'rtype': 'M'
+ },
+ {
+ 'version': 'EOS-4.23.1.F',
+ 'is_valid': True,
+ 'major': 4,
+ 'minor': 23,
+ 'patch': 1,
+ 'rtype': 'F'
+ },
+ {
+ 'version': 'EOS-5.23.1F',
+ 'is_valid': False,
+ 'major': 4,
+ 'minor': 23,
+ 'patch': 1,
+ 'rtype': 'F'
+ },
+] \ No newline at end of file
diff --git a/tests/lib/fixtures.py b/tests/lib/fixtures.py
new file mode 100644
index 0000000..4515f9b
--- /dev/null
+++ b/tests/lib/fixtures.py
@@ -0,0 +1,69 @@
+#!/usr/bin/python
+# coding: utf-8 -*-
+# pylint: disable=logger-format-interpolation
+# pylint: disable=dangerous-default-value
+# flake8: noqa: W503
+# flake8: noqa: W1202
+
+from __future__ import (absolute_import, division, print_function)
+import os
+import pytest
+import eos_downloader
+from typing import Dict, Any, List
+from tests.lib.dataset import eos_dataset_valid, eos_dataset_invalid, eos_token, eos_token_invalid
+
+
+
+@pytest.fixture
+@pytest.mark.parametrize("DOWNLOAD_INFO", eos_dataset_valid)
+def create_download_instance(request, DOWNLOAD_INFO):
+ # logger.info("Execute fixture to create class elements")
+ request.cls.eos_downloader = eos_downloader.eos.EOSDownloader(
+ image=DOWNLOAD_INFO['image'],
+ software=DOWNLOAD_INFO['software'],
+ version=DOWNLOAD_INFO['version'],
+ token=eos_token,
+ hash_method='sha512sum')
+ yield
+ # logger.info('Cleanup test environment')
+ os.system('rm -f {}*'.format(DOWNLOAD_INFO['filename']))
+
+
+def generate_test_ids_dict(val: Dict[str, Any], key: str = 'name') -> str:
+ """
+ generate_test_ids Helper to generate test ID for parametrize
+
+ Only related to SYSTEM_CONFIGLETS_TESTS structure
+
+ Parameters
+ ----------
+ val : dict
+ A configlet test structure
+
+ Returns
+ -------
+ str
+ Name of the configlet
+ """
+ if key in val.keys():
+ # note this wouldn't show any hours/minutes/seconds
+ return val[key]
+ return "undefined_test"
+
+def generate_test_ids_list(val: List[Dict[str, Any]], key: str = 'name') -> str:
+ """
+ generate_test_ids Helper to generate test ID for parametrize
+
+ Only related to SYSTEM_CONFIGLETS_TESTS structure
+
+ Parameters
+ ----------
+ val : dict
+ A configlet test structure
+
+ Returns
+ -------
+ str
+ Name of the configlet
+ """
+ return [ entry[key] if key in entry.keys() else 'unset_entry' for entry in val ]
diff --git a/tests/lib/helpers.py b/tests/lib/helpers.py
new file mode 100644
index 0000000..308f2a5
--- /dev/null
+++ b/tests/lib/helpers.py
@@ -0,0 +1,40 @@
+#!/usr/bin/python
+# coding: utf-8 -*-
+# pylint: disable=logger-format-interpolation
+# pylint: disable=dangerous-default-value
+# flake8: noqa: W503
+# flake8: noqa: W1202
+
+from __future__ import (absolute_import, division, print_function)
+
+import os
+
+from eos_downloader.data import DATA_MAPPING
+
+
+
+def default_filename(version: str, info):
+ """
+ default_filename Helper to build default filename
+
+ Parameters
+ ----------
+ version : str
+ EOS version
+ info : dict
+ TEST Inputs
+
+ Returns
+ -------
+ str
+ Filename
+ """
+ if version is None or info is None:
+ return None
+ return DATA_MAPPING[info['software']]['default']['prepend'] + '-' + version + '.swi'
+
+
+def is_on_github_actions():
+ """Check if code is running on a CI runner"""
+ if "CI" not in os.environ or not os.environ["CI"] or "GITHUB_RUN_ID" not in os.environ:
+ return False \ No newline at end of file