def test_if_supports_extended_but_there_are_no_flags_then_none_should_be_returned( self, ): fname = "/path/to/fnord" with_extended = ( textwrap.dedent( """ ------------------- {} """ ) .strip() .format(fname) ) expected = set("") patch_has_ext = patch( "hubblestack.modules.file._chattr_has_extended_attrs", Mock(return_value=True), ) patch_run = patch.dict( filemod.__mods__, {"cmd.run": Mock(return_value=with_extended)}, ) with patch_has_ext, patch_run: actual = set(filemod.lsattr(fname)[fname]) msg = "Actual: {!r} Expected: {!r}".format( actual, expected ) # pylint: disable=E1322 assert actual == expected, msg
def test_on_aix_lsattr_should_be_None(self): patch_aix = patch("hubblestack.utils.platform.is_aix", Mock(return_value=True),) with patch_aix: # SaltInvocationError will be raised if filemod.lsattr # doesn't early exit actual = filemod.lsattr("foo") self.assertIsNone(actual)
def test_if_chattr_version_is_less_than_required_flags_should_ignore_extended(self): fname = "/path/to/fnord" with_extended = ( textwrap.dedent( """ aAcCdDeijPsStTu---- {} """ ) .strip() .format(fname) ) expected = set("acdijstuADST") patch_has_ext = patch( "hubblestack.modules.file._chattr_has_extended_attrs", Mock(return_value=False), ) patch_run = patch.dict( filemod.__mods__, {"cmd.run": Mock(return_value=with_extended)}, ) with patch_has_ext, patch_run: actual = set(filemod.lsattr(fname)[fname]) msg = "Actual: {!r} Expected: {!r}".format( actual, expected ) # pylint: disable=E1322 assert actual == expected, msg
def test_SaltInvocationError_should_be_raised_when_file_is_missing(self): patch_exists = patch("os.path.exists", Mock(return_value=False),) with patch_exists, self.assertRaises(HubbleInvocationError): filemod.lsattr("foo")
def test_if_lsattr_is_missing_it_should_return_None(self): patch_which = patch("hubblestack.utils.path.which", Mock(return_value=None),) with patch_which: actual = filemod.lsattr("foo") assert actual is None, actual