mirror of
https://github.com/valitydev/salt.git
synced 2024-11-07 17:09:03 +00:00
Actually testing parted
called_once_with didn't work, changed to assert_called_once_with
This commit is contained in:
parent
1bee2a2d89
commit
70e4062cf9
@ -73,37 +73,33 @@ class PartedTestCase(TestCase):
|
||||
|
||||
def test_probe_wo_args(self):
|
||||
parted.probe()
|
||||
self.cmdrun.called_once_with(
|
||||
['partprobe'], python_shell=False)
|
||||
self.cmdrun.assert_called_once_with('partprobe -- ')
|
||||
|
||||
def test_probe_w_single_arg(self):
|
||||
parted.probe("/dev/sda")
|
||||
self.cmdrun.called_once_with(
|
||||
['partprobe', '/dev/sda'], python_shell=False)
|
||||
self.cmdrun.assert_called_once_with('partprobe -- /dev/sda')
|
||||
|
||||
def test_probe_w_multiple_args(self):
|
||||
parted.probe('/dev/sda', '/dev/sdb')
|
||||
self.cmdrun.called_once_with(
|
||||
['partprobe', '/dev/sda', '/dev/sdb'], python_shell=False)
|
||||
self.cmdrun.assert_called_once_with('partprobe -- /dev/sda /dev/sdb')
|
||||
|
||||
@patch('salt.utils.kwargs_warn_until')
|
||||
def test_probe_w_device_kwarg(self, *args, **kwargs):
|
||||
parted.probe(device="/dev/sda")
|
||||
parted.salt.utils.kwargs_warn_until.called_once_with({'device': '/dev/sda'})
|
||||
self.cmdrun.called_once_with(['partprobe', '/dev/sda'], python_shell=False)
|
||||
parted.salt.utils.kwargs_warn_until({'device': '/dev/sda'})
|
||||
self.cmdrun.assert_called_once_with('partprobe -- /dev/sda')
|
||||
|
||||
@patch('salt.utils.kwargs_warn_until')
|
||||
def test_probe_w_device_kwarg_and_arg(self, *args, **kwargs):
|
||||
'''device arg is concatanated with possitional args'''
|
||||
parted.probe("/dev/sdb", device="/dev/sda")
|
||||
parted.salt.utils.kwargs_warn_until.called_once_with({'device': '/dev/sda'})
|
||||
self.cmdrun.called_once_with(
|
||||
['partprobe', '/dev/sda', '/dev/sdb'], python_shell=False)
|
||||
parted.salt.utils.kwargs_warn_until({'device': '/dev/sda'})
|
||||
self.cmdrun.assert_called_once_with('partprobe -- /dev/sda /dev/sdb')
|
||||
|
||||
@patch('salt.utils.kwargs_warn_until')
|
||||
def test_probe_w_extra_kwarg(self, *args, **kwargs):
|
||||
self.assertRaises(TypeError, parted.probe, foo="bar")
|
||||
parted.salt.utils.kwargs_warn_until.called_once_with({'device': '/dev/sda'})
|
||||
parted.salt.utils.kwargs_warn_until({'device': '/dev/sda'})
|
||||
self.assertFalse(self.cmdrun.called)
|
||||
|
||||
# Test part_list function
|
||||
@ -113,12 +109,11 @@ class PartedTestCase(TestCase):
|
||||
def test_part_list(self, *args, **kwargs):
|
||||
'''Function should call new function and raise deprecation warning'''
|
||||
parted.part_list("foo", "bar")
|
||||
parted.list_.called_once_with("foo", "bar")
|
||||
parted.salt.utils.warn_until.called_once_with(
|
||||
parted.list_.assert_called_once_with("foo", "bar")
|
||||
parted.salt.utils.warn_until.assert_called_once_with(
|
||||
'Beryllium',
|
||||
'''The \'part_list\' function has been deprecated in favor of
|
||||
\'list\'. Please update your code and configs to reflect
|
||||
this.''')
|
||||
\'list_\'. Please update your code and configs to reflect this.''')
|
||||
|
||||
# Test _list function
|
||||
|
||||
@ -165,28 +160,14 @@ class PartedTestCase(TestCase):
|
||||
def test_list__empty_cmd_output(self):
|
||||
self.cmdrun.return_value = self.parted_print_output('empty')
|
||||
output = parted.list_('/dev/sda')
|
||||
self.cmdrun.called_once_with(
|
||||
['parted',
|
||||
'-m',
|
||||
'-s',
|
||||
'/dev/sda'
|
||||
'print']
|
||||
)
|
||||
self.cmdrun.assert_called_once_with('parted -m -s /dev/sda print')
|
||||
expected = {'info': {}, 'partitions': {}}
|
||||
self.assertEqual(output, expected)
|
||||
|
||||
def test_list__valid_unit_empty_cmd_output(self):
|
||||
self.cmdrun.return_value = self.parted_print_output('empty')
|
||||
output = parted.list_('/dev/sda', unit='s')
|
||||
self.cmdrun.called_once_with(
|
||||
['parted',
|
||||
'-m',
|
||||
'-s',
|
||||
'/dev/sda'
|
||||
'unit',
|
||||
's',
|
||||
'print']
|
||||
)
|
||||
self.cmdrun.assert_called_once_with('parted -m -s /dev/sda unit s print')
|
||||
expected = {'info': {}, 'partitions': {}}
|
||||
self.assertEqual(output, expected)
|
||||
|
||||
@ -198,46 +179,22 @@ class PartedTestCase(TestCase):
|
||||
def test_list__bad_header(self):
|
||||
self.cmdrun.return_value = self.parted_print_output('bad_header')
|
||||
self.assertRaises(CommandExecutionError, parted.list_, '/dev/sda')
|
||||
self.cmdrun.called_once_with(
|
||||
['parted',
|
||||
'-m',
|
||||
'-s',
|
||||
'/dev/sda'
|
||||
'print']
|
||||
)
|
||||
self.cmdrun.assert_called_once_with('parted -m -s /dev/sda print')
|
||||
|
||||
def test_list__bad_label_info(self):
|
||||
self.cmdrun.return_value = self.parted_print_output('bad_label_info')
|
||||
self.assertRaises(CommandExecutionError, parted.list_, '/dev/sda')
|
||||
self.cmdrun.called_once_with(
|
||||
['parted',
|
||||
'-m',
|
||||
'-s',
|
||||
'/dev/sda'
|
||||
'print']
|
||||
)
|
||||
self.cmdrun.assert_called_once_with('parted -m -s /dev/sda print')
|
||||
|
||||
def test_list__bad_partition(self):
|
||||
self.cmdrun.return_value = self.parted_print_output('bad_partition')
|
||||
self.assertRaises(CommandExecutionError, parted.list_, '/dev/sda')
|
||||
self.cmdrun.called_once_with(
|
||||
['parted',
|
||||
'-m',
|
||||
'-s',
|
||||
'/dev/sda'
|
||||
'print']
|
||||
)
|
||||
self.cmdrun.assert_called_once_with('parted -m -s /dev/sda print')
|
||||
|
||||
def test_list__valid_cmd_output(self):
|
||||
self.cmdrun.return_value = self.parted_print_output('valid')
|
||||
output = parted.list_('/dev/sda')
|
||||
self.cmdrun.called_once_with(
|
||||
['parted',
|
||||
'-m',
|
||||
'-s',
|
||||
'/dev/sda'
|
||||
'print']
|
||||
)
|
||||
self.cmdrun.assert_called_once_with('parted -m -s /dev/sda print')
|
||||
expected = {
|
||||
'info': {
|
||||
'logical sector': '512',
|
||||
@ -274,15 +231,7 @@ class PartedTestCase(TestCase):
|
||||
def test_list__valid_unit_valid_cmd_output(self):
|
||||
self.cmdrun.return_value = self.parted_print_output('valid')
|
||||
output = parted.list_('/dev/sda', unit='s')
|
||||
self.cmdrun.called_once_with(
|
||||
['parted',
|
||||
'-m',
|
||||
'-s',
|
||||
'/dev/sda'
|
||||
'unit',
|
||||
's',
|
||||
'print']
|
||||
)
|
||||
self.cmdrun.assert_called_once_with('parted -m -s /dev/sda unit s print')
|
||||
expected = {
|
||||
'info': {
|
||||
'logical sector': '512',
|
||||
@ -319,13 +268,7 @@ class PartedTestCase(TestCase):
|
||||
def test_list__valid_legacy_cmd_output(self):
|
||||
self.cmdrun.return_value = self.parted_print_output('valid_legacy')
|
||||
output = parted.list_('/dev/sda')
|
||||
self.cmdrun.called_once_with(
|
||||
['parted',
|
||||
'-m',
|
||||
'-s',
|
||||
'/dev/sda'
|
||||
'print']
|
||||
)
|
||||
self.cmdrun.assert_called_once_with('parted -m -s /dev/sda print')
|
||||
expected = {
|
||||
'info': {
|
||||
'logical sector': '512',
|
||||
@ -361,15 +304,7 @@ class PartedTestCase(TestCase):
|
||||
def test_list__valid_unit_valid_legacy_cmd_output(self):
|
||||
self.cmdrun.return_value = self.parted_print_output('valid_legacy')
|
||||
output = parted.list_('/dev/sda', unit='s')
|
||||
self.cmdrun.called_once_with(
|
||||
['parted',
|
||||
'-m',
|
||||
'-s',
|
||||
'/dev/sda'
|
||||
'unit',
|
||||
's',
|
||||
'print']
|
||||
)
|
||||
self.cmdrun.assert_called_once_with('parted -m -s /dev/sda unit s print')
|
||||
expected = {
|
||||
'info': {
|
||||
'logical sector': '512',
|
||||
|
Loading…
Reference in New Issue
Block a user