diff options
author | Scott Moser <smoser@brickies.net> | 2017-06-15 16:39:50 -0400 |
---|---|---|
committer | Scott Moser <smoser@brickies.net> | 2017-06-15 17:02:01 -0400 |
commit | 9ccb8f5e2ab262ee04bb9c103c1302479f7c81d3 (patch) | |
tree | 9f3f74137c89ed4a652322bdaf1b71192b57632a /tests | |
parent | ea0a534d93544837e44d03e3394233d28c247f7d (diff) | |
download | vyos-cloud-init-9ccb8f5e2ab262ee04bb9c103c1302479f7c81d3.tar.gz vyos-cloud-init-9ccb8f5e2ab262ee04bb9c103c1302479f7c81d3.zip |
FreeBSD: fix test failure
The previous commit caused test failure.
This separates out _check_freebsd_cdrom and mocks it in a test
rather than patching open.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/unittests/test_datasource/test_azure.py | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/tests/unittests/test_datasource/test_azure.py b/tests/unittests/test_datasource/test_azure.py index 114b1a5d..7d33daf7 100644 --- a/tests/unittests/test_datasource/test_azure.py +++ b/tests/unittests/test_datasource/test_azure.py @@ -7,8 +7,7 @@ from cloudinit.util import find_freebsd_part from cloudinit.util import get_path_dev_freebsd from ..helpers import (CiTestCase, TestCase, populate_dir, mock, - ExitStack, PY26, PY3, SkipTest) -from mock import patch, mock_open + ExitStack, PY26, SkipTest) import crypt import os @@ -544,14 +543,16 @@ fdescfs /dev/fd fdescfs rw 0 0 ds.get_data() self.assertEqual(self.instance_id, ds.metadata['instance-id']) - def test_list_possible_azure_ds_devs(self): - devlist = [] - with patch('platform.platform', - mock.MagicMock(return_value="FreeBSD")): - name = 'builtins.open' if PY3 else '__builtin__.open' - with patch(name, mock_open(read_data="data")): - devlist.extend(dsaz.list_possible_azure_ds_devs()) - self.assertEqual(devlist, ['/dev/cd0']) + @mock.patch("cloudinit.sources.DataSourceAzure.util.is_FreeBSD") + @mock.patch("cloudinit.sources.DataSourceAzure._check_freebsd_cdrom") + def test_list_possible_azure_ds_devs(self, m_check_fbsd_cdrom, + m_is_FreeBSD): + """On FreeBSD, possible devs should show /dev/cd0.""" + m_is_FreeBSD.return_value = True + m_check_fbsd_cdrom.return_value = True + self.assertEqual(dsaz.list_possible_azure_ds_devs(), ['/dev/cd0']) + self.assertEqual( + [mock.call("/dev/cd0")], m_check_fbsd_cdrom.call_args_list) class TestAzureBounce(TestCase): |