Skip to content

Commit

Permalink
tests update
Browse files Browse the repository at this point in the history
Updated unit tests for change made to how config is read using the config api
Updated api.feature behave test to add new endpoints
  • Loading branch information
dheyay committed Sep 5, 2024
1 parent 50d5392 commit 3f9b9d4
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 35 deletions.
2 changes: 2 additions & 0 deletions features/api/api.feature
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,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
Expand All @@ -21,6 +22,7 @@ Feature: Client behaviour for the API endpoints
When I run `python3 -c "from uaclient.api.u.pro.services.list.v1 import list"` 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
Expand Down
5 changes: 2 additions & 3 deletions uaclient/cli/tests/test_cli_attach.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 2 additions & 3 deletions uaclient/cli/tests/test_cli_config_show.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
25 changes: 12 additions & 13 deletions uaclient/cli/tests/test_cli_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
28 changes: 12 additions & 16 deletions uaclient/tests/test_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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}
]
Expand All @@ -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,
Expand All @@ -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()
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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")
Expand All @@ -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
Expand Down

0 comments on commit 3f9b9d4

Please sign in to comment.