From 613a844e727acc6617e4698db2da74da4d2466ed Mon Sep 17 00:00:00 2001 From: Dheyay Date: Wed, 14 Aug 2024 13:35:18 -0700 Subject: [PATCH] tests update Updated unit tests for change made to how config is read using the config api Updated api.feature behave test to add new endpoints --- features/api/api.feature | 2 ++ uaclient/cli/tests/test_cli_attach.py | 5 ++-- uaclient/cli/tests/test_cli_config_show.py | 5 ++-- uaclient/cli/tests/test_cli_status.py | 25 ++++++++++--------- uaclient/tests/test_status.py | 28 ++++++++++------------ 5 files changed, 30 insertions(+), 35 deletions(-) diff --git a/features/api/api.feature b/features/api/api.feature index 46c51e82bc..196ed93412 100644 --- a/features/api/api.feature +++ b/features/api/api.feature @@ -8,6 +8,7 @@ Feature: Client behaviour for the API endpoints When I run `python3 -c "from uaclient.api.u.pro.attach.magic.initiate.v1 import initiate"` as non-root When I run `python3 -c "from uaclient.api.u.pro.attach.magic.revoke.v1 import revoke"` as non-root When I run `python3 -c "from uaclient.api.u.pro.attach.magic.wait.v1 import wait"` as non-root + When I run `python3 -c "from uaclient.api.u.pro.config.v1 import config"` as non-root When I run `python3 -c "from uaclient.api.u.pro.packages.summary.v1 import summary"` as non-root When I run `python3 -c "from uaclient.api.u.pro.packages.updates.v1 import updates"` as non-root When I run `python3 -c "from uaclient.api.u.pro.security.fix.cve.execute.v1 import execute"` as non-root @@ -19,6 +20,7 @@ Feature: Client behaviour for the API endpoints When I run `python3 -c "from uaclient.api.u.pro.services.dependencies.v1 import dependencies"` as non-root When I run `python3 -c "from uaclient.api.u.pro.status.enabled_services.v1 import enabled_services"` as non-root When I run `python3 -c "from uaclient.api.u.pro.status.is_attached.v1 import is_attached"` as non-root + When I run `python3 -c "from uaclient.api.u.pro.subscription.v1 import subscription"` as non-root When I run `python3 -c "from uaclient.api.u.pro.version.v1 import version"` as non-root When I run `python3 -c "from uaclient.api.u.security.package_manifest.v1 import package_manifest"` as non-root When I run `python3 -c "from uaclient.api.u.unattended_upgrades.status.v1 import status"` as non-root diff --git a/uaclient/cli/tests/test_cli_attach.py b/uaclient/cli/tests/test_cli_attach.py index 8ad1e6bd99..6f36b80d1d 100644 --- a/uaclient/cli/tests/test_cli_attach.py +++ b/uaclient/cli/tests/test_cli_attach.py @@ -518,13 +518,12 @@ def test_attach_config_enable_services( @mock.patch("uaclient.contract.UAContractClient.request_url") @mock.patch("uaclient.timer.update_messaging.update_motd_messages") @mock.patch( - "uaclient.files.user_config_file.UserConfigFileObject.public_config", - new_callable=mock.PropertyMock, + "uaclient.files.user_config_file.UserConfigFileObject.read", return_value=UserConfigData(), ) def test_attach_when_one_service_fails_to_enable( self, - m_public_config, + _m_config_read, _m_update_messages, m_request_url, _m_apply_contract_overrides, diff --git a/uaclient/cli/tests/test_cli_config_show.py b/uaclient/cli/tests/test_cli_config_show.py index 99195dc391..9eb082eb22 100644 --- a/uaclient/cli/tests/test_cli_config_show.py +++ b/uaclient/cli/tests/test_cli_config_show.py @@ -46,12 +46,11 @@ class TestActionConfigShow: ), ) @mock.patch( - "uaclient.files.user_config_file.UserConfigFileObject.public_config", - new_callable=mock.PropertyMock, + "uaclient.files.user_config_file.UserConfigFileObject.read", return_value=UserConfigData(), ) def test_show_values_and_limit_when_optional_key_provided( - self, _m_public_config, optional_key, FakeConfig, capsys + self, _m_config_read, optional_key, FakeConfig, capsys ): cfg = FakeConfig() cfg.user_config.http_proxy = "http://http_proxy" diff --git a/uaclient/cli/tests/test_cli_status.py b/uaclient/cli/tests/test_cli_status.py index 7247007019..bc909f09e1 100644 --- a/uaclient/cli/tests/test_cli_status.py +++ b/uaclient/cli/tests/test_cli_status.py @@ -292,8 +292,7 @@ return_value=RESPONSE_CONTRACT_INFO, ) @mock.patch( - "uaclient.files.user_config_file.UserConfigFileObject.public_config", - new_callable=mock.PropertyMock, + "uaclient.files.user_config_file.UserConfigFileObject.read", return_value=UserConfigData(), ) class TestActionStatus: @@ -327,7 +326,7 @@ def test_attached( self, _m_format_expires, _m_status_cache_file, - _m_public_config, + _m_config_read, _m_get_contract_information, _m_get_avail_resources, _m_should_reboot, @@ -387,7 +386,7 @@ def test_attached( def test_unattached( self, _m_status_cache_file, - _m_public_config, + _m_config_read, _m_get_contract_information, _m_get_avail_resources, _m_should_reboot, @@ -414,7 +413,7 @@ def test_unattached( ) def test_simulated( self, - _m_public_config, + _m_config_read, _m_get_contract_information, _m_get_avail_resources, _m_should_reboot, @@ -445,7 +444,7 @@ def test_wait_blocks_until_lock_released( _m_get_version, m_check_lock_info, _m_status_cache_file, - _m_public_config, + _m_config_read, _m_get_contract_information, _m_get_avail_resources, _m_should_reboot, @@ -500,7 +499,7 @@ def fake_sleep(seconds): def test_unattached_formats( self, _m_status_cache_file, - _m_public_config, + _m_config_read, _m_get_contract_information, _m_get_avail_resources, _m_should_reboot, @@ -612,7 +611,7 @@ def test_unattached_formats( def test_attached_formats( self, _m_status_cache_file, - _m_public_config, + _m_config_read, _m_get_contract_information, _m_get_avail_resources, _m_should_reboot, @@ -746,7 +745,7 @@ def test_attached_formats( @pytest.mark.parametrize("use_all", (True, False)) def test_simulated_formats( self, - _m_public_config, + _m_config_read, _m_get_contract_information, _m_get_avail_resources, _m_should_reboot, @@ -897,7 +896,7 @@ def test_simulated_formats( def test_error_on_connectivity_errors( self, - _m_public_config, + _m_config_read, _m_get_contract_information, m_get_avail_resources, _m_should_reboot, @@ -927,7 +926,7 @@ def test_unicode_dash_replacement_when_unprintable( self, _m_format_expires, _m_status_cache_file, - _m_public_config, + _m_config_read, _m_get_contract_information, _m_get_avail_resources, _m_should_reboot, @@ -989,7 +988,7 @@ def test_unicode_dash_replacement_when_unprintable( ) def test_errors_are_raised_appropriately( self, - _m_public_config, + _m_config_read, m_get_contract_information, _m_get_avail_resources, _m_should_reboot, @@ -1050,7 +1049,7 @@ def test_errors_are_raised_appropriately( ) def test_errors_for_token_dates( self, - _m_public_config, + _m_config_read, m_get_contract_information, _m_get_avail_resources, _m_should_reboot, diff --git a/uaclient/tests/test_status.py b/uaclient/tests/test_status.py index de39612e35..b7181b8784 100644 --- a/uaclient/tests/test_status.py +++ b/uaclient/tests/test_status.py @@ -552,12 +552,12 @@ def test_root_attached( @mock.patch("uaclient.util.we_are_currently_root") @mock.patch("uaclient.status.get_available_resources") @mock.patch( - "uaclient.files.user_config_file.UserConfigFileObject.public_config", - new_callable=mock.PropertyMock, + "uaclient.files.user_config_file.UserConfigFileObject.read", + return_value=UserConfigData(), ) def test_nonroot_unattached_is_same_as_unattached_root( self, - m_public_config, + m_config_read, m_get_available_resources, m_we_are_currently_root, _m_status_cache_file, @@ -566,7 +566,6 @@ def test_nonroot_unattached_is_same_as_unattached_root( m_on_supported_kernel, FakeConfig, ): - m_public_config.return_value = UserConfigData() m_get_available_resources.return_value = [ {"name": "esm-infra", "available": True} ] @@ -584,12 +583,12 @@ def test_nonroot_unattached_is_same_as_unattached_root( @mock.patch("uaclient.util.we_are_currently_root") @mock.patch("uaclient.status.get_available_resources") @mock.patch( - "uaclient.files.user_config_file.UserConfigFileObject.public_config", - new_callable=mock.PropertyMock, + "uaclient.files.user_config_file.UserConfigFileObject.read", + return_value=UserConfigData(), ) def test_root_and_non_root_are_same_attached( self, - m_public_config, + m_config_read, m_get_available_resources, m_we_are_currently_root, _m_status_cache_file, @@ -599,7 +598,6 @@ def test_root_and_non_root_are_same_attached( FakeConfig, fake_machine_token_file, ): - m_public_config.return_value = UserConfigData() m_we_are_currently_root.return_value = True fake_machine_token_file.attached = True cfg = FakeConfig() @@ -853,12 +851,12 @@ def test_attached_reports_contract_and_service_status( @mock.patch("uaclient.util.we_are_currently_root") @mock.patch("uaclient.status.get_available_resources") @mock.patch( - "uaclient.files.user_config_file.UserConfigFileObject.public_config", - new_callable=mock.PropertyMock, + "uaclient.files.user_config_file.UserConfigFileObject.read", + return_value=UserConfigData(), ) def test_expires_handled_appropriately( self, - m_public_config, + m_config_read, _m_get_available_resources, m_we_are_currently_root, _m_status_cache_file, @@ -869,7 +867,6 @@ def test_expires_handled_appropriately( FakeConfig, fake_machine_token_file, ): - m_public_config.return_value = UserConfigData() m_we_are_currently_root.return_value = True token = { "availableResources": all_resources_available, @@ -911,8 +908,8 @@ def test_expires_handled_appropriately( new_callable=mock.PropertyMock, ) @mock.patch( - "uaclient.files.user_config_file.UserConfigFileObject.public_config", - new_callable=mock.PropertyMock, + "uaclient.files.user_config_file.UserConfigFileObject.read", + return_value=UserConfigData(), ) @mock.patch("uaclient.files.state_files.status_cache_file.read") @mock.patch("uaclient.files.state_files.status_cache_file.write") @@ -922,14 +919,13 @@ def test_nonroot_user_does_not_use_cache( _m_get_available_resources, _m_status_cache_file_write, m_status_cache_file_read, - m_public_config, + m_config_read, m_reboot_cmd_marker_file, _m_should_reboot, m_remove_notice, m_on_supported_kernel, FakeConfig, ): - m_public_config.return_value = UserConfigData() m_reboot_cmd_marker_file.is_present = True cached_status = {"pass": True} m_status_cache_file_read.return_value = cached_status