From 468931802281e2b2a1ccba9e7cc9840b178c451e Mon Sep 17 00:00:00 2001 From: nkyuray Date: Tue, 11 Jan 2022 18:42:44 +0100 Subject: [PATCH 1/5] adapter compability messaging added. --- core/dbt/version.py | 26 ++++++--- test/unit/test_version.py | 110 +++++++++++++++++++++++++------------- 2 files changed, 92 insertions(+), 44 deletions(-) diff --git a/core/dbt/version.py b/core/dbt/version.py index d83d63a1f90..8d871649b03 100644 --- a/core/dbt/version.py +++ b/core/dbt/version.py @@ -10,6 +10,8 @@ import dbt.exceptions import dbt.semver +from dbt.ui import green, red +from dbt import flags PYPI_VERSION_URL = 'https://pypi.org/pypi/dbt-core/json' @@ -30,6 +32,8 @@ def get_installed_version(): def get_version_information(): + flags.USE_COLORS = True if not flags.USE_COLORS else None + installed = get_installed_version() latest = get_latest_version() @@ -44,16 +48,26 @@ def get_version_information(): plugin_version_msg = "Plugins:\n" for plugin_name, version in _get_dbt_plugins_info(): - plugin_version_msg += ' - {plugin_name}: {version}\n'.format( - plugin_name=plugin_name, version=version - ) + version_major = dbt.semver.VersionSpecifier.from_version_string(version).major + plugin_update_msg = '' + if installed.major == version_major: + compatibility_msg = green('compatible') + else: + compatibility_msg = red('requires update!') + plugin_update_msg = (" To update dbt-{} please run:\n" + " pip install dbt-{} --upgrade\n\n".format(plugin_name, plugin_name)) + + plugin_version_msg += (" - {}: {} - {}\n" + "{}").format(plugin_name, version, compatibility_msg, plugin_update_msg) + if latest is None: return ("{}The latest version of dbt could not be determined!\n" "Make sure that the following URL is accessible:\n{}\n\n{}" - .format(version_msg, PYPI_VERSION_URL, plugin_version_msg)) + .format(version_msg, PYPI_VERSION_URL, plugin_version_msg) + ) if installed == latest: - return "{}Up to date!\n\n{}".format(version_msg, plugin_version_msg) + return f"{version_msg}{green('Up to date!')}\n\n{plugin_version_msg}" elif installed > latest: return ("{}Your version of dbt is ahead of the latest " @@ -91,7 +105,7 @@ def _get_dbt_plugins_info(): f'dbt.adapters.{plugin_name}.__version__' ) except ImportError: - # not an adpater + # not an adapter continue yield plugin_name, mod.version diff --git a/test/unit/test_version.py b/test/unit/test_version.py index e1431b292ae..98f5b8f28ba 100644 --- a/test/unit/test_version.py +++ b/test/unit/test_version.py @@ -3,6 +3,7 @@ import dbt.main import dbt.version +from dbt.ui import green, red class VersionTest(unittest.TestCase): @@ -15,10 +16,10 @@ def test_versions_equal(self, mock_get, mock_get_dbt_plugins_info): 'info': {'version': '0.10.0'} } mock_get_dbt_plugins_info.return_value = [ - ('dbt-postgres', '0.10.0'), - ('dbt-redshift', '0.10.0'), - ('dbt-bigquery', '0.10.0'), - ('dbt-snowflake', '0.10.0') + ('postgres', '0.10.0'), + ('redshift', '0.10.0'), + ('bigquery', '0.10.0'), + ('snowflake', '0.10.0') ] latest_version = dbt.version.get_latest_version() @@ -26,14 +27,13 @@ def test_versions_equal(self, mock_get, mock_get_dbt_plugins_info): version_information = dbt.version.get_version_information() expected_version_information = "installed version: 0.10.0\n" \ - " latest version: 0.10.0\n\n" \ - "Up to date!\n\n" \ - "Plugins:\n" \ - " - dbt-postgres: 0.10.0\n" \ - " - dbt-redshift: 0.10.0\n" \ - " - dbt-bigquery: 0.10.0\n" \ - " - dbt-snowflake: 0.10.0\n" - + " latest version: 0.10.0\n\n" \ + f"{green('Up to date!')}\n\n" \ + "Plugins:\n" \ + f" - postgres: 0.10.0 - {green('compatible')}\n" \ + f" - redshift: 0.10.0 - {green('compatible')}\n" \ + f" - bigquery: 0.10.0 - {green('compatible')}\n" \ + f" - snowflake: 0.10.0 - {green('compatible')}\n" self.assertEqual(latest_version, installed_version) self.assertEqual(latest_version, installed_version) self.assertMultiLineEqual(version_information, @@ -47,23 +47,23 @@ def test_installed_version_greater(self, mock_get, mock_get_dbt_plugins_info): 'info': {'version': '0.10.1'} } mock_get_dbt_plugins_info.return_value = [ - ('dbt-postgres', '0.10.0'), - ('dbt-redshift', '0.10.0'), - ('dbt-bigquery', '0.10.0'), - ('dbt-snowflake', '0.10.0') + ('postgres', '0.10.0'), + ('redshift', '0.10.0'), + ('bigquery', '0.10.0'), + ('snowflake', '0.10.0') ] latest_version = dbt.version.get_latest_version() installed_version = dbt.version.get_installed_version() version_information = dbt.version.get_version_information() expected_version_information = "installed version: 0.10.2-a1\n" \ - " latest version: 0.10.1\n\n" \ - "Your version of dbt is ahead of the latest release!\n\n" \ - "Plugins:\n" \ - " - dbt-postgres: 0.10.0\n" \ - " - dbt-redshift: 0.10.0\n" \ - " - dbt-bigquery: 0.10.0\n" \ - " - dbt-snowflake: 0.10.0\n" + " latest version: 0.10.1\n\n" \ + "Your version of dbt is ahead of the latest release!\n\n" \ + "Plugins:\n" \ + f" - postgres: 0.10.0 - {green('compatible')}\n" \ + f" - redshift: 0.10.0 - {green('compatible')}\n" \ + f" - bigquery: 0.10.0 - {green('compatible')}\n" \ + f" - snowflake: 0.10.0 - {green('compatible')}\n" assert installed_version > latest_version self.assertMultiLineEqual(version_information, @@ -73,34 +73,66 @@ def test_installed_version_greater(self, mock_get, mock_get_dbt_plugins_info): @patch('dbt.version._get_dbt_plugins_info', autospec=True) @patch('dbt.version.requests.get') def test_installed_version_lower(self, mock_get, mock_get_dbt_plugins_info): + mock_get.return_value.json.return_value = { 'info': {'version': '0.10.0'} } mock_get_dbt_plugins_info.return_value = [ - ('dbt-postgres', '0.10.0'), - ('dbt-redshift', '0.10.0'), - ('dbt-bigquery', '0.10.0'), - ('dbt-snowflake', '0.10.0') + ('postgres', '0.10.0'), + ('redshift', '0.10.0'), + ('bigquery', '0.10.0'), + ('snowflake', '0.10.0') ] latest_version = dbt.version.get_latest_version() installed_version = dbt.version.get_installed_version() version_information = dbt.version.get_version_information() expected_version_information = "installed version: 0.9.5\n" \ - " latest version: 0.10.0\n\n" \ - "Your version of dbt is out of date! " \ - "You can find instructions for upgrading here:\n" \ - "https://docs.getdbt.com/docs/installation\n\n" \ - "Plugins:\n" \ - " - dbt-postgres: 0.10.0\n" \ - " - dbt-redshift: 0.10.0\n" \ - " - dbt-bigquery: 0.10.0\n" \ - " - dbt-snowflake: 0.10.0\n" - + " latest version: 0.10.0\n\n" \ + "Your version of dbt is out of date! " \ + "You can find instructions for upgrading here:\n" \ + "https://docs.getdbt.com/docs/installation\n\n" \ + "Plugins:\n" \ + f" - postgres: 0.10.0 - {green('compatible')}\n" \ + f" - redshift: 0.10.0 - {green('compatible')}\n" \ + f" - bigquery: 0.10.0 - {green('compatible')}\n" \ + f" - snowflake: 0.10.0 - {green('compatible')}\n" assert installed_version < latest_version self.assertMultiLineEqual(version_information, expected_version_information) + @patch("dbt.version.__version__", "1.0.1") + @patch('dbt.version._get_dbt_plugins_info', autospec=True) + @patch('dbt.version.requests.get') + def test_installed_version_major(self, mock_get, mock_get_dbt_plugins_info): + mock_get.return_value.json.return_value = { + 'info': {'version': '1.0.1'} + } + mock_get_dbt_plugins_info.return_value = [ + ('postgres', '1.0.0'), + ('redshift', '0.10.0'), + ('bigquery', '0.10.0'), + ('snowflake', '0.10.0') + ] + version_information = dbt.version.get_version_information() + expected_version_information = "installed version: 1.0.1\n" \ + " latest version: 1.0.1\n\n" \ + f"{green('Up to date!')}\n\n" \ + "Plugins:\n" \ + f" - postgres: 1.0.0 - {green('compatible')}\n" \ + f" - redshift: 0.10.0 - {red('requires update!')}\n" \ + " To update dbt-redshift please run:\n" \ + " pip install dbt-redshift --upgrade\n\n" \ + f" - bigquery: 0.10.0 - {red('requires update!')}\n" \ + " To update dbt-bigquery please run:\n" \ + " pip install dbt-bigquery --upgrade\n\n" \ + f" - snowflake: 0.10.0 - {red('requires update!')}\n" \ + " To update dbt-snowflake please run:\n" \ + " pip install dbt-snowflake --upgrade\n\n" + + self.assertMultiLineEqual(version_information, + expected_version_information) + # suppress having version info printed to the screen during tests. @patch('sys.stderr') @patch('dbt.version.requests.get') @@ -125,6 +157,7 @@ def glob_side_effect(path: str) -> str: path.replace('*', 'postgres'), path.replace('*', 'snowflake'), ] + mock_glob.side_effect = glob_side_effect self.assertEqual( list(dbt.version._get_adapter_plugin_names()), @@ -148,6 +181,7 @@ def glob_side_effect(path: str) -> str: return [path.replace('*', 'postgres')] elif 'snowflake' in path: return [path.replace('*', 'snowflake')] + mock_glob.side_effect = glob_side_effect self.assertEqual( list(dbt.version._get_adapter_plugin_names()), @@ -159,7 +193,7 @@ def glob_side_effect(path: str) -> str: @patch('dbt.version._get_adapter_plugin_names', autospec=True) @patch('importlib.import_module', autospec=True) def test_get_dbt_plugins_info_with_version_info( - self, mock_mod, mock_get_plugin_names + self, mock_mod, mock_get_plugin_names ): mock_get_plugin_names.return_value = ['postgres', 'snowflake'] mod_version = unittest.mock.Mock() From e4e8e9766dd21d61e55119f93b6fd32824da9035 Mon Sep 17 00:00:00 2001 From: nkyuray Date: Sun, 30 Jan 2022 18:42:42 +0100 Subject: [PATCH 2/5] edited plugin version compatibility message --- core/dbt/version.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/core/dbt/version.py b/core/dbt/version.py index 8d871649b03..9de87c03d6f 100644 --- a/core/dbt/version.py +++ b/core/dbt/version.py @@ -10,7 +10,7 @@ import dbt.exceptions import dbt.semver -from dbt.ui import green, red +from dbt.ui import green, red, yellow from dbt import flags PYPI_VERSION_URL = 'https://pypi.org/pypi/dbt-core/json' @@ -48,14 +48,18 @@ def get_version_information(): plugin_version_msg = "Plugins:\n" for plugin_name, version in _get_dbt_plugins_info(): - version_major = dbt.semver.VersionSpecifier.from_version_string(version).major + plugin_version = dbt.semver.VersionSpecifier.from_version_string(version) plugin_update_msg = '' - if installed.major == version_major: - compatibility_msg = green('compatible') + if installed == plugin_version: + compatibility_msg = green('Up to date!') else: - compatibility_msg = red('requires update!') - plugin_update_msg = (" To update dbt-{} please run:\n" - " pip install dbt-{} --upgrade\n\n".format(plugin_name, plugin_name)) + if installed.major == plugin_version.major: + compatibility_msg = yellow('Update available!') + else: + compatibility_msg = red('Out of date!') + plugin_update_msg = (" Your version of dbt-{} is out of date! " + "You can find instructions for upgrading here:\n" + " https://docs.getdbt.com/dbt-cli/install/overview\n\n").format(plugin_name) plugin_version_msg += (" - {}: {} - {}\n" "{}").format(plugin_name, version, compatibility_msg, plugin_update_msg) From ff8ca6bbc53d3053f62074bb2264cb58495845b7 Mon Sep 17 00:00:00 2001 From: nkyuray Date: Sun, 30 Jan 2022 19:16:57 +0100 Subject: [PATCH 3/5] edited test version for plugin compability --- test/unit/test_version.py | 70 ++++++++++++++++++++------------------- 1 file changed, 36 insertions(+), 34 deletions(-) diff --git a/test/unit/test_version.py b/test/unit/test_version.py index 98f5b8f28ba..7e66529030c 100644 --- a/test/unit/test_version.py +++ b/test/unit/test_version.py @@ -3,7 +3,7 @@ import dbt.main import dbt.version -from dbt.ui import green, red +from dbt.ui import green, red, yellow class VersionTest(unittest.TestCase): @@ -30,10 +30,10 @@ def test_versions_equal(self, mock_get, mock_get_dbt_plugins_info): " latest version: 0.10.0\n\n" \ f"{green('Up to date!')}\n\n" \ "Plugins:\n" \ - f" - postgres: 0.10.0 - {green('compatible')}\n" \ - f" - redshift: 0.10.0 - {green('compatible')}\n" \ - f" - bigquery: 0.10.0 - {green('compatible')}\n" \ - f" - snowflake: 0.10.0 - {green('compatible')}\n" + f" - postgres: 0.10.0 - {green('Up to date!')}\n" \ + f" - redshift: 0.10.0 - {green('Up to date!')}\n" \ + f" - bigquery: 0.10.0 - {green('Up to date!')}\n" \ + f" - snowflake: 0.10.0 - {green('Up to date!')}\n" self.assertEqual(latest_version, installed_version) self.assertEqual(latest_version, installed_version) self.assertMultiLineEqual(version_information, @@ -47,10 +47,10 @@ def test_installed_version_greater(self, mock_get, mock_get_dbt_plugins_info): 'info': {'version': '0.10.1'} } mock_get_dbt_plugins_info.return_value = [ - ('postgres', '0.10.0'), - ('redshift', '0.10.0'), - ('bigquery', '0.10.0'), - ('snowflake', '0.10.0') + ('postgres', '0.10.2-a1'), + ('redshift', '0.10.2-a1'), + ('bigquery', '0.10.2-a1'), + ('snowflake', '0.10.2-a1') ] latest_version = dbt.version.get_latest_version() installed_version = dbt.version.get_installed_version() @@ -60,10 +60,10 @@ def test_installed_version_greater(self, mock_get, mock_get_dbt_plugins_info): " latest version: 0.10.1\n\n" \ "Your version of dbt is ahead of the latest release!\n\n" \ "Plugins:\n" \ - f" - postgres: 0.10.0 - {green('compatible')}\n" \ - f" - redshift: 0.10.0 - {green('compatible')}\n" \ - f" - bigquery: 0.10.0 - {green('compatible')}\n" \ - f" - snowflake: 0.10.0 - {green('compatible')}\n" + f" - postgres: 0.10.2-a1 - {green('Up to date!')}\n" \ + f" - redshift: 0.10.2-a1 - {green('Up to date!')}\n" \ + f" - bigquery: 0.10.2-a1 - {green('Up to date!')}\n" \ + f" - snowflake: 0.10.2-a1 - {green('Up to date!')}\n" assert installed_version > latest_version self.assertMultiLineEqual(version_information, @@ -78,10 +78,10 @@ def test_installed_version_lower(self, mock_get, mock_get_dbt_plugins_info): 'info': {'version': '0.10.0'} } mock_get_dbt_plugins_info.return_value = [ - ('postgres', '0.10.0'), - ('redshift', '0.10.0'), - ('bigquery', '0.10.0'), - ('snowflake', '0.10.0') + ('postgres', '0.9.5'), + ('redshift', '0.9.5'), + ('bigquery', '0.9.5'), + ('snowflake', '0.9.5') ] latest_version = dbt.version.get_latest_version() installed_version = dbt.version.get_installed_version() @@ -93,10 +93,10 @@ def test_installed_version_lower(self, mock_get, mock_get_dbt_plugins_info): "You can find instructions for upgrading here:\n" \ "https://docs.getdbt.com/docs/installation\n\n" \ "Plugins:\n" \ - f" - postgres: 0.10.0 - {green('compatible')}\n" \ - f" - redshift: 0.10.0 - {green('compatible')}\n" \ - f" - bigquery: 0.10.0 - {green('compatible')}\n" \ - f" - snowflake: 0.10.0 - {green('compatible')}\n" + f" - postgres: 0.9.5 - {green('Up to date!')}\n" \ + f" - redshift: 0.9.5 - {green('Up to date!')}\n" \ + f" - bigquery: 0.9.5 - {green('Up to date!')}\n" \ + f" - snowflake: 0.9.5 - {green('Up to date!')}\n" assert installed_version < latest_version self.assertMultiLineEqual(version_information, expected_version_information) @@ -109,8 +109,8 @@ def test_installed_version_major(self, mock_get, mock_get_dbt_plugins_info): 'info': {'version': '1.0.1'} } mock_get_dbt_plugins_info.return_value = [ - ('postgres', '1.0.0'), - ('redshift', '0.10.0'), + ('postgres', '1.0.1'), + ('redshift', '1.0.0'), ('bigquery', '0.10.0'), ('snowflake', '0.10.0') ] @@ -119,17 +119,19 @@ def test_installed_version_major(self, mock_get, mock_get_dbt_plugins_info): " latest version: 1.0.1\n\n" \ f"{green('Up to date!')}\n\n" \ "Plugins:\n" \ - f" - postgres: 1.0.0 - {green('compatible')}\n" \ - f" - redshift: 0.10.0 - {red('requires update!')}\n" \ - " To update dbt-redshift please run:\n" \ - " pip install dbt-redshift --upgrade\n\n" \ - f" - bigquery: 0.10.0 - {red('requires update!')}\n" \ - " To update dbt-bigquery please run:\n" \ - " pip install dbt-bigquery --upgrade\n\n" \ - f" - snowflake: 0.10.0 - {red('requires update!')}\n" \ - " To update dbt-snowflake please run:\n" \ - " pip install dbt-snowflake --upgrade\n\n" - + f" - postgres: 1.0.1 - {green('Up to date!')}\n" \ + f" - redshift: 1.0.0 - {yellow('Update available!')}\n" \ + " Your version of dbt-redshift is out of date! You can find instructions for " \ + "upgrading here:\n" \ + " https://docs.getdbt.com/dbt-cli/install/overview\n\n" \ + f" - bigquery: 0.10.0 - {red('Out of date!')}\n" \ + " Your version of dbt-bigquery is out of date! You can find instructions for " \ + "upgrading here:\n" \ + " https://docs.getdbt.com/dbt-cli/install/overview\n\n" \ + f" - snowflake: 0.10.0 - {red('Out of date!')}\n" \ + " Your version of dbt-snowflake is out of date! You can find instructions for " \ + "upgrading here:\n" \ + " https://docs.getdbt.com/dbt-cli/install/overview\n\n" self.assertMultiLineEqual(version_information, expected_version_information) From 433f9fa81898849c0e3f268c2514093016232a7c Mon Sep 17 00:00:00 2001 From: Chenyu Li Date: Thu, 3 Feb 2022 10:15:06 -0500 Subject: [PATCH 4/5] compare using only major and minor --- core/dbt/version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/dbt/version.py b/core/dbt/version.py index 9de87c03d6f..857b4f7bf2f 100644 --- a/core/dbt/version.py +++ b/core/dbt/version.py @@ -50,7 +50,7 @@ def get_version_information(): for plugin_name, version in _get_dbt_plugins_info(): plugin_version = dbt.semver.VersionSpecifier.from_version_string(version) plugin_update_msg = '' - if installed == plugin_version: + if installed.major == plugin_version.major and installed.minor == plugin_version.minor: compatibility_msg = green('Up to date!') else: if installed.major == plugin_version.major: From 260e2bb2ec3a28b6248a90c1704294ffcebdd4ce Mon Sep 17 00:00:00 2001 From: ChenyuLi Date: Thu, 3 Feb 2022 16:03:47 -0500 Subject: [PATCH 5/5] Add checking PYPI and update changelog --- CHANGELOG.md | 6 ++++++ core/dbt/version.py | 36 +++++++++++++++++++++++----------- test/unit/test_version.py | 41 +++++++++++++++++++++++++++------------ 3 files changed, 60 insertions(+), 23 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2761a3746c4..2f0c66ca091 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,12 @@ ### Under the hood - Testing cleanup ([#4496](https://github.com/dbt-labs/dbt-core/pull/4496), [#4509](https://github.com/dbt-labs/dbt-core/pull/4509)) +## dbt-core 1.0.2 (TBD) +### Fixes +- adapter compability messaging added([#4438](https://github.com/dbt-labs/dbt-core/pull/4438) [#4565](https://github.com/dbt-labs/dbt-core/pull/4565)) + +Contributors: +* [@nkyuray](https://github.com/nkyuray) ([#4565](https://github.com/dbt-labs/dbt-core/pull/4565)) ## dbt-core 1.0.1 (January 03, 2022) ## dbt-core 1.0.1rc1 (December 20, 2021) diff --git a/core/dbt/version.py b/core/dbt/version.py index 857b4f7bf2f..2438ec015db 100644 --- a/core/dbt/version.py +++ b/core/dbt/version.py @@ -16,9 +16,9 @@ PYPI_VERSION_URL = 'https://pypi.org/pypi/dbt-core/json' -def get_latest_version(): +def get_latest_version(version_url: str = PYPI_VERSION_URL): try: - resp = requests.get(PYPI_VERSION_URL) + resp = requests.get(version_url) data = resp.json() version_string = data['info']['version'] except (json.JSONDecodeError, KeyError, requests.RequestException): @@ -31,6 +31,10 @@ def get_installed_version(): return dbt.semver.VersionSpecifier.from_version_string(__version__) +def get_package_pypi_url(package_name: str) -> str: + return f'https://pypi.org/pypi/dbt-{package_name}/json' + + def get_version_information(): flags.USE_COLORS = True if not flags.USE_COLORS else None @@ -49,20 +53,30 @@ def get_version_information(): plugin_version_msg = "Plugins:\n" for plugin_name, version in _get_dbt_plugins_info(): plugin_version = dbt.semver.VersionSpecifier.from_version_string(version) + latest_plugin_version = get_latest_version(version_url=get_package_pypi_url(plugin_name)) plugin_update_msg = '' - if installed.major == plugin_version.major and installed.minor == plugin_version.minor: + if installed == plugin_version or ( + latest_plugin_version and plugin_version == latest_plugin_version + ): compatibility_msg = green('Up to date!') else: - if installed.major == plugin_version.major: - compatibility_msg = yellow('Update available!') + if latest_plugin_version: + if installed.major == plugin_version.major: + compatibility_msg = yellow('Update available!') + else: + compatibility_msg = red('Out of date!') + plugin_update_msg = ( + " Your version of dbt-{} is out of date! " + "You can find instructions for upgrading here:\n" + " https://docs.getdbt.com/dbt-cli/install/overview\n\n" + ).format(plugin_name) else: - compatibility_msg = red('Out of date!') - plugin_update_msg = (" Your version of dbt-{} is out of date! " - "You can find instructions for upgrading here:\n" - " https://docs.getdbt.com/dbt-cli/install/overview\n\n").format(plugin_name) + compatibility_msg = yellow('No PYPI version available') - plugin_version_msg += (" - {}: {} - {}\n" - "{}").format(plugin_name, version, compatibility_msg, plugin_update_msg) + plugin_version_msg += ( + " - {}: {} - {}\n" + "{}" + ).format(plugin_name, version, compatibility_msg, plugin_update_msg) if latest is None: return ("{}The latest version of dbt could not be determined!\n" diff --git a/test/unit/test_version.py b/test/unit/test_version.py index 7e66529030c..6642be8281b 100644 --- a/test/unit/test_version.py +++ b/test/unit/test_version.py @@ -6,6 +6,14 @@ from dbt.ui import green, red, yellow +class MockResponse(object): + + def __init__(self, content: dict) -> None: + self.content = content + + def json(self) -> dict: + return self.content + class VersionTest(unittest.TestCase): @patch("dbt.version.__version__", "0.10.0") @@ -13,7 +21,7 @@ class VersionTest(unittest.TestCase): @patch('dbt.version.requests.get') def test_versions_equal(self, mock_get, mock_get_dbt_plugins_info): mock_get.return_value.json.return_value = { - 'info': {'version': '0.10.0'} + 'info': {'version': '0.10.0'}, } mock_get_dbt_plugins_info.return_value = [ ('postgres', '0.10.0'), @@ -104,15 +112,24 @@ def test_installed_version_lower(self, mock_get, mock_get_dbt_plugins_info): @patch("dbt.version.__version__", "1.0.1") @patch('dbt.version._get_dbt_plugins_info', autospec=True) @patch('dbt.version.requests.get') - def test_installed_version_major(self, mock_get, mock_get_dbt_plugins_info): - mock_get.return_value.json.return_value = { - 'info': {'version': '1.0.1'} - } + def test_installed_version_major_minor_pypi(self, mock_get, mock_get_dbt_plugins_info): + mock_get.side_effect = [ + MockResponse({'info': {'version': '1.0.1'}}), # version for dbt-core + MockResponse({'info': {'version': '1.0.1'}}), # version for dbt-postgres + MockResponse({'info': {'version': '1.0.1'}}), # version for dbt-redshift + MockResponse({'info': {'version': '1.0.0'}}), # version for dbt-bigquery + MockResponse({'info': {'version': '1.0.1'}}), # version for dbt-snowflake + KeyError('no PYPI Version'), # no PYPI registry for newdb1 + KeyError('no PYPI Version') # no PYPI registry for newdb2 + ] + mock_get_dbt_plugins_info.return_value = [ ('postgres', '1.0.1'), ('redshift', '1.0.0'), - ('bigquery', '0.10.0'), - ('snowflake', '0.10.0') + ('bigquery', '1.0.0'), + ('snowflake', '0.10.0'), + ('newdb1', '1.0.1'), + ('newdb2', '0.5.1'), ] version_information = dbt.version.get_version_information() expected_version_information = "installed version: 1.0.1\n" \ @@ -124,14 +141,14 @@ def test_installed_version_major(self, mock_get, mock_get_dbt_plugins_info): " Your version of dbt-redshift is out of date! You can find instructions for " \ "upgrading here:\n" \ " https://docs.getdbt.com/dbt-cli/install/overview\n\n" \ - f" - bigquery: 0.10.0 - {red('Out of date!')}\n" \ - " Your version of dbt-bigquery is out of date! You can find instructions for " \ - "upgrading here:\n" \ - " https://docs.getdbt.com/dbt-cli/install/overview\n\n" \ + f" - bigquery: 1.0.0 - {green('Up to date!')}\n" \ f" - snowflake: 0.10.0 - {red('Out of date!')}\n" \ " Your version of dbt-snowflake is out of date! You can find instructions for " \ "upgrading here:\n" \ - " https://docs.getdbt.com/dbt-cli/install/overview\n\n" + " https://docs.getdbt.com/dbt-cli/install/overview\n\n"\ + f" - newdb1: 1.0.1 - {green('Up to date!')}\n" \ + f" - newdb2: 0.5.1 - {yellow('No PYPI version available')}\n" + self.assertMultiLineEqual(version_information, expected_version_information)