Exemple #1
0
    def test_add(self):
        """
        Test for Append an entry to the specified set.
        """
        self.assertEqual(ipset.add(), "Error: Set needs to be specified")

        self.assertEqual(ipset.add("set"),
                         "Error: Entry needs to be specified")

        with patch.object(ipset, "_find_set_info", return_value=None):
            self.assertEqual(ipset.add("set", "entry"),
                             "Error: Set set does not exist")

        mock = MagicMock(return_value={"Type": "type", "Header": "Header"})
        with patch.object(ipset, "_find_set_info", mock):
            self.assertEqual(
                ipset.add("set", "entry", timeout=0),
                "Error: Set set not created with timeout support",
            )

            self.assertEqual(
                ipset.add("set", "entry", packets=0),
                "Error: Set set not created with \
counters support",
            )

            self.assertEqual(
                ipset.add("set", "entry", comment=0),
                "Error: Set set not created with \
comment support",
            )

        mock = MagicMock(return_value={
            "Type": "bitmap:ip",
            "Header": "Header"
        })
        with patch.object(ipset, "_find_set_info", mock):
            with patch.object(ipset, "_find_set_members",
                              return_value="entry"):
                self.assertEqual(
                    ipset.add("set", "entry"),
                    "Warn: Entry entry already exists in set set",
                )

            with patch.object(ipset, "_find_set_members", return_value="A"):
                mock = MagicMock(return_value="")
                with patch.dict(ipset.__salt__, {"cmd.run": mock}):
                    self.assertEqual(ipset.add("set", "entry"), "Success")

                mock = MagicMock(return_value="out")
                with patch.dict(ipset.__salt__, {"cmd.run": mock}):
                    self.assertEqual(ipset.add("set", "entry"), "Error: out")
Exemple #2
0
    def test_add(self):
        '''
        Test for Append an entry to the specified set.
        '''
        self.assertEqual(ipset.add(), 'Error: Set needs to be specified')

        self.assertEqual(ipset.add('set'),
                         'Error: Entry needs to be specified')

        with patch.object(ipset, '_find_set_info', return_value=None):
            self.assertEqual(ipset.add('set', 'entry'),
                             'Error: Set set does not exist')

        mock = MagicMock(return_value={'Type': 'type', 'Header': 'Header'})
        with patch.object(ipset, '_find_set_info', mock):
            self.assertEqual(
                ipset.add('set', 'entry', timeout=0),
                'Error: Set set not created with timeout support')

            self.assertEqual(
                ipset.add('set', 'entry', packets=0),
                'Error: Set set not created with \
counters support')

            self.assertEqual(
                ipset.add('set', 'entry', comment=0),
                'Error: Set set not created with \
comment support')

        mock = MagicMock(return_value={
            'Type': 'bitmap:ip',
            'Header': 'Header'
        })
        with patch.object(ipset, '_find_set_info', mock):
            with patch.object(ipset, '_find_set_members',
                              return_value='entry'):
                self.assertEqual(
                    ipset.add('set', 'entry'),
                    'Warn: Entry entry already exists in set set')

            with patch.object(ipset, '_find_set_members', return_value='A'):
                mock = MagicMock(return_value='')
                with patch.dict(ipset.__salt__, {'cmd.run': mock}):
                    self.assertEqual(ipset.add('set', 'entry'), 'Success')

                mock = MagicMock(return_value='out')
                with patch.dict(ipset.__salt__, {'cmd.run': mock}):
                    self.assertEqual(ipset.add('set', 'entry'), 'Error: out')
Exemple #3
0
    def test_add(self):
        '''
        Test for Append an entry to the specified set.
        '''
        self.assertEqual(ipset.add(), 'Error: Set needs to be specified')

        self.assertEqual(ipset.add('set'),
                         'Error: Entry needs to be specified')

        with patch.object(ipset, '_find_set_info', return_value=None):
            self.assertEqual(ipset.add('set', 'entry'),
                             'Error: Set set does not exist')

        mock = MagicMock(return_value={'Type': 'type',
                                       'Header': 'Header'})
        with patch.object(ipset, '_find_set_info', mock):
            self.assertEqual(ipset.add('set', 'entry', timeout=0),
                             'Error: Set set not created with timeout support')

            self.assertEqual(ipset.add('set', 'entry', packets=0),
                             'Error: Set set not created with \
counters support')

            self.assertEqual(ipset.add('set', 'entry', comment=0),
                             'Error: Set set not created with \
comment support')

        mock = MagicMock(return_value={'Type': 'bitmap:ip',
                                       'Header': 'Header'})
        with patch.object(ipset, '_find_set_info', mock):
            with patch.object(ipset, '_find_set_members', return_value='entry'):
                self.assertEqual(ipset.add('set', 'entry'),
                                 'Warn: Entry entry already exists in set set')

            with patch.object(ipset, '_find_set_members', return_value='A'):
                mock = MagicMock(return_value='')
                with patch.dict(ipset.__salt__, {'cmd.run': mock}):
                    self.assertEqual(ipset.add('set', 'entry'), 'Success')

                mock = MagicMock(return_value='out')
                with patch.dict(ipset.__salt__, {'cmd.run': mock}):
                    self.assertEqual(ipset.add('set', 'entry'), 'Error: out')