Ejemplo n.º 1
0
    def test_save(self):
        '''
        Test if it save the current in-memory rules to disk
        '''
        with patch.dict(nftables.__grains__, {'os_family': 'Debian'}):
            mock = MagicMock(return_value=False)
            with patch.dict(nftables.__salt__, {'cmd.run': mock}):
                with patch.object(salt.utils, 'fopen', MagicMock(mock_open())):
                    self.assertEqual(nftables.save(), '#! nft -f\n\n')

                with patch.object(salt.utils, 'fopen',
                                  MagicMock(side_effect=IOError)):
                    self.assertRaises(CommandExecutionError, nftables.save)
Ejemplo n.º 2
0
    def test_save(self):
        '''
        Test if it save the current in-memory rules to disk
        '''
        with patch.dict(nftables.__grains__, {'os_family': 'Debian'}):
            mock = MagicMock(return_value=False)
            with patch.dict(nftables.__salt__, {'cmd.run': mock}):
                with patch.object(salt.utils, 'fopen', MagicMock(mock_open())):
                    self.assertEqual(nftables.save(), '#! nft -f\n\n')

                with patch.object(salt.utils, 'fopen',
                                  MagicMock(side_effect=IOError)):
                    self.assertRaises(CommandExecutionError, nftables.save)
Ejemplo n.º 3
0
    def test_save(self):
        """
        Test if it save the current in-memory rules to disk
        """
        with patch.dict(nftables.__grains__, {"os_family": "Debian"}):
            mock = MagicMock(return_value=False)
            with patch.dict(nftables.__salt__, {"cmd.run": mock}):
                with patch.object(salt.utils.files, "fopen",
                                  MagicMock(mock_open())):
                    self.assertEqual(nftables.save(), "#! nft -f\n\n")

                with patch.object(salt.utils.files, "fopen",
                                  MagicMock(side_effect=IOError)):
                    self.assertRaises(CommandExecutionError, nftables.save)