diff options
Diffstat (limited to 'tests/unit')
-rw-r--r-- | tests/unit/test_eos_version.py | 152 | ||||
-rw-r--r-- | tests/unit/test_object_downloader.py | 128 |
2 files changed, 171 insertions, 109 deletions
diff --git a/tests/unit/test_eos_version.py b/tests/unit/test_eos_version.py index 1b97ffc..82f1269 100644 --- a/tests/unit/test_eos_version.py +++ b/tests/unit/test_eos_version.py @@ -5,126 +5,166 @@ # flake8: noqa: W503 # flake8: noqa: W1202 -from __future__ import (absolute_import, division, print_function) +from __future__ import absolute_import, division, print_function import sys -from loguru import logger + import pytest -from eos_downloader.models.version import EosVersion, BASE_VERSION_STR +from loguru import logger + +from eos_downloader.models.version import BASE_VERSION_STR, EosVersion from tests.lib.dataset import eos_version from tests.lib.fixtures import generate_test_ids_list logger.remove() logger.add(sys.stderr, level="DEBUG") -@pytest.mark.parametrize("EOS_VERSION", eos_version, ids=generate_test_ids_list(eos_version,key='version')) + +@pytest.mark.parametrize( + "EOS_VERSION", eos_version, ids=generate_test_ids_list(eos_version, key="version") +) def test_eos_version_from_str(EOS_VERSION): - version = EosVersion.from_str(EOS_VERSION['version']) - if EOS_VERSION['is_valid']: - assert version.major == EOS_VERSION['major'] - assert version.minor == EOS_VERSION['minor'] - assert version.patch == EOS_VERSION['patch'] - assert version.rtype == EOS_VERSION['rtype'] + version = EosVersion.from_str(EOS_VERSION["version"]) + if EOS_VERSION["is_valid"]: + assert version.major == EOS_VERSION["major"] + assert version.minor == EOS_VERSION["minor"] + assert version.patch == EOS_VERSION["patch"] + assert version.rtype == EOS_VERSION["rtype"] else: assert str(version) == BASE_VERSION_STR -@pytest.mark.parametrize("EOS_VERSION", eos_version, ids=generate_test_ids_list(eos_version,key='version')) +@pytest.mark.parametrize( + "EOS_VERSION", eos_version, ids=generate_test_ids_list(eos_version, key="version") +) def test_eos_version_to_str(EOS_VERSION): version = EosVersion(**EOS_VERSION) - if EOS_VERSION['is_valid']: - assert version.major == EOS_VERSION['major'] - assert version.minor == EOS_VERSION['minor'] - assert version.patch == EOS_VERSION['patch'] - assert version.rtype == EOS_VERSION['rtype'] + if EOS_VERSION["is_valid"]: + assert version.major == EOS_VERSION["major"] + assert version.minor == EOS_VERSION["minor"] + assert version.patch == EOS_VERSION["patch"] + assert version.rtype == EOS_VERSION["rtype"] + -@pytest.mark.parametrize("EOS_VERSION", eos_version, ids=generate_test_ids_list(eos_version,key='version')) +@pytest.mark.parametrize( + "EOS_VERSION", eos_version, ids=generate_test_ids_list(eos_version, key="version") +) def test_eos_version_branch(EOS_VERSION): - if EOS_VERSION['is_valid']: + if EOS_VERSION["is_valid"]: version = EosVersion(**EOS_VERSION) assert version.branch == f'{EOS_VERSION["major"]}.{EOS_VERSION["minor"]}' -@pytest.mark.parametrize("EOS_VERSION", eos_version, ids=generate_test_ids_list(eos_version,key='version')) + +@pytest.mark.parametrize( + "EOS_VERSION", eos_version, ids=generate_test_ids_list(eos_version, key="version") +) def test_eos_version_eq_operator(EOS_VERSION): - if not EOS_VERSION['is_valid']: - pytest.skip('not a valid version to test') + if not EOS_VERSION["is_valid"]: + pytest.skip("not a valid version to test") version = EosVersion(**EOS_VERSION) - logger.warning(f'version is: {version.dict()}') + logger.warning(f"version is: {version.dict()}") assert version == version -@pytest.mark.parametrize("EOS_VERSION", eos_version, ids=generate_test_ids_list(eos_version,key='version')) + +@pytest.mark.parametrize( + "EOS_VERSION", eos_version, ids=generate_test_ids_list(eos_version, key="version") +) def test_eos_version_ge_operator(EOS_VERSION): - if not EOS_VERSION['is_valid']: - pytest.skip('not a valid version to test') + if not EOS_VERSION["is_valid"]: + pytest.skip("not a valid version to test") version = EosVersion(**EOS_VERSION) version_b = EosVersion.from_str(BASE_VERSION_STR) assert version >= version_b -@pytest.mark.parametrize("EOS_VERSION", eos_version, ids=generate_test_ids_list(eos_version,key='version')) + +@pytest.mark.parametrize( + "EOS_VERSION", eos_version, ids=generate_test_ids_list(eos_version, key="version") +) def test_eos_version_gs_operator(EOS_VERSION): - if not EOS_VERSION['is_valid']: - pytest.skip('not a valid version to test') + if not EOS_VERSION["is_valid"]: + pytest.skip("not a valid version to test") version = EosVersion(**EOS_VERSION) version_b = EosVersion.from_str(BASE_VERSION_STR) assert version > version_b -@pytest.mark.parametrize("EOS_VERSION", eos_version, ids=generate_test_ids_list(eos_version,key='version')) + +@pytest.mark.parametrize( + "EOS_VERSION", eos_version, ids=generate_test_ids_list(eos_version, key="version") +) def test_eos_version_le_operator(EOS_VERSION): - if not EOS_VERSION['is_valid']: - pytest.skip('not a valid version to test') + if not EOS_VERSION["is_valid"]: + pytest.skip("not a valid version to test") version = EosVersion(**EOS_VERSION) version_b = EosVersion.from_str(BASE_VERSION_STR) assert version_b <= version -@pytest.mark.parametrize("EOS_VERSION", eos_version, ids=generate_test_ids_list(eos_version,key='version')) + +@pytest.mark.parametrize( + "EOS_VERSION", eos_version, ids=generate_test_ids_list(eos_version, key="version") +) def test_eos_version_ls_operator(EOS_VERSION): - if not EOS_VERSION['is_valid']: - pytest.skip('not a valid version to test') + if not EOS_VERSION["is_valid"]: + pytest.skip("not a valid version to test") version = EosVersion(**EOS_VERSION) version_b = EosVersion.from_str(BASE_VERSION_STR) assert version_b < version -@pytest.mark.parametrize("EOS_VERSION", eos_version, ids=generate_test_ids_list(eos_version,key='version')) + +@pytest.mark.parametrize( + "EOS_VERSION", eos_version, ids=generate_test_ids_list(eos_version, key="version") +) def test_eos_version_ne_operator(EOS_VERSION): - if not EOS_VERSION['is_valid']: - pytest.skip('not a valid version to test') + if not EOS_VERSION["is_valid"]: + pytest.skip("not a valid version to test") version = EosVersion(**EOS_VERSION) version_b = EosVersion.from_str(BASE_VERSION_STR) assert version_b != version -@pytest.mark.parametrize("EOS_VERSION", eos_version, ids=generate_test_ids_list(eos_version,key='version')) + +@pytest.mark.parametrize( + "EOS_VERSION", eos_version, ids=generate_test_ids_list(eos_version, key="version") +) def test_eos_version_match(EOS_VERSION): - if not EOS_VERSION['is_valid']: - pytest.skip('not a valid version to test') + if not EOS_VERSION["is_valid"]: + pytest.skip("not a valid version to test") version = EosVersion(**EOS_VERSION) assert version.match(f'=={EOS_VERSION["version"]}') - assert version.match(f'!={BASE_VERSION_STR}') - assert version.match(f'>={BASE_VERSION_STR}') - assert version.match(f'>{BASE_VERSION_STR}') - assert version.match('<=4.99.0F') - assert version.match('<4.99.0F') + assert version.match(f"!={BASE_VERSION_STR}") + assert version.match(f">={BASE_VERSION_STR}") + assert version.match(f">{BASE_VERSION_STR}") + assert version.match("<=4.99.0F") + assert version.match("<4.99.0F") + -@pytest.mark.parametrize("EOS_VERSION", eos_version, ids=generate_test_ids_list(eos_version,key='version')) +@pytest.mark.parametrize( + "EOS_VERSION", eos_version, ids=generate_test_ids_list(eos_version, key="version") +) def test_eos_version_is_in_branch(EOS_VERSION): - if not EOS_VERSION['is_valid']: - pytest.skip('not a valid version to test') + if not EOS_VERSION["is_valid"]: + pytest.skip("not a valid version to test") version = EosVersion(**EOS_VERSION) assert version.is_in_branch(f"{EOS_VERSION['major']}.{EOS_VERSION['minor']}") -@pytest.mark.parametrize("EOS_VERSION", eos_version, ids=generate_test_ids_list(eos_version,key='version')) + +@pytest.mark.parametrize( + "EOS_VERSION", eos_version, ids=generate_test_ids_list(eos_version, key="version") +) def test_eos_version_match_exception(EOS_VERSION): - if not EOS_VERSION['is_valid']: - pytest.skip('not a valid version to test') + if not EOS_VERSION["is_valid"]: + pytest.skip("not a valid version to test") with pytest.raises(Exception) as e_info: version = EosVersion(**EOS_VERSION) assert version.match(f'+={EOS_VERSION["version"]}') - logger.info(f'receive exception: {e_info}') + logger.info(f"receive exception: {e_info}") + -@pytest.mark.parametrize("EOS_VERSION", eos_version, ids=generate_test_ids_list(eos_version,key='version')) +@pytest.mark.parametrize( + "EOS_VERSION", eos_version, ids=generate_test_ids_list(eos_version, key="version") +) def test_eos_version_compare_exception(EOS_VERSION): - if not EOS_VERSION['is_valid']: - pytest.skip('not a valid version to test') + if not EOS_VERSION["is_valid"]: + pytest.skip("not a valid version to test") with pytest.raises(Exception) as e_info: version = EosVersion(**EOS_VERSION) version._compare(BASE_VERSION_STR) - logger.info(f'receive exception: {e_info}') + logger.info(f"receive exception: {e_info}") diff --git a/tests/unit/test_object_downloader.py b/tests/unit/test_object_downloader.py index 8237b1c..d178dfc 100644 --- a/tests/unit/test_object_downloader.py +++ b/tests/unit/test_object_downloader.py @@ -14,30 +14,41 @@ from loguru import logger import eos_downloader from eos_downloader.data import DATA_MAPPING from eos_downloader.eos import EOSDownloader -from tests.lib.dataset import eos_dataset_invalid, eos_dataset_valid, eos_token, eos_token_invalid +from tests.lib.dataset import ( + eos_dataset_invalid, + eos_dataset_valid, + eos_token, + eos_token_invalid, +) from tests.lib.fixtures import create_download_instance from tests.lib.helpers import default_filename, is_on_github_actions logger.remove() logger.add(sys.stderr, level="DEBUG") + @pytest.mark.usefixtures("create_download_instance") -@pytest.mark.parametrize("DOWNLOAD_INFO", eos_dataset_valid, ids=['EOS-sha512', 'EOS-md5' ,'vEOS-lab-no-hash']) +@pytest.mark.parametrize( + "DOWNLOAD_INFO", + eos_dataset_valid, + ids=["EOS-sha512", "EOS-md5", "vEOS-lab-no-hash"], +) @pytest.mark.eos_download -class TestEosDownload_valid(): +class TestEosDownload_valid: def test_data(self, DOWNLOAD_INFO): - logger.info(f'test input: {DOWNLOAD_INFO}') - logger.info(f'test build: {self.eos_downloader.__dict__}') + logger.info(f"test input: {DOWNLOAD_INFO}") + logger.info(f"test build: {self.eos_downloader.__dict__}") def test_eos_download_create(self, DOWNLOAD_INFO): my_download = eos_downloader.eos.EOSDownloader( - image=DOWNLOAD_INFO['image'], - software=DOWNLOAD_INFO['software'], - version=DOWNLOAD_INFO['version'], + image=DOWNLOAD_INFO["image"], + software=DOWNLOAD_INFO["software"], + version=DOWNLOAD_INFO["version"], token=eos_token, - hash_method='sha512sum') + hash_method="sha512sum", + ) logger.info(my_download) - assert isinstance(my_download, eos_downloader.eos.EOSDownloader) + assert isinstance(my_download, eos_downloader.eos.EOSDownloader) def test_eos_download_repr_string(self, DOWNLOAD_INFO): expected = f"{DOWNLOAD_INFO['software']} - {DOWNLOAD_INFO['image']} - {DOWNLOAD_INFO['version']}" @@ -45,47 +56,56 @@ class TestEosDownload_valid(): assert str(self.eos_downloader) == expected def test_eos_download_build_filename(self, DOWNLOAD_INFO): - assert self.eos_downloader._build_filename() == DOWNLOAD_INFO['filename'] + assert self.eos_downloader._build_filename() == DOWNLOAD_INFO["filename"] - @pytest.mark.dependency(name='authentication') - @pytest.mark.skipif(eos_token == eos_token_invalid, reason="Token is not set correctly") + @pytest.mark.dependency(name="authentication") + @pytest.mark.skipif( + eos_token == eos_token_invalid, reason="Token is not set correctly" + ) @pytest.mark.skipif(is_on_github_actions(), reason="Running on Github Runner") # @pytest.mark.xfail(reason="Deliberate - CI not set for testing AUTH") @pytest.mark.webtest def test_eos_download_authenticate(self): assert self.eos_downloader.authenticate() is True - @pytest.mark.dependency(depends=["authentication"], scope='class') + @pytest.mark.dependency(depends=["authentication"], scope="class") @pytest.mark.webtest def test_eos_download_get_remote_file_path(self, DOWNLOAD_INFO): - assert self.eos_downloader._get_remote_filepath() == DOWNLOAD_INFO['remote_path'] + assert ( + self.eos_downloader._get_remote_filepath() == DOWNLOAD_INFO["remote_path"] + ) - @pytest.mark.dependency(depends=["authentication"], scope='class') + @pytest.mark.dependency(depends=["authentication"], scope="class") @pytest.mark.webtest def test_eos_download_get_file_url(self, DOWNLOAD_INFO): - url = self.eos_downloader._get_url(remote_file_path = DOWNLOAD_INFO['remote_path']) + url = self.eos_downloader._get_url( + remote_file_path=DOWNLOAD_INFO["remote_path"] + ) logger.info(url) - assert 'https://downloads.arista.com/EOS-USA/Active%20Releases/' in url + assert "https://downloads.arista.com/EOS-USA/Active%20Releases/" in url -@pytest.mark.usefixtures("create_download_instance") -@pytest.mark.parametrize("DOWNLOAD_INFO", eos_dataset_invalid, ids=['EOS-FAKE']) -class TestEosDownload_invalid(): +@pytest.mark.usefixtures("create_download_instance") +@pytest.mark.parametrize("DOWNLOAD_INFO", eos_dataset_invalid, ids=["EOS-FAKE"]) +class TestEosDownload_invalid: def test_data(self, DOWNLOAD_INFO): - logger.info(f'test input: {dict(DOWNLOAD_INFO)}') - logger.info(f'test build: {self.eos_downloader.__dict__}') + logger.info(f"test input: {dict(DOWNLOAD_INFO)}") + logger.info(f"test build: {self.eos_downloader.__dict__}") def test_eos_download_login_error(self, DOWNLOAD_INFO): my_download = eos_downloader.eos.EOSDownloader( - image=DOWNLOAD_INFO['image'], - software=DOWNLOAD_INFO['software'], - version=DOWNLOAD_INFO['version'], + image=DOWNLOAD_INFO["image"], + software=DOWNLOAD_INFO["software"], + version=DOWNLOAD_INFO["version"], token=eos_token_invalid, - hash_method=DOWNLOAD_INFO['expected_hash']) + hash_method=DOWNLOAD_INFO["expected_hash"], + ) assert my_download.authenticate() is False - @pytest.mark.dependency(name='authentication') - @pytest.mark.skipif(eos_token == eos_token_invalid, reason="Token is not set correctly") + @pytest.mark.dependency(name="authentication") + @pytest.mark.skipif( + eos_token == eos_token_invalid, reason="Token is not set correctly" + ) @pytest.mark.skipif(is_on_github_actions(), reason="Running on Github Runner") # @pytest.mark.xfail(reason="Deliberate - CI not set for testing AUTH") @pytest.mark.webtest @@ -96,46 +116,48 @@ class TestEosDownload_invalid(): # @pytest.mark.skip(reason="Not yet implemented in lib") def test_eos_file_name_with_incorrect_software(self, DOWNLOAD_INFO): - self.eos_downloader.software = 'FAKE' - logger.info(f'test build: {self.eos_downloader.__dict__}') + self.eos_downloader.software = "FAKE" + logger.info(f"test build: {self.eos_downloader.__dict__}") with pytest.raises(ValueError) as e_info: result = self.eos_downloader._build_filename() - logger.info(f'receive exception: {e_info}') - self.eos_downloader.software = DOWNLOAD_INFO['software'] + logger.info(f"receive exception: {e_info}") + self.eos_downloader.software = DOWNLOAD_INFO["software"] @pytest.mark.webtest - @pytest.mark.dependency(depends=["authentication"], scope='class') - def test_eos_download_get_remote_file_path_for_invlaid_software(self, DOWNLOAD_INFO): - self.eos_downloader.software = 'FAKE' - logger.info(f'Platform set to: {self.eos_downloader.software}') - logger.info(f'test build: {self.eos_downloader.__dict__}') + @pytest.mark.dependency(depends=["authentication"], scope="class") + def test_eos_download_get_remote_file_path_for_invlaid_software( + self, DOWNLOAD_INFO + ): + self.eos_downloader.software = "FAKE" + logger.info(f"Platform set to: {self.eos_downloader.software}") + logger.info(f"test build: {self.eos_downloader.__dict__}") with pytest.raises(ValueError) as e_info: result = self.eos_downloader._build_filename() - logger.info(f'receive exception: {e_info}') - self.eos_downloader.software = DOWNLOAD_INFO['software'] + logger.info(f"receive exception: {e_info}") + self.eos_downloader.software = DOWNLOAD_INFO["software"] # IMAGE TESTING def test_eos_file_name_with_incorrect_image(self, DOWNLOAD_INFO): - self.eos_downloader.image = 'FAKE' - logger.info(f'Image set to: {self.eos_downloader.image}') - assert DOWNLOAD_INFO['filename'] == self.eos_downloader._build_filename() - self.eos_downloader.software == DOWNLOAD_INFO['image'] + self.eos_downloader.image = "FAKE" + logger.info(f"Image set to: {self.eos_downloader.image}") + assert DOWNLOAD_INFO["filename"] == self.eos_downloader._build_filename() + self.eos_downloader.software == DOWNLOAD_INFO["image"] @pytest.mark.webtest - @pytest.mark.dependency(depends=["authentication"], scope='class') + @pytest.mark.dependency(depends=["authentication"], scope="class") def test_eos_download_get_remote_file_path_for_invlaid_image(self, DOWNLOAD_INFO): - self.eos_downloader.image = 'FAKE' - logger.info(f'Image set to: {self.eos_downloader.image}') + self.eos_downloader.image = "FAKE" + logger.info(f"Image set to: {self.eos_downloader.image}") assert self.eos_downloader.authenticate() is True - assert DOWNLOAD_INFO['filename'] == self.eos_downloader._build_filename() - self.eos_downloader.image = DOWNLOAD_INFO['image'] + assert DOWNLOAD_INFO["filename"] == self.eos_downloader._build_filename() + self.eos_downloader.image = DOWNLOAD_INFO["image"] # VERSION TESTING @pytest.mark.webtest - @pytest.mark.dependency(depends=["authentication"], scope='class') + @pytest.mark.dependency(depends=["authentication"], scope="class") def test_eos_download_get_remote_file_path_for_invlaid_version(self, DOWNLOAD_INFO): - self.eos_downloader.version = 'FAKE' - logger.info(f'Version set to: {self.eos_downloader.version}') - assert self.eos_downloader._get_remote_filepath() == ''
\ No newline at end of file + self.eos_downloader.version = "FAKE" + logger.info(f"Version set to: {self.eos_downloader.version}") + assert self.eos_downloader._get_remote_filepath() == "" |