Skip to content

Commit

Permalink
Reorganize file structure of unit tests (#2894)
Browse files Browse the repository at this point in the history
* Reorganize file structure of unit tests

* remove duplicate

* add init

* mocks

---------

Co-authored-by: narrieta <narrieta>
  • Loading branch information
narrieta authored Aug 11, 2023
1 parent 0e99ee1 commit 4a1d3de
Show file tree
Hide file tree
Showing 91 changed files with 456 additions and 481 deletions.
2 changes: 1 addition & 1 deletion tests/common/dhcp/test_dhcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import mock
import azurelinuxagent.common.dhcp as dhcp
import azurelinuxagent.common.osutil.default as osutil
from tests.tools import AgentTestCase, open_patch, patch
from tests.lib.tools import AgentTestCase, open_patch, patch


class TestDHCP(AgentTestCase):
Expand Down
2 changes: 1 addition & 1 deletion tests/common/osutil/test_alpine.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import unittest

from azurelinuxagent.common.osutil.alpine import AlpineOSUtil
from tests.tools import AgentTestCase
from tests.lib.tools import AgentTestCase
from .test_default import osutil_get_dhcp_pid_should_return_a_list_of_pids


Expand Down
2 changes: 1 addition & 1 deletion tests/common/osutil/test_arch.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import unittest

from azurelinuxagent.common.osutil.arch import ArchUtil
from tests.tools import AgentTestCase
from tests.lib.tools import AgentTestCase
from .test_default import osutil_get_dhcp_pid_should_return_a_list_of_pids


Expand Down
2 changes: 1 addition & 1 deletion tests/common/osutil/test_bigip.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import azurelinuxagent.common.utils.shellutil as shellutil
from azurelinuxagent.common.exception import OSUtilError
from azurelinuxagent.common.osutil.bigip import BigIpOSUtil
from tests.tools import AgentTestCase, patch
from tests.lib.tools import AgentTestCase, patch
from .test_default import osutil_get_dhcp_pid_should_return_a_list_of_pids


Expand Down
2 changes: 1 addition & 1 deletion tests/common/osutil/test_clearlinux.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import unittest

from azurelinuxagent.common.osutil.clearlinux import ClearLinuxUtil
from tests.tools import AgentTestCase
from tests.lib.tools import AgentTestCase
from .test_default import osutil_get_dhcp_pid_should_return_a_list_of_pids


Expand Down
2 changes: 1 addition & 1 deletion tests/common/osutil/test_coreos.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import unittest

from azurelinuxagent.common.osutil.coreos import CoreOSUtil
from tests.tools import AgentTestCase
from tests.lib.tools import AgentTestCase
from .test_default import osutil_get_dhcp_pid_should_return_a_list_of_pids


Expand Down
4 changes: 2 additions & 2 deletions tests/common/osutil/test_default.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
from azurelinuxagent.common.utils import fileutil
from azurelinuxagent.common.utils.flexible_version import FlexibleVersion
from azurelinuxagent.common.utils.networkutil import AddFirewallRules
from tests.common.mock_environment import MockEnvironment
from tests.tools import AgentTestCase, patch, open_patch, load_data, data_dir, is_python_version_26_or_34, skip_if_predicate_true
from tests.lib.mock_environment import MockEnvironment
from tests.lib.tools import AgentTestCase, patch, open_patch, load_data, data_dir, is_python_version_26_or_34, skip_if_predicate_true

actual_get_proc_net_route = 'azurelinuxagent.common.osutil.default.DefaultOSUtil._get_proc_net_route'

Expand Down
2 changes: 1 addition & 1 deletion tests/common/osutil/test_default_osutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#

from azurelinuxagent.common.osutil.default import DefaultOSUtil, shellutil # pylint: disable=unused-import
from tests.tools import AgentTestCase, patch # pylint: disable=unused-import
from tests.lib.tools import AgentTestCase, patch # pylint: disable=unused-import


class DefaultOsUtilTestCase(AgentTestCase):
Expand Down
2 changes: 1 addition & 1 deletion tests/common/osutil/test_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
from azurelinuxagent.common.osutil.suse import SUSEOSUtil, SUSE11OSUtil
from azurelinuxagent.common.osutil.ubuntu import UbuntuOSUtil, Ubuntu12OSUtil, Ubuntu14OSUtil, \
UbuntuSnappyOSUtil, Ubuntu16OSUtil, Ubuntu18OSUtil
from tests.tools import AgentTestCase, patch
from tests.lib.tools import AgentTestCase, patch


class TestOsUtilFactory(AgentTestCase):
Expand Down
2 changes: 1 addition & 1 deletion tests/common/osutil/test_freebsd.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import azurelinuxagent.common.utils.shellutil as shellutil
from azurelinuxagent.common.osutil.freebsd import FreeBSDOSUtil
from azurelinuxagent.common.utils import textutil
from tests.tools import AgentTestCase, patch
from tests.lib.tools import AgentTestCase, patch
from .test_default import osutil_get_dhcp_pid_should_return_a_list_of_pids


Expand Down
2 changes: 1 addition & 1 deletion tests/common/osutil/test_nsbsd.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

from azurelinuxagent.common.osutil.nsbsd import NSBSDOSUtil
from azurelinuxagent.common.utils.fileutil import read_file
from tests.tools import AgentTestCase, patch
from tests.lib.tools import AgentTestCase, patch


class TestNSBSDOSUtil(AgentTestCase):
Expand Down
2 changes: 1 addition & 1 deletion tests/common/osutil/test_openbsd.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import unittest

from azurelinuxagent.common.osutil.openbsd import OpenBSDOSUtil
from tests.tools import AgentTestCase
from tests.lib.tools import AgentTestCase
from .test_default import osutil_get_dhcp_pid_should_return_a_list_of_pids


Expand Down
2 changes: 1 addition & 1 deletion tests/common/osutil/test_openwrt.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import unittest

from azurelinuxagent.common.osutil.openwrt import OpenWRTOSUtil
from tests.tools import AgentTestCase
from tests.lib.tools import AgentTestCase
from .test_default import osutil_get_dhcp_pid_should_return_a_list_of_pids


Expand Down
2 changes: 1 addition & 1 deletion tests/common/osutil/test_photonos.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import unittest

from azurelinuxagent.common.osutil.photonos import PhotonOSUtil
from tests.tools import AgentTestCase
from tests.lib.tools import AgentTestCase
from .test_default import osutil_get_dhcp_pid_should_return_a_list_of_pids


Expand Down
2 changes: 1 addition & 1 deletion tests/common/osutil/test_redhat.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import unittest

from azurelinuxagent.common.osutil.redhat import Redhat6xOSUtil
from tests.tools import AgentTestCase
from tests.lib.tools import AgentTestCase
from .test_default import osutil_get_dhcp_pid_should_return_a_list_of_pids


Expand Down
2 changes: 1 addition & 1 deletion tests/common/osutil/test_suse.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import unittest

from azurelinuxagent.common.osutil.suse import SUSE11OSUtil
from tests.tools import AgentTestCase
from tests.lib.tools import AgentTestCase
from .test_default import osutil_get_dhcp_pid_should_return_a_list_of_pids


Expand Down
2 changes: 1 addition & 1 deletion tests/common/osutil/test_ubuntu.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import unittest

from azurelinuxagent.common.osutil.ubuntu import Ubuntu12OSUtil, Ubuntu18OSUtil
from tests.tools import AgentTestCase
from tests.lib.tools import AgentTestCase
from .test_default import osutil_get_dhcp_pid_should_return_a_list_of_pids


Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@
# Licensed under the Apache License.
from azurelinuxagent.common.AgentGlobals import AgentGlobals
from azurelinuxagent.common.protocol.extensions_goal_state import GoalStateChannel
from tests.protocol.mocks import mockwiredata, mock_wire_protocol
from tests.tools import AgentTestCase
from tests.lib.mock_wire_protocol import wire_protocol_data, mock_wire_protocol
from tests.lib.tools import AgentTestCase


class ExtensionsGoalStateFromExtensionsConfigTestCase(AgentTestCase):
def test_it_should_parse_in_vm_metadata(self):
with mock_wire_protocol(mockwiredata.DATA_FILE_IN_VM_META_DATA) as protocol:
with mock_wire_protocol(wire_protocol_data.DATA_FILE_IN_VM_META_DATA) as protocol:
extensions_goal_state = protocol.get_goal_state().extensions_goal_state
self.assertEqual("555e551c-600e-4fb4-90ba-8ab8ec28eccc", extensions_goal_state.activity_id, "Incorrect activity Id")
self.assertEqual("400de90b-522e-491f-9d89-ec944661f531", extensions_goal_state.correlation_id, "Incorrect correlation Id")
self.assertEqual('2020-11-09T17:48:50.412125Z', extensions_goal_state.created_on_timestamp, "Incorrect GS Creation time")

def test_it_should_use_default_values_when_in_vm_metadata_is_missing(self):
data_file = mockwiredata.DATA_FILE.copy()
data_file = wire_protocol_data.DATA_FILE.copy()
data_file["ext_conf"] = "wire/ext_conf-no_gs_metadata.xml"
with mock_wire_protocol(data_file) as protocol:
extensions_goal_state = protocol.get_goal_state().extensions_goal_state
Expand All @@ -24,14 +24,14 @@ def test_it_should_use_default_values_when_in_vm_metadata_is_missing(self):
self.assertEqual('1900-01-01T00:00:00.000000Z', extensions_goal_state.created_on_timestamp, "Incorrect GS Creation time")

def test_it_should_use_default_values_when_in_vm_metadata_is_invalid(self):
with mock_wire_protocol(mockwiredata.DATA_FILE_INVALID_VM_META_DATA) as protocol:
with mock_wire_protocol(wire_protocol_data.DATA_FILE_INVALID_VM_META_DATA) as protocol:
extensions_goal_state = protocol.get_goal_state().extensions_goal_state
self.assertEqual(AgentGlobals.GUID_ZERO, extensions_goal_state.activity_id, "Incorrect activity Id")
self.assertEqual(AgentGlobals.GUID_ZERO, extensions_goal_state.correlation_id, "Incorrect correlation Id")
self.assertEqual('1900-01-01T00:00:00.000000Z', extensions_goal_state.created_on_timestamp, "Incorrect GS Creation time")

def test_it_should_parse_missing_status_upload_blob_as_none(self):
data_file = mockwiredata.DATA_FILE.copy()
data_file = wire_protocol_data.DATA_FILE.copy()
data_file["ext_conf"] = "hostgaplugin/ext_conf-no_status_upload_blob.xml"
with mock_wire_protocol(data_file) as protocol:
extensions_goal_state = protocol.get_goal_state().extensions_goal_state
Expand All @@ -40,14 +40,14 @@ def test_it_should_parse_missing_status_upload_blob_as_none(self):
self.assertEqual("BlockBlob", extensions_goal_state.status_upload_blob_type, "Expected status upload blob to be Block")

def test_it_should_default_to_block_blob_when_the_status_blob_type_is_not_valid(self):
data_file = mockwiredata.DATA_FILE.copy()
data_file = wire_protocol_data.DATA_FILE.copy()
data_file["ext_conf"] = "hostgaplugin/ext_conf-invalid_blob_type.xml"
with mock_wire_protocol(data_file) as protocol:
extensions_goal_state = protocol.get_goal_state().extensions_goal_state
self.assertEqual("BlockBlob", extensions_goal_state.status_upload_blob_type, 'Expected BlockBlob for an invalid statusBlobType')

def test_it_should_parse_empty_depends_on_as_dependency_level_0(self):
data_file = mockwiredata.DATA_FILE_VM_SETTINGS.copy()
data_file = wire_protocol_data.DATA_FILE_VM_SETTINGS.copy()
data_file["vm_settings"] = "hostgaplugin/vm_settings-empty_depends_on.json"
data_file["ext_conf"] = "hostgaplugin/ext_conf-empty_depends_on.xml"
with mock_wire_protocol(data_file) as protocol:
Expand All @@ -56,7 +56,7 @@ def test_it_should_parse_empty_depends_on_as_dependency_level_0(self):
self.assertEqual(0, extensions[0].settings[0].dependencyLevel, "Incorrect dependencyLevel")

def test_its_source_channel_should_be_wire_server(self):
with mock_wire_protocol(mockwiredata.DATA_FILE) as protocol:
with mock_wire_protocol(wire_protocol_data.DATA_FILE) as protocol:
extensions_goal_state = protocol.get_goal_state().extensions_goal_state

self.assertEqual(GoalStateChannel.WireServer, extensions_goal_state.channel, "The channel is incorrect")
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
from azurelinuxagent.common.protocol.goal_state import GoalState
from azurelinuxagent.common.protocol.extensions_goal_state import GoalStateChannel
from azurelinuxagent.common.protocol.extensions_goal_state_from_vm_settings import _CaseFoldedDict
from tests.protocol.mocks import mockwiredata, mock_wire_protocol
from tests.tools import AgentTestCase
from tests.lib.mock_wire_protocol import wire_protocol_data, mock_wire_protocol
from tests.lib.tools import AgentTestCase


class ExtensionsGoalStateFromVmSettingsTestCase(AgentTestCase):
def test_it_should_parse_vm_settings(self):
with mock_wire_protocol(mockwiredata.DATA_FILE_VM_SETTINGS) as protocol:
with mock_wire_protocol(wire_protocol_data.DATA_FILE_VM_SETTINGS) as protocol:
extensions_goal_state = protocol.get_goal_state().extensions_goal_state

def assert_property(name, value):
Expand Down Expand Up @@ -49,13 +49,13 @@ def assert_property(name, value):
self.assertEqual(1, extensions_goal_state.extensions[3].settings[1].dependencyLevel, "Incorrect dependency level (multi-config)")

def test_it_should_parse_requested_version_properly(self):
with mock_wire_protocol(mockwiredata.DATA_FILE_VM_SETTINGS) as protocol:
with mock_wire_protocol(wire_protocol_data.DATA_FILE_VM_SETTINGS) as protocol:
goal_state = GoalState(protocol.client)
families = goal_state.extensions_goal_state.agent_families
for family in families:
self.assertEqual(family.requested_version_string, "0.0.0.0", "Version should be None")

data_file = mockwiredata.DATA_FILE_VM_SETTINGS.copy()
data_file = wire_protocol_data.DATA_FILE_VM_SETTINGS.copy()
data_file["vm_settings"] = "hostgaplugin/vm_settings-requested_version.json"
with mock_wire_protocol(data_file) as protocol:
protocol.mock_wire_data.set_etag(888)
Expand All @@ -65,7 +65,7 @@ def test_it_should_parse_requested_version_properly(self):
self.assertEqual(family.requested_version_string, "9.9.9.9", "Version should be 9.9.9.9")

def test_it_should_parse_missing_status_upload_blob_as_none(self):
data_file = mockwiredata.DATA_FILE_VM_SETTINGS.copy()
data_file = wire_protocol_data.DATA_FILE_VM_SETTINGS.copy()
data_file["vm_settings"] = "hostgaplugin/vm_settings-no_status_upload_blob.json"
with mock_wire_protocol(data_file) as protocol:
extensions_goal_state = protocol.get_goal_state().extensions_goal_state
Expand All @@ -74,15 +74,15 @@ def test_it_should_parse_missing_status_upload_blob_as_none(self):
self.assertEqual("BlockBlob", extensions_goal_state.status_upload_blob_type, "Expected status upload blob to be Block")

def test_it_should_parse_missing_agent_manifests_as_empty(self):
data_file = mockwiredata.DATA_FILE_VM_SETTINGS.copy()
data_file = wire_protocol_data.DATA_FILE_VM_SETTINGS.copy()
data_file["vm_settings"] = "hostgaplugin/vm_settings-no_manifests.json"
with mock_wire_protocol(data_file) as protocol:
extensions_goal_state = protocol.get_goal_state().extensions_goal_state
self.assertEqual(1, len(extensions_goal_state.agent_families), "Expected exactly one agent manifest. Got: {0}".format(extensions_goal_state.agent_families))
self.assertListEqual([], extensions_goal_state.agent_families[0].uris, "Expected an empty list of agent manifests")

def test_it_should_parse_missing_extension_manifests_as_empty(self):
data_file = mockwiredata.DATA_FILE_VM_SETTINGS.copy()
data_file = wire_protocol_data.DATA_FILE_VM_SETTINGS.copy()
data_file["vm_settings"] = "hostgaplugin/vm_settings-no_manifests.json"
with mock_wire_protocol(data_file) as protocol:
extensions_goal_state = protocol.get_goal_state().extensions_goal_state
Expand All @@ -98,15 +98,15 @@ def test_it_should_parse_missing_extension_manifests_as_empty(self):
extensions_goal_state.extensions[2].manifest_uris, "Incorrect list of manifests for {0}".format(extensions_goal_state.extensions[2]))

def test_it_should_default_to_block_blob_when_the_status_blob_type_is_not_valid(self):
data_file = mockwiredata.DATA_FILE_VM_SETTINGS.copy()
data_file = wire_protocol_data.DATA_FILE_VM_SETTINGS.copy()
data_file["vm_settings"] = "hostgaplugin/vm_settings-invalid_blob_type.json"
with mock_wire_protocol(data_file) as protocol:
extensions_goal_state = protocol.get_goal_state().extensions_goal_state

self.assertEqual("BlockBlob", extensions_goal_state.status_upload_blob_type, 'Expected BlockBlob for an invalid statusBlobType')

def test_its_source_channel_should_be_host_ga_plugin(self):
with mock_wire_protocol(mockwiredata.DATA_FILE_VM_SETTINGS) as protocol:
with mock_wire_protocol(wire_protocol_data.DATA_FILE_VM_SETTINGS) as protocol:
extensions_goal_state = protocol.get_goal_state().extensions_goal_state

self.assertEqual(GoalStateChannel.HostGAPlugin, extensions_goal_state.channel, "The channel is incorrect")
Expand Down
Loading

0 comments on commit 4a1d3de

Please sign in to comment.