From e38a7b77a5f848638d2d18d4cb2e36697b32396b Mon Sep 17 00:00:00 2001 From: alexquali Date: Tue, 30 Jul 2024 14:01:02 +0200 Subject: [PATCH] Added support for old and new cloudshell-rest-api. Added possibility to pack shell without src folder --- dev_requirements.txt | 1 + requirements.txt | 2 +- setup.py | 5 +- shellfoundry/models/install_config.py | 1 - shellfoundry/utilities/archive_creator.py | 33 ++++---- .../cloudshell_api/client_wrapper.py | 27 ++++--- shellfoundry/utilities/driver_generator.py | 35 +++++--- shellfoundry/utilities/installer.py | 31 ++++--- .../utilities/shell_package_installer.py | 43 ++++++---- tests/__init__.py | 2 - tests/asserts.py | 11 +-- tests/helpers/__init__.py | 1 - tests/helpers/mocking_extensions.py | 8 +- tests/test_bootstrap.py | 8 +- tests/test_commands/test_config_command.py | 17 ++-- tests/test_commands/test_dist_command.py | 8 +- tests/test_commands/test_extend_command.py | 12 +-- tests/test_commands/test_generate_command.py | 7 +- tests/test_commands/test_install_command.py | 11 +-- tests/test_commands/test_list_command.py | 9 +-- tests/test_commands/test_new_command.py | 21 ++--- tests/test_commands/test_pack_command.py | 7 +- tests/test_commands/test_show_command.py | 8 +- tests/test_decorators/test_version_check.py | 12 +-- tests/test_models/test_install_config.py | 8 +- .../config/test_config_record.py | 7 +- .../test_password_modification.py | 8 +- .../standards/test_standards_retriever.py | 8 +- .../standards/test_standards_versions.py | 12 +-- .../test_client_wrapper.py | 23 ++---- tests/test_utilities/test_config_reader.py | 7 +- .../test_cookiecutter_integration.py | 8 +- tests/test_utilities/test_datamodel_merger.py | 1 - .../test_dependencies_packager.py | 7 +- tests/test_utilities/test_driver_generator.py | 12 +-- tests/test_utilities/test_filters.py | 1 - ...t_shell_installer.py => test_installer.py} | 14 +--- tests/test_utilities/test_package_builder.py | 10 +-- tests/test_utilities/test_repo_downloader.py | 5 +- .../test_shell_config_reader.py | 1 - tests/test_utilities/test_shell_package.py | 1 - .../test_shell_package_builder.py | 7 +- .../test_shell_package_installer.py | 80 +++++++++++-------- .../test_utilities/test_template_retriever.py | 9 +-- tests/test_utilities/test_template_url.py | 1 - .../test_utilities/test_template_versions.py | 8 +- .../test_shell_name_validations.py | 1 - .../test_utilities/test_version_utilities.py | 1 - tests/test_utilities/test_versions.py | 8 +- tox.ini | 9 +-- 50 files changed, 222 insertions(+), 355 deletions(-) rename tests/test_utilities/{test_shell_installer.py => test_installer.py} (76%) diff --git a/dev_requirements.txt b/dev_requirements.txt index 966817e..dd1db73 100644 --- a/dev_requirements.txt +++ b/dev_requirements.txt @@ -1,4 +1,5 @@ pre-commit tox +tox-factor -r test_requirements.txt -r requirements.txt diff --git a/requirements.txt b/requirements.txt index e2c320e..974af63 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,7 +3,7 @@ cookiecutter~=1.7.2 click~=7.1.2 pyyaml terminaltables -cloudshell-rest-api>=8.2.3.1,<9 +cloudshell-rest-api~=9.0.0 colorama giturlparse.py ruamel.yaml diff --git a/setup.py b/setup.py index 00b46b1..a64bb84 100644 --- a/setup.py +++ b/setup.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- from setuptools import find_packages, setup @@ -27,8 +26,8 @@ def get_file_content(file_name): + "\n\n" + get_file_content("HISTORY.rst"), long_description_content_type="text/markdown", - author="QualiSystems", - author_email="info@qualisystems.com", + author="Quali", + author_email="info@quali.com", url="https://github.com/QualiSystems/shellfoundry", packages=find_packages(exclude=["*.tests", "*.tests.*", "tests.*", "tests"]), package_data={"shellfoundry": ["data/*.yml", "data/*.json"]}, diff --git a/shellfoundry/models/install_config.py b/shellfoundry/models/install_config.py index cf06e6d..ea8a687 100644 --- a/shellfoundry/models/install_config.py +++ b/shellfoundry/models/install_config.py @@ -1,5 +1,4 @@ #!/usr/bin/python -# -*- coding: utf-8 -*- from shellfoundry.utilities.modifiers.configuration.password_modification import ( PasswordModification, diff --git a/shellfoundry/utilities/archive_creator.py b/shellfoundry/utilities/archive_creator.py index 1e79764..340e2af 100644 --- a/shellfoundry/utilities/archive_creator.py +++ b/shellfoundry/utilities/archive_creator.py @@ -15,20 +15,21 @@ def make_archive(output_filename, archive_format, source_dir): :param source_dir: Directory to scan for archiving :return: """ - if os.path.splitext(output_filename)[1] == "": - output_filename += ".zip" - output_dir = os.path.dirname(output_filename) - if output_dir and not os.path.exists(output_dir): - os.makedirs(output_dir) - relroot = source_dir - with zipfile.ZipFile(output_filename, "w", zipfile.ZIP_DEFLATED) as zip_f: - for root, dirs, files in os.walk(source_dir): - # add directory (needed for empty dirs) - zip_f.write(root, os.path.relpath(root, relroot)) - for file in files: - filename = os.path.join(root, file) - if os.path.isfile(filename): # regular files only - arcname = os.path.join(os.path.relpath(root, relroot), file) - zip_f.write(filename, arcname) + if os.path.exists(source_dir): + if os.path.splitext(output_filename)[1] == "": + output_filename += ".zip" + output_dir = os.path.dirname(output_filename) + if output_dir and not os.path.exists(output_dir): + os.makedirs(output_dir) + relroot = source_dir + with zipfile.ZipFile(output_filename, "w", zipfile.ZIP_DEFLATED) as zip_f: + for root, dirs, files in os.walk(source_dir): + # add directory (needed for empty dirs) + zip_f.write(root, os.path.relpath(root, relroot)) + for file in files: + filename = os.path.join(root, file) + if os.path.isfile(filename): # regular files only + arcname = os.path.join(os.path.relpath(root, relroot), file) + zip_f.write(filename, arcname) - return output_filename + return output_filename diff --git a/shellfoundry/utilities/cloudshell_api/client_wrapper.py b/shellfoundry/utilities/cloudshell_api/client_wrapper.py index 063ea31..d5cfeca 100644 --- a/shellfoundry/utilities/cloudshell_api/client_wrapper.py +++ b/shellfoundry/utilities/cloudshell_api/client_wrapper.py @@ -1,5 +1,4 @@ #!/usr/bin/python -# -*- coding: utf-8 -*- from cloudshell.rest.api import PackagingRestApiClient @@ -44,14 +43,24 @@ def create_client(self, **kwargs): def _create_client(self): try: - client = PackagingRestApiClient( - ip=self._cs_config.host, - username=self._cs_config.username, - port=self._cs_config.port, - domain=self._cs_config.domain, - password=self._cs_config.password, - ) - return client + try: + client = PackagingRestApiClient.login( + host=self._cs_config.host, + port=self._cs_config.port, + username=self._cs_config.username, + password=self._cs_config.password, + domain=self._cs_config.domain, + ) + return client + except AttributeError: + client = PackagingRestApiClient( + ip=self._cs_config.host, + port=self._cs_config.port, + username=self._cs_config.username, + password=self._cs_config.password, + domain=self._cs_config.domain, + ) + return client except (HTTPError, Exception) as e: if hasattr(e, "code") and e.code == 401: if hasattr(e, "msg") and e.msg: diff --git a/shellfoundry/utilities/driver_generator.py b/shellfoundry/utilities/driver_generator.py index ff1b7eb..fb6dca9 100644 --- a/shellfoundry/utilities/driver_generator.py +++ b/shellfoundry/utilities/driver_generator.py @@ -1,5 +1,4 @@ #!/usr/bin/python -# -*- coding: utf-8 -*- try: from urllib.error import URLError except ImportError: @@ -65,7 +64,7 @@ def _generate_driver_data_model( :param shell_name: :return: """ - url = "http://{0}:{1}/API/ShellDrivers/Generate".format( + url = "http://{}:{}/API/ShellDrivers/Generate".format( cloudshell_config.host, cloudshell_config.port ) token = client.token @@ -76,7 +75,7 @@ def _generate_driver_data_model( ) if response.status_code != 200: - error_message = "Code generation failed with code {0} and error {1}".format( + error_message = "Code generation failed with code {} and error {}".format( response.status_code, response.text ) click.echo(message=error_message, err=True) @@ -85,25 +84,35 @@ def _generate_driver_data_model( click.echo("Extracting data model ...") with TempDirContext(remove_dir_on_error=False, prefix=shell_name) as temp_dir: generated_zip = path.join(temp_dir, shell_filename) - click.echo("Writing temporary file {0}".format(generated_zip)) + click.echo("Writing temporary file {}".format(generated_zip)) with open(generated_zip, "wb") as driver_file: driver_file.write(response.content) - click.echo("Extracting generated code at {0}".format(destination_path)) + click.echo("Extracting generated code at {}".format(destination_path)) with zipfile.ZipFile(generated_zip) as zf: zf.extractall(destination_path) @staticmethod def _connect_to_cloudshell(cloudshell_config): try: - client = PackagingRestApiClient( - ip=cloudshell_config.host, - username=cloudshell_config.username, - port=cloudshell_config.port, - domain=cloudshell_config.domain, - password=cloudshell_config.password, - ) - return client + try: + client = PackagingRestApiClient.login( + host=cloudshell_config.host, + port=cloudshell_config.port, + username=cloudshell_config.username, + password=cloudshell_config.password, + domain=cloudshell_config.domain, + ) + return client + except AttributeError: + client = PackagingRestApiClient( + ip=cloudshell_config.host, + port=cloudshell_config.port, + username=cloudshell_config.username, + password=cloudshell_config.password, + domain=cloudshell_config.domain, + ) + return client except URLError: click.echo( "Login to CloudShell failed. Please verify the credentials in cloudshell_config.yml", # noqa: E501 diff --git a/shellfoundry/utilities/installer.py b/shellfoundry/utilities/installer.py index 320722a..b34166d 100644 --- a/shellfoundry/utilities/installer.py +++ b/shellfoundry/utilities/installer.py @@ -17,17 +17,28 @@ def install(self, package_name, config): :type config shellfoundry.models.install_config.InstallConfig :return: """ - host = config.host - port = config.port - username = config.username - password = config.password - domain = config.domain - package_full_path = os.path.join(os.getcwd(), "dist", package_name + ".zip") click.echo( - "Installing package {0} into CloudShell at http://{1}:{2}".format( - package_full_path, host, port + "Installing package {} into CloudShell at http://{}:{}".format( + package_full_path, config.host, config.port ) ) - server = PackagingRestApiClient(host, port, username, password, domain) - server.import_package(package_full_path) + + try: + client = PackagingRestApiClient.login( + host=config.host, + port=config.port, + username=config.username, + password=config.password, + domain=config.domain, + ) + except AttributeError: + client = PackagingRestApiClient( + ip=config.host, + port=config.port, + username=config.username, + password=config.password, + domain=config.domain, + ) + + client.import_package(package_full_path) diff --git a/shellfoundry/utilities/shell_package_installer.py b/shellfoundry/utilities/shell_package_installer.py index 456def0..e61734b 100644 --- a/shellfoundry/utilities/shell_package_installer.py +++ b/shellfoundry/utilities/shell_package_installer.py @@ -1,5 +1,4 @@ #!/usr/bin/python -# -*- coding: utf-8 -*- import json import os @@ -13,7 +12,14 @@ from urllib2 import HTTPError from cloudshell.rest.api import PackagingRestApiClient -from cloudshell.rest.exceptions import FeatureUnavailable, ShellNotFoundException + +try: + from cloudshell.rest.exceptions import FeatureUnavailable, ShellNotFound +except ImportError: + from cloudshell.rest.exceptions import ( + FeatureUnavailable, + ShellNotFoundException as ShellNotFound, + ) from shellfoundry.exceptions import FatalError from shellfoundry.utilities.config_reader import CloudShellConfigReader, Configuration @@ -77,7 +83,7 @@ def install(self, path): except FeatureUnavailable: # try to update shell first pass - except ShellNotFoundException: + except ShellNotFound: # try to install shell pass except click.Abort: @@ -98,7 +104,7 @@ def install(self, path): ) as pbar: try: client.update_shell(package_full_path) - except ShellNotFoundException: + except ShellNotFound: self._increase_pbar(pbar, DEFAULT_TIME_WAIT) self._add_new_shell(client, package_full_path) except Exception as e: @@ -145,7 +151,7 @@ def delete(self, shell_name): raise click.ClickException( "Delete shell command unavailable (probably due to CloudShell version below 9.2)" # noqa: E501 ) - except ShellNotFoundException: + except ShellNotFound: self._increase_pbar(pbar, DEFAULT_TIME_WAIT) raise click.ClickException( "Shell '{shell_name}' doesn't exist on CloudShell".format( @@ -166,16 +172,25 @@ def _open_connection_to_quali_server(self, cloudshell_config, pbar, retry): "Connection to CloudShell Server failed. " "Please make sure it is up and running properly." ) - try: - client = PackagingRestApiClient( - ip=cloudshell_config.host, - username=cloudshell_config.username, - port=cloudshell_config.port, - domain=cloudshell_config.domain, - password=cloudshell_config.password, - ) - return client + try: + client = PackagingRestApiClient.login( + host=cloudshell_config.host, + port=cloudshell_config.port, + username=cloudshell_config.username, + password=cloudshell_config.password, + domain=cloudshell_config.domain, + ) + return client + except AttributeError: + client = PackagingRestApiClient( + ip=cloudshell_config.host, + port=cloudshell_config.port, + username=cloudshell_config.username, + password=cloudshell_config.password, + domain=cloudshell_config.domain, + ) + return client except HTTPError as e: if e.code == 401: raise FatalError( diff --git a/tests/__init__.py b/tests/__init__.py index 095f8dc..8433f62 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - import os TEST_DIR = os.path.dirname(__file__) diff --git a/tests/asserts.py b/tests/asserts.py index 578fc48..194920e 100644 --- a/tests/asserts.py +++ b/tests/asserts.py @@ -1,19 +1,14 @@ #!/usr/bin/python -# -*- coding: utf-8 -*- import os def assertFileExists(obj, file_path): obj.assertTrue( os.path.exists(file_path), - msg="File/directory {0} does not exist".format(file_path), - ) - obj.assertTrue( - os.path.isfile(file_path), msg="File {0} does not exist".format(file_path) + msg=f"File/directory {file_path} does not exist", ) + obj.assertTrue(os.path.isfile(file_path), msg=f"File {file_path} does not exist") def assertFileDoesNotExist(obj, file_path): - obj.assertFalse( - os.path.exists(file_path), msg="File/directory {0} exists".format(file_path) - ) + obj.assertFalse(os.path.exists(file_path), msg=f"File/directory {file_path} exists") diff --git a/tests/helpers/__init__.py b/tests/helpers/__init__.py index 40a96af..e69de29 100644 --- a/tests/helpers/__init__.py +++ b/tests/helpers/__init__.py @@ -1 +0,0 @@ -# -*- coding: utf-8 -*- diff --git a/tests/helpers/mocking_extensions.py b/tests/helpers/mocking_extensions.py index bf512d1..19f3aa0 100644 --- a/tests/helpers/mocking_extensions.py +++ b/tests/helpers/mocking_extensions.py @@ -1,12 +1,6 @@ #!/usr/bin/python -# -*- coding: utf-8 -*- import inspect -import sys - -if sys.version_info >= (3, 0): - from unittest.mock import MagicMock -else: - from mock import MagicMock +from unittest.mock import MagicMock def bootstrap(): diff --git a/tests/test_bootstrap.py b/tests/test_bootstrap.py index e6c0966..2201fc5 100644 --- a/tests/test_bootstrap.py +++ b/tests/test_bootstrap.py @@ -1,16 +1,10 @@ #!/usr/bin/python -# -*- coding: utf-8 -*- -import sys import traceback import unittest +from unittest.mock import MagicMock, patch from click.testing import CliRunner -if sys.version_info >= (3, 0): - from unittest.mock import MagicMock, patch -else: - from mock import MagicMock, patch - from shellfoundry.bootstrap import ( config, delete, diff --git a/tests/test_commands/test_config_command.py b/tests/test_commands/test_config_command.py index b68fa93..e7f102c 100644 --- a/tests/test_commands/test_config_command.py +++ b/tests/test_commands/test_config_command.py @@ -1,16 +1,9 @@ #!/usr/bin/python -# -*- coding: utf-8 -*- import os -import sys +from unittest.mock import MagicMock, patch from click import BadArgumentUsage - -if sys.version_info >= (3, 0): - from unittest.mock import MagicMock, patch -else: - from mock import MagicMock, patch - from pyfakefs import fake_filesystem_unittest from shellfoundry.commands.config_command import DEFAULTS_CHAR, ConfigCommandExecutor @@ -184,7 +177,7 @@ def test_remove_key_is_allowed(self, echo_mock, get_app_dir_mock): ).contents self.assertTrue( file_content == desired_result, - "Expected: {}{}Actual: {}".format(desired_result, os.linesep, file_content), + f"Expected: {desired_result}{os.linesep}Actual: {file_content}", ) @patch("shellfoundry.utilities.config.config_providers.click.get_app_dir") @@ -227,7 +220,7 @@ def test_update_existing_key(self, echo_mock, get_app_dir_mock): ).contents self.assertTrue( file_content == desired_result, - "Expected: {}{}Actual: {}".format(desired_result, os.linesep, file_content), + f"Expected: {desired_result}{os.linesep}Actual: {file_content}", ) @patch("shellfoundry.utilities.config.config_providers.click.get_app_dir") @@ -251,7 +244,7 @@ def test_adding_key_to_global_config_that_hasnt_been_created_yet( ).contents self.assertTrue( file_content == desired_result, - "Expected: {}{}Actual: {}".format(desired_result, os.linesep, file_content), + f"Expected: {desired_result}{os.linesep}Actual: {file_content}", ) @patch("shellfoundry.utilities.config.config_providers.click.get_app_dir") @@ -293,5 +286,5 @@ def test_set_password_config_password_should_appear_encrypted( ).contents self.assertTrue( file_content == desired_result, - "Expected: {}{}Actual: {}".format(desired_result, os.linesep, file_content), + f"Expected: {desired_result}{os.linesep}Actual: {file_content}", ) diff --git a/tests/test_commands/test_dist_command.py b/tests/test_commands/test_dist_command.py index 087064d..24bfd31 100644 --- a/tests/test_commands/test_dist_command.py +++ b/tests/test_commands/test_dist_command.py @@ -1,13 +1,7 @@ #!/usr/bin/python -# -*- coding: utf-8 -*- import os -import sys import unittest - -if sys.version_info >= (3, 0): - from unittest.mock import MagicMock, patch -else: - from mock import MagicMock, patch +from unittest.mock import MagicMock, patch from shellfoundry.commands.dist_command import DistCommandExecutor from shellfoundry.models.install_config import InstallConfig diff --git a/tests/test_commands/test_extend_command.py b/tests/test_commands/test_extend_command.py index f9e6547..11222f7 100644 --- a/tests/test_commands/test_extend_command.py +++ b/tests/test_commands/test_extend_command.py @@ -1,14 +1,8 @@ #!/usr/bin/python -# -*- coding: utf-8 -*- import shutil -import sys import unittest - -if sys.version_info >= (3, 0): - from unittest.mock import MagicMock, patch -else: - from mock import MagicMock, patch +from unittest.mock import MagicMock, patch from click import BadParameter, ClickException @@ -19,7 +13,7 @@ class TestExtendCommandExecutor(unittest.TestCase): def setUp(self): - super(TestExtendCommandExecutor, self).setUp() + super().setUp() repository_downloader = MagicMock shell_name_validations = MagicMock with patch("shellfoundry.commands.extend_command.Configuration"): @@ -30,7 +24,7 @@ def setUp(self): ) def tearDown(self): - super(TestExtendCommandExecutor, self).tearDown() + super().tearDown() del self.tested_instance @patch( diff --git a/tests/test_commands/test_generate_command.py b/tests/test_commands/test_generate_command.py index f07b1e9..e7180e0 100644 --- a/tests/test_commands/test_generate_command.py +++ b/tests/test_commands/test_generate_command.py @@ -1,13 +1,8 @@ #!/usr/bin/python -# -*- coding: utf-8 -*- import os -import sys +from unittest.mock import MagicMock -if sys.version_info >= (3, 0): - from unittest.mock import MagicMock -else: - from mock import MagicMock from pyfakefs import fake_filesystem_unittest from shellfoundry.commands.generate_command import GenerateCommandExecutor diff --git a/tests/test_commands/test_install_command.py b/tests/test_commands/test_install_command.py index a55fb9e..a14cddf 100644 --- a/tests/test_commands/test_install_command.py +++ b/tests/test_commands/test_install_command.py @@ -1,15 +1,8 @@ #!/usr/bin/python -# -*- coding: utf-8 -*- -import sys import unittest - -if sys.version_info >= (3, 0): - from unittest.mock import MagicMock, patch - from urllib.error import HTTPError, URLError -else: - from mock import MagicMock, patch - from urllib2 import HTTPError, URLError +from unittest.mock import MagicMock, patch +from urllib.error import HTTPError, URLError from shellfoundry.commands.install_command import InstallCommandExecutor from shellfoundry.exceptions import FatalError diff --git a/tests/test_commands/test_list_command.py b/tests/test_commands/test_list_command.py index 22eef8d..64cc437 100644 --- a/tests/test_commands/test_list_command.py +++ b/tests/test_commands/test_list_command.py @@ -1,17 +1,10 @@ #!/usr/bin/python -# -*- coding: utf-8 -*- -import sys import unittest +from unittest.mock import MagicMock, patch import httpretty from click import ClickException, UsageError from cloudshell.rest.api import FeatureUnavailable - -if sys.version_info >= (3, 0): - from unittest.mock import MagicMock, patch -else: - from mock import MagicMock, patch - from pyfakefs import fake_filesystem_unittest from requests.exceptions import SSLError diff --git a/tests/test_commands/test_new_command.py b/tests/test_commands/test_new_command.py index b4b2d93..0da9b88 100644 --- a/tests/test_commands/test_new_command.py +++ b/tests/test_commands/test_new_command.py @@ -1,17 +1,10 @@ #!/usr/bin/python -# -*- coding: utf-8 -*- -import sys import unittest +from unittest.mock import MagicMock, patch from click import BadParameter, ClickException from cloudshell.rest.api import FeatureUnavailable -if sys.version_info >= (3, 0): - from unittest.mock import MagicMock, patch -else: - from mock import MagicMock, patch - - from shellfoundry import ALTERNATIVE_STANDARDS_PATH from shellfoundry.commands.new_command import NewCommandExecutor from shellfoundry.models.install_config import InstallConfig @@ -71,7 +64,7 @@ def test_new_standard_fetch_base_exception(self, mock_echo, mock_os): ) with self.assertRaisesRegex( - ClickException, "Cannot retrieve standards list. Error: {}".format(exc_msg) + ClickException, f"Cannot retrieve standards list. Error: {exc_msg}" ): command_executor.new( name="Shell_Name", @@ -149,7 +142,7 @@ def test_new_direct_online_template( "python_version", ) mock_echo.assert_called_with( - "Created shell {0} based on template {1}".format( + "Created shell {} based on template {}".format( "Shell_Name", "shell/template" ) ) @@ -197,7 +190,7 @@ def test_new_direct_local_template( "python_version", ) mock_echo.assert_called_with( - "Created shell {0} based on template {1}".format( + "Created shell {} based on template {}".format( "Shell_Name", "shell/template" ) ) @@ -254,7 +247,7 @@ def test_new_github_templates( "python_version", ) mock_echo.assert_called_with( - "Created shell {0} based on template {1}".format( + "Created shell {} based on template {}".format( "Shell_Name", "shell/template" ) ) @@ -316,7 +309,7 @@ def test_new_local_templates( "python_version", ) mock_echo.assert_called_with( - "Created shell {0} based on template {1}".format( + "Created shell {} based on template {}".format( "Shell_Name", "local_template_name" ) ) @@ -383,7 +376,7 @@ def test_new_l1_template( "WARNING: L1 shells support python 2.7 only!", fg="yellow" ) mock_echo.assert_called_with( - "Created shell {0} based on template {1}".format( + "Created shell {} based on template {}".format( "Shell_Name", command_executor.L1_TEMPLATE ) ) diff --git a/tests/test_commands/test_pack_command.py b/tests/test_commands/test_pack_command.py index abf5a8e..a524528 100644 --- a/tests/test_commands/test_pack_command.py +++ b/tests/test_commands/test_pack_command.py @@ -1,12 +1,7 @@ #!/usr/bin/python -# -*- coding: utf-8 -*- import os -import sys +from unittest.mock import patch -if sys.version_info >= (3, 0): - from unittest.mock import patch -else: - from mock import patch from pyfakefs import fake_filesystem_unittest from shellfoundry.commands.pack_command import PackCommandExecutor diff --git a/tests/test_commands/test_show_command.py b/tests/test_commands/test_show_command.py index 93341d3..9b6c72a 100644 --- a/tests/test_commands/test_show_command.py +++ b/tests/test_commands/test_show_command.py @@ -1,15 +1,9 @@ #!/usr/bin/python -# -*- coding: utf-8 -*- -import sys import unittest +from unittest.mock import MagicMock, PropertyMock, call, patch import click -if sys.version_info >= (3, 0): - from unittest.mock import MagicMock, PropertyMock, call, patch -else: - from mock import MagicMock, PropertyMock, call, patch - from shellfoundry.commands.show_command import ShowCommandExecutor from shellfoundry.models.shell_template import ShellTemplate from shellfoundry.utilities.template_retriever import TemplateRetriever diff --git a/tests/test_decorators/test_version_check.py b/tests/test_decorators/test_version_check.py index 5a21a69..4cf049b 100644 --- a/tests/test_decorators/test_version_check.py +++ b/tests/test_decorators/test_version_check.py @@ -1,19 +1,11 @@ #!/usr/bin/python -# -*- coding: utf-8 -*- -from __future__ import print_function -import sys import unittest +from io import StringIO +from unittest.mock import patch from click import Abort -if sys.version_info >= (3, 0): - from io import StringIO - from unittest.mock import patch -else: - from mock import patch - from StringIO import StringIO - from shellfoundry.decorators import shellfoundry_version_check diff --git a/tests/test_models/test_install_config.py b/tests/test_models/test_install_config.py index 6d2805b..bf2b5be 100644 --- a/tests/test_models/test_install_config.py +++ b/tests/test_models/test_install_config.py @@ -1,13 +1,7 @@ #!/usr/bin/python -# -*- coding: utf-8 -*- -import sys import unittest - -if sys.version_info >= (3, 0): - from unittest.mock import MagicMock, patch -else: - from mock import MagicMock, patch +from unittest.mock import MagicMock, patch from shellfoundry.models.install_config import InstallConfig diff --git a/tests/test_utilities/config/test_config_record.py b/tests/test_utilities/config/test_config_record.py index 7c432a7..c444ec0 100644 --- a/tests/test_utilities/config/test_config_record.py +++ b/tests/test_utilities/config/test_config_record.py @@ -1,12 +1,7 @@ #!/usr/bin/python -# -*- coding: utf-8 -*- -import sys +from unittest.mock import patch -if sys.version_info >= (3, 0): - from unittest.mock import patch -else: - from mock import patch from pyfakefs import fake_filesystem_unittest from shellfoundry.utilities.config.config_context import ConfigContext diff --git a/tests/test_utilities/modifiers/configuration/test_password_modification.py b/tests/test_utilities/modifiers/configuration/test_password_modification.py index 58d4f46..dcdac49 100644 --- a/tests/test_utilities/modifiers/configuration/test_password_modification.py +++ b/tests/test_utilities/modifiers/configuration/test_password_modification.py @@ -1,13 +1,7 @@ #!/usr/bin/python -# -*- coding: utf-8 -*- -import sys import unittest - -if sys.version_info >= (3, 0): - from unittest.mock import MagicMock, patch -else: - from mock import MagicMock, patch +from unittest.mock import MagicMock, patch from shellfoundry.exceptions import PlatformNameIsEmptyException from shellfoundry.utilities.modifiers.configuration.password_modification import ( diff --git a/tests/test_utilities/standards/test_standards_retriever.py b/tests/test_utilities/standards/test_standards_retriever.py index 36d2eb4..bdc9420 100644 --- a/tests/test_utilities/standards/test_standards_retriever.py +++ b/tests/test_utilities/standards/test_standards_retriever.py @@ -1,11 +1,5 @@ #!/usr/bin/python -# -*- coding: utf-8 -*- -import sys - -if sys.version_info >= (3, 0): - from unittest.mock import MagicMock, patch -else: - from mock import MagicMock, patch +from unittest.mock import MagicMock, patch from cloudshell.rest.api import FeatureUnavailable from pyfakefs import fake_filesystem_unittest diff --git a/tests/test_utilities/standards/test_standards_versions.py b/tests/test_utilities/standards/test_standards_versions.py index 3ed8c14..e297c1b 100644 --- a/tests/test_utilities/standards/test_standards_versions.py +++ b/tests/test_utilities/standards/test_standards_versions.py @@ -1,13 +1,7 @@ #!/usr/bin/python -# -*- coding: utf-8 -*- -import sys import unittest - -if sys.version_info >= (3, 0): - from unittest.mock import MagicMock, patch -else: - from mock import MagicMock, patch +from unittest.mock import MagicMock, patch from shellfoundry.utilities.standards import StandardVersions @@ -44,7 +38,7 @@ def test_get_latest_version_failed_to_find_requested_standard(self): # Assert self.assertTrue( str(context.exception) == "Failed to find latest version", - "Actual: {}".format(context.exception), + f"Actual: {context.exception}", ) def test_get_latest_version_find_requested_standard_within_lots_of_standards(self): @@ -79,5 +73,5 @@ def test_standards_list_empty_raises_an_exception(self): == "Standards list is empty. Please verify that {} exists".format( "/shellfoundry/folder/data/standards.json" ), - "Actual: {}".format(context.exception), + f"Actual: {context.exception}", ) diff --git a/tests/test_utilities/test_cloudshell_api/test_client_wrapper.py b/tests/test_utilities/test_cloudshell_api/test_client_wrapper.py index 0fbf720..00a363e 100644 --- a/tests/test_utilities/test_cloudshell_api/test_client_wrapper.py +++ b/tests/test_utilities/test_cloudshell_api/test_client_wrapper.py @@ -1,15 +1,8 @@ #!/usr/bin/python -# -*- coding: utf-8 -*- -import sys import unittest - -if sys.version_info >= (3, 0): - from unittest.mock import MagicMock, patch - from urllib.error import HTTPError -else: - from mock import MagicMock, patch - from urllib2 import HTTPError +from unittest.mock import MagicMock, patch +from urllib.error import HTTPError from shellfoundry.exceptions import FatalError from shellfoundry.utilities.cloudshell_api import ( @@ -33,7 +26,7 @@ def test_client_wrapper_raises_an_error_when_create_client_fails(self): self.assertEqual(context.exception.message, "failure") @patch( - "shellfoundry.utilities.cloudshell_api.client_wrapper.PackagingRestApiClient" + "shellfoundry.utilities.cloudshell_api.client_wrapper.PackagingRestApiClient.login" # noqa: E501 ) def test_client_wrapper_raises_an_error_when_create_client_fails_after_retries_regular_exception( # noqa: E501 self, api_mock @@ -51,7 +44,7 @@ def test_client_wrapper_raises_an_error_when_create_client_fails_after_retries_r ) @patch( - "shellfoundry.utilities.cloudshell_api.client_wrapper.PackagingRestApiClient", + "shellfoundry.utilities.cloudshell_api.client_wrapper.PackagingRestApiClient.login", # noqa: E501 new_callable=MagicMock(), ) def test_client_wrapper_raises_an_error_when_create_client_fails_after_retries_http_error( # noqa: E501 @@ -69,7 +62,7 @@ def test_client_wrapper_raises_an_error_when_create_client_fails_after_retries_h # Assert self.assertEqual( context.exception.message, - "Login to CloudShell failed. {}".format(error_msg), + f"Login to CloudShell failed. {error_msg}", ) @patch( @@ -102,10 +95,10 @@ def test_client_wrapper_creates_client_successfully(self, api_mock): cs_client = create_cloudshell_client() # Assert - self.assertEqual(cs_client, api_mock) + self.assertEqual(cs_client, api_mock.login()) @patch( - "shellfoundry.utilities.cloudshell_api.client_wrapper.PackagingRestApiClient" + "shellfoundry.utilities.cloudshell_api.client_wrapper.PackagingRestApiClient" # noqa: E501 ) def test_client_wrapper_creates_client_successfully_after_initial_exception( self, api_mock @@ -117,4 +110,4 @@ def test_client_wrapper_creates_client_successfully_after_initial_exception( cs_client = create_cloudshell_client(retries=2) # Assert - self.assertEqual(cs_client, api_mock) + self.assertEqual(cs_client, api_mock.login()) diff --git a/tests/test_utilities/test_config_reader.py b/tests/test_utilities/test_config_reader.py index 5861014..8226a8c 100644 --- a/tests/test_utilities/test_config_reader.py +++ b/tests/test_utilities/test_config_reader.py @@ -1,13 +1,8 @@ #!/usr/bin/python -# -*- coding: utf-8 -*- import os -import sys +from unittest.mock import patch -if sys.version_info >= (3, 0): - from unittest.mock import patch -else: - from mock import patch from pyfakefs import fake_filesystem_unittest from shellfoundry.utilities.config_reader import ( diff --git a/tests/test_utilities/test_cookiecutter_integration.py b/tests/test_utilities/test_cookiecutter_integration.py index 851e403..3596e48 100644 --- a/tests/test_utilities/test_cookiecutter_integration.py +++ b/tests/test_utilities/test_cookiecutter_integration.py @@ -1,17 +1,11 @@ #!/usr/bin/python -# -*- coding: utf-8 -*- import os -import sys import unittest +from unittest.mock import MagicMock, patch from cookiecutter.main import cookiecutter -if sys.version_info >= (3, 0): - from unittest.mock import MagicMock, patch -else: - from mock import MagicMock, patch - from shellfoundry.utilities.cookiecutter_integration import CookiecutterTemplateCompiler diff --git a/tests/test_utilities/test_datamodel_merger.py b/tests/test_utilities/test_datamodel_merger.py index bd37915..1e8831d 100644 --- a/tests/test_utilities/test_datamodel_merger.py +++ b/tests/test_utilities/test_datamodel_merger.py @@ -1,5 +1,4 @@ #!/usr/bin/python -# -*- coding: utf-8 -*- import codecs import os diff --git a/tests/test_utilities/test_dependencies_packager.py b/tests/test_utilities/test_dependencies_packager.py index db2fbc6..285998c 100644 --- a/tests/test_utilities/test_dependencies_packager.py +++ b/tests/test_utilities/test_dependencies_packager.py @@ -1,13 +1,8 @@ #!/usr/bin/python -# -*- coding: utf-8 -*- import os -import sys +from unittest.mock import patch -if sys.version_info >= (3, 0): - from unittest.mock import patch -else: - from mock import patch from pyfakefs import fake_filesystem_unittest from shellfoundry.utilities.python_dependencies_packager import ( diff --git a/tests/test_utilities/test_driver_generator.py b/tests/test_utilities/test_driver_generator.py index 6e09f35..f22a5bb 100644 --- a/tests/test_utilities/test_driver_generator.py +++ b/tests/test_utilities/test_driver_generator.py @@ -1,14 +1,8 @@ #!/usr/bin/python -# -*- coding: utf-8 -*- -import sys +from unittest.mock import MagicMock, patch +from urllib.error import URLError -if sys.version_info >= (3, 0): - from unittest.mock import MagicMock, patch - from urllib.error import URLError -else: - from mock import MagicMock, patch - from urllib2 import URLError from pyfakefs import fake_filesystem_unittest from shellfoundry.models.install_config import InstallConfig @@ -159,7 +153,7 @@ def test_error_displayed_when_failed_to_connect_to_cloudshell_server(self): ) with patch( - "shellfoundry.utilities.driver_generator.PackagingRestApiClient" + "shellfoundry.utilities.driver_generator.PackagingRestApiClient.login" ) as mock_rest: mock_rest.side_effect = URLError("connected failed") diff --git a/tests/test_utilities/test_filters.py b/tests/test_utilities/test_filters.py index 5286fe2..d730ac0 100644 --- a/tests/test_utilities/test_filters.py +++ b/tests/test_utilities/test_filters.py @@ -1,5 +1,4 @@ #!/usr/bin/python -# -*- coding: utf-8 -*- import unittest from shellfoundry.utilities.filters import ( diff --git a/tests/test_utilities/test_shell_installer.py b/tests/test_utilities/test_installer.py similarity index 76% rename from tests/test_utilities/test_shell_installer.py rename to tests/test_utilities/test_installer.py index 13f845c..0af70c2 100644 --- a/tests/test_utilities/test_shell_installer.py +++ b/tests/test_utilities/test_installer.py @@ -1,13 +1,8 @@ #!/usr/bin/python -# -*- coding: utf-8 -*- import os -import sys +from unittest.mock import patch -if sys.version_info >= (3, 0): - from unittest.mock import patch -else: - from mock import patch from pyfakefs import fake_filesystem_unittest from shellfoundry.models.install_config import InstallConfig @@ -18,14 +13,13 @@ class TestShellInstaller(fake_filesystem_unittest.TestCase): def setUp(self): self.setUpPyfakefs() - @patch("cloudshell.rest.api.PackagingRestApiClient.import_package") - @patch("cloudshell.rest.api.PackagingRestApiClient.__init__") + @patch("cloudshell.rest.api.PackagingRestApiClient.login.import_package") + @patch("cloudshell.rest.api.PackagingRestApiClient.login") def test_when_install_called_it_uploads_package_to_cloudshell( self, mock_quali_api_client, mock_import_package ): # Arrange - # Constructor should return None - mock_quali_api_client.return_value = None + mock_quali_api_client.return_value = mock_quali_api_client self.fs.create_file("work/dest/nut_shell.zip") diff --git a/tests/test_utilities/test_package_builder.py b/tests/test_utilities/test_package_builder.py index 742dad6..69717cf 100644 --- a/tests/test_utilities/test_package_builder.py +++ b/tests/test_utilities/test_package_builder.py @@ -1,14 +1,8 @@ #!/usr/bin/python -# -*- coding: utf-8 -*- import os -import sys import xml.etree.ElementTree as etree import zipfile - -if sys.version_info >= (3, 0): - from unittest.mock import MagicMock, patch -else: - from mock import MagicMock, patch +from unittest.mock import MagicMock, patch from pyfakefs import fake_filesystem_unittest @@ -480,7 +474,7 @@ def _assert_utf_file_content(self, path, content): @staticmethod def _get_driver_version_from_file(path): - with open(path, "r") as f: + with open(path) as f: text = f.read() metadata_xml = TestPackageBuilder._parse_xml(text) diff --git a/tests/test_utilities/test_repo_downloader.py b/tests/test_utilities/test_repo_downloader.py index 2f57bd6..f266c59 100644 --- a/tests/test_utilities/test_repo_downloader.py +++ b/tests/test_utilities/test_repo_downloader.py @@ -1,5 +1,4 @@ #!/usr/bin/python -# -*- coding: utf-8 -*- import os import httpretty @@ -101,12 +100,12 @@ def test_returns_the_root_folder_of_the_git_repo(self): class FakeExtractor(DownloadedRepoExtractor): def __init__(self, fs): - super(TestRepositoryDownloader.FakeExtractor, self).__init__() + super().__init__() self.fs = fs def extract_to_folder(self, repo_link, folder): files = [] - with open(repo_link, "r") as f: + with open(repo_link) as f: content = f.read().replace("\n", "") for file in content.split(","): diff --git a/tests/test_utilities/test_shell_config_reader.py b/tests/test_utilities/test_shell_config_reader.py index 0e2a17f..066d723 100644 --- a/tests/test_utilities/test_shell_config_reader.py +++ b/tests/test_utilities/test_shell_config_reader.py @@ -1,5 +1,4 @@ #!/usr/bin/python -# -*- coding: utf-8 -*- import os from pyfakefs import fake_filesystem_unittest diff --git a/tests/test_utilities/test_shell_package.py b/tests/test_utilities/test_shell_package.py index 7f4bcd2..c5c34a2 100644 --- a/tests/test_utilities/test_shell_package.py +++ b/tests/test_utilities/test_shell_package.py @@ -1,5 +1,4 @@ #!/usr/bin/python -# -*- coding: utf-8 -*- import unittest diff --git a/tests/test_utilities/test_shell_package_builder.py b/tests/test_utilities/test_shell_package_builder.py index ccbaa16..8efc45d 100644 --- a/tests/test_utilities/test_shell_package_builder.py +++ b/tests/test_utilities/test_shell_package_builder.py @@ -1,13 +1,8 @@ #!/usr/bin/python -# -*- coding: utf-8 -*- import os -import sys +from unittest.mock import patch -if sys.version_info >= (3, 0): - from unittest.mock import patch -else: - from mock import patch from pyfakefs import fake_filesystem_unittest from shellfoundry.utilities.shell_package_builder import ShellPackageBuilder diff --git a/tests/test_utilities/test_shell_package_installer.py b/tests/test_utilities/test_shell_package_installer.py index cbea471..c08dad5 100644 --- a/tests/test_utilities/test_shell_package_installer.py +++ b/tests/test_utilities/test_shell_package_installer.py @@ -1,17 +1,15 @@ #!/usr/bin/python -# -*- coding: utf-8 -*- - -import sys import click -from cloudshell.rest.exceptions import FeatureUnavailable, ShellNotFoundException -if sys.version_info >= (3, 0): - from unittest.mock import MagicMock, patch - from urllib.error import HTTPError -else: - from mock import MagicMock, patch - from urllib2 import HTTPError +try: + from cloudshell.rest.exceptions import FeatureUnavailable, ShellNotFound +except ImportError: + from cloudshell.rest.exceptions import FeatureUnavailable + from cloudshell.rest.exceptions import ShellNotFoundException as ShellNotFound + +from unittest.mock import MagicMock, patch +from urllib.error import HTTPError from pyfakefs import fake_filesystem_unittest @@ -39,7 +37,9 @@ class TestShellPackageInstaller(fake_filesystem_unittest.TestCase): def setUp(self): self.setUpPyfakefs() - @patch("shellfoundry.utilities.shell_package_installer.PackagingRestApiClient") + @patch( + "shellfoundry.utilities.shell_package_installer.PackagingRestApiClient.login" + ) @patch( "shellfoundry.utilities.shell_package_installer.ShellPackage.get_name_from_definition", # noqa: E501 new=MagicMock(return_value="NutShell"), @@ -58,7 +58,9 @@ def test_install_shell_updates_an_existing_shell(self, rest_client_mock): # Assert self.assertTrue(mock_client.update_shell.called) - @patch("shellfoundry.utilities.shell_package_installer.PackagingRestApiClient") + @patch( + "shellfoundry.utilities.shell_package_installer.PackagingRestApiClient.login" + ) @patch( "shellfoundry.utilities.shell_package_installer.ShellPackage.get_name_from_definition", # noqa: E501 new=MagicMock(return_value="NutShell"), @@ -68,7 +70,7 @@ def test_install_shell_adds_a_new_shell_when_shell_does_not_exist( ): # Arrange mock_client = MagicMock() - mock_client.update_shell = MagicMock(side_effect=ShellNotFoundException()) + mock_client.update_shell = MagicMock(side_effect=ShellNotFound()) mock_client.get_shell.return_value = {SHELL_IS_OFFICIAL_FLAG: False} rest_client_mock.return_value = mock_client installer = ShellPackageInstaller() @@ -81,7 +83,9 @@ def test_install_shell_adds_a_new_shell_when_shell_does_not_exist( self.assertTrue(mock_client.update_shell.called) self.assertTrue(mock_client.add_shell.called) - @patch("shellfoundry.utilities.shell_package_installer.PackagingRestApiClient") + @patch( + "shellfoundry.utilities.shell_package_installer.PackagingRestApiClient.login" + ) @patch( "shellfoundry.utilities.shell_package_installer.ShellPackage.get_name_from_definition", # noqa: E501 new=MagicMock(return_value="NutShell"), @@ -107,7 +111,7 @@ def test_shell_add_should_not_be_called_when_update_fails(self, rest_client_mock self.assertFalse(mock_client.add_shell.called) @patch( - "shellfoundry.utilities.shell_package_installer.PackagingRestApiClient", + "shellfoundry.utilities.shell_package_installer.PackagingRestApiClient.login", new=MagicMock(side_effect=Exception()), ) @patch( @@ -124,13 +128,13 @@ def test_fail_to_open_connection_to_cs(self): installer.install("work/nut-shell") # Assert - self.assertTrue( - context.exception.message - == "Connection to CloudShell Server failed. Please make sure it is up and running properly." # noqa: E501 + self.assertEqual( + context.exception.message, + "Connection to CloudShell Server failed. Please make sure it is up and running properly.", # noqa: E501 ) @patch( - "shellfoundry.utilities.shell_package_installer.PackagingRestApiClient", + "shellfoundry.utilities.shell_package_installer.PackagingRestApiClient.login", new=MagicMock(side_effect=HTTPError("", 401, "", None, None)), ) @patch( @@ -147,13 +151,13 @@ def test_fail_to_login_into_cs(self): installer.install("work/nut-shell") # Assert - self.assertTrue( - context.exception.message - == "Login to CloudShell failed. Please verify the credentials in the config" # noqa: E501 + self.assertEqual( + context.exception.message, + "Login to CloudShell failed. Please verify the credentials in the config", ) @patch( - "shellfoundry.utilities.shell_package_installer.PackagingRestApiClient", + "shellfoundry.utilities.shell_package_installer.PackagingRestApiClient.login", new=MagicMock(side_effect=HTTPError("", 403, "", None, None)), ) @patch( @@ -170,16 +174,16 @@ def test_fail_with_http_error_other_than_authentication_error(self): installer.install("work/nut-shell") # Assert - self.assertTrue( - context.exception.message - == "Connection to CloudShell Server failed. Please make sure it is up and running properly." # noqa: E501 + self.assertEqual( + context.exception.message, + "Connection to CloudShell Server failed. Please make sure it is up and running properly.", # noqa: E501 ) @patch( - "shellfoundry.utilities.shell_package_installer.PackagingRestApiClient", + "shellfoundry.utilities.shell_package_installer.PackagingRestApiClient.login", new=MagicMock( return_value=mock_rest_client( - update_side_effect=ShellNotFoundException(), + update_side_effect=ShellNotFound(), add_side_effect=Exception( add_shell_error_message("Failed to add shell") ), @@ -223,12 +227,14 @@ def test_fail_to_update_and_than_add_shell(self): installer.install("work/nut-shell") # Assert - self.assertTrue( - context.exception.message - == "Failed to add new shell. CloudShell responded with: 'Failed to add shell'" # noqa: E501 + self.assertEqual( + context.exception.message, + "Failed to add new shell. CloudShell responded with: 'Failed to add shell'", # noqa: E501 ) - @patch("shellfoundry.utilities.shell_package_installer.PackagingRestApiClient") + @patch( + "shellfoundry.utilities.shell_package_installer.PackagingRestApiClient.login" + ) @patch( "shellfoundry.utilities.shell_package_installer.click.confirm", new=MagicMock() ) @@ -270,7 +276,9 @@ def test_install_shell_updates_official_shell_abort(self, rest_client_mock): with self.assertRaises(click.Abort): installer.install("work/nut-shell") - @patch("shellfoundry.utilities.shell_package_installer.PackagingRestApiClient") + @patch( + "shellfoundry.utilities.shell_package_installer.PackagingRestApiClient.login" + ) @patch( "shellfoundry.utilities.shell_package_installer.click.confirm", new=MagicMock(side_effect=(FeatureUnavailable)), @@ -295,10 +303,12 @@ def test_install_shell_updates_official_shell_feature_unavailable( # Assert self.assertTrue(mock_client.update_shell.called) - @patch("shellfoundry.utilities.shell_package_installer.PackagingRestApiClient") + @patch( + "shellfoundry.utilities.shell_package_installer.PackagingRestApiClient.login" + ) @patch( "shellfoundry.utilities.shell_package_installer.click.confirm", - new=MagicMock(side_effect=(ShellNotFoundException)), + new=MagicMock(side_effect=(ShellNotFound)), ) @patch( "shellfoundry.utilities.shell_package_installer.ShellPackage.get_name_from_definition", # noqa: E501 diff --git a/tests/test_utilities/test_template_retriever.py b/tests/test_utilities/test_template_retriever.py index c60be65..2c27692 100644 --- a/tests/test_utilities/test_template_retriever.py +++ b/tests/test_utilities/test_template_retriever.py @@ -1,15 +1,8 @@ #!/usr/bin/python -# -*- coding: utf-8 -*- -import sys import unittest +from unittest.mock import patch import httpretty - -if sys.version_info >= (3, 0): - from unittest.mock import patch -else: - from mock import patch - from pyfakefs import fake_filesystem_unittest from shellfoundry.utilities import GEN_ONE, GEN_TWO, NO_FILTER diff --git a/tests/test_utilities/test_template_url.py b/tests/test_utilities/test_template_url.py index ca526f1..44fd3ad 100644 --- a/tests/test_utilities/test_template_url.py +++ b/tests/test_utilities/test_template_url.py @@ -1,5 +1,4 @@ #!/usr/bin/python -# -*- coding: utf-8 -*- import unittest from shellfoundry.utilities.template_url import construct_template_url diff --git a/tests/test_utilities/test_template_versions.py b/tests/test_utilities/test_template_versions.py index 8d8d2da..8682e5e 100644 --- a/tests/test_utilities/test_template_versions.py +++ b/tests/test_utilities/test_template_versions.py @@ -1,15 +1,9 @@ #!/usr/bin/python -# -*- coding: utf-8 -*- -import sys import unittest +from unittest.mock import MagicMock, patch import requests -if sys.version_info >= (3, 0): - from unittest.mock import MagicMock, patch -else: - from mock import patch, MagicMock - from shellfoundry.exceptions import NoVersionsHaveBeenFoundException from shellfoundry.utilities.template_versions import TemplateVersions diff --git a/tests/test_utilities/test_validations/test_shell_name_validations.py b/tests/test_utilities/test_validations/test_shell_name_validations.py index e65ce40..454cefa 100644 --- a/tests/test_utilities/test_validations/test_shell_name_validations.py +++ b/tests/test_utilities/test_validations/test_shell_name_validations.py @@ -1,5 +1,4 @@ #!/usr/bin/python -# -*- coding: utf-8 -*- import unittest from shellfoundry.utilities.validations import ShellNameValidations diff --git a/tests/test_utilities/test_version_utilities.py b/tests/test_utilities/test_version_utilities.py index 01a0c1b..ecf2077 100644 --- a/tests/test_utilities/test_version_utilities.py +++ b/tests/test_utilities/test_version_utilities.py @@ -1,5 +1,4 @@ #!/usr/bin/python -# -*- coding: utf-8 -*- import unittest from freezegun import freeze_time diff --git a/tests/test_utilities/test_versions.py b/tests/test_utilities/test_versions.py index e58eeab..c9dac8a 100644 --- a/tests/test_utilities/test_versions.py +++ b/tests/test_utilities/test_versions.py @@ -1,12 +1,6 @@ #!/usr/bin/python -# -*- coding: utf-8 -*- -import sys import unittest - -if sys.version_info >= (3, 0): - from unittest.mock import MagicMock, patch -else: - from mock import MagicMock, patch +from unittest.mock import MagicMock, patch from shellfoundry.utilities import is_index_version_greater_than_current diff --git a/tox.ini b/tox.ini index bb9727d..a468b5b 100644 --- a/tox.ini +++ b/tox.ini @@ -16,7 +16,7 @@ deps = master: -r test_requirements.txt dev: -r dev_requirements.txt commands = - pytest --cov=shellfoundry tests + pytest --cov=shellfoundry tests --cov-report=xml [testenv:pre-commit] basepython = python3 @@ -26,9 +26,8 @@ commands = pre-commit run --all-files --show-diff-on-failure [testenv:build] skip_install = true -commands = - python setup.py -q sdist --format zip - python setup.py -q bdist_wheel --universal +deps = build +commands = python -m build [isort] profile=black @@ -38,4 +37,4 @@ forced_separate = shellfoundry,tests max-line-length = 88 ;we don't need have docstrings in every func, class and package ;and W503 is not PEP 8 compliant -ignore = D100,D101,D102,D103,D104,D105,D106,D107,D401,W503,E203,T001,T201 +ignore = A004,D100,D101,D102,D103,D104,D105,D106,D107,D401,W503,E203,T001,T201