def test_absent(self): ''' Test to remove a entry or entries from a chain ''' name = 'salt' entry = ['192.168.0.3', '192.168.1.3'] ret = {'name': name, 'result': False, 'comment': '', 'changes': {}} mock = MagicMock(side_effect=[True, False, False]) with patch.dict(ipset.__salt__, {'ipset.check': mock}): comt = ('ipset entry must be specified') ret.update({'comment': comt}) self.assertDictEqual(ipset.absent(name), ret) with patch.dict(ipset.__opts__, {'test': True}): comt = ('ipset entry 192.168.0.3 needs to removed ' 'from set salt for family ipv4\n') ret.update({'comment': comt, 'result': None}) self.assertDictEqual(ipset.absent(name, entry, set_name='salt'), ret) comt = ('ipset entry for 192.168.0.3 not present in set (salt) for ' 'ipv4\nipset entry for 192.168.1.3 not present in set ' '(salt) for ipv4\n') ret.update({'comment': comt, 'result': True}) self.assertDictEqual(ipset.absent(name, entry, set_name='salt'), ret)
def _runner( self, expected_ret, test=False, check=False, delete=False, delete_assertion=False, ): mock_check = MagicMock(return_value=check) mock_delete = MagicMock(return_value=delete) with patch.dict(ipset.__opts__, {"test": test}): with patch.dict(ipset.__salt__, { "ipset.check": mock_check, "ipset.delete": mock_delete }): actual_ret = ipset.absent(self.fake_name, self.fake_entries, set_name=self.fake_name) mock_check.assert_has_calls( [call(self.fake_name, e, "ipv4") for e in self.fake_entries], any_order=True) if delete_assertion: expected_calls = [ call(self.fake_name, e, "ipv4", set_name=self.fake_name) for e in self.fake_entries ] if delete is not True: expected_calls = expected_calls[:1] mock_delete.assert_has_calls(expected_calls, any_order=True) else: self.assertTrue(mock_delete.call_count == 0) self.assertDictEqual(actual_ret, expected_ret)
def test_absent(self): ret = {'name': self.fake_name, 'result': False, 'comment': 'ipset entry must be specified', 'changes': {}} mock = MagicMock(return_value=True) with patch.dict(ipset.__salt__, {'ipset.check': mock}): self.assertDictEqual(ipset.absent(self.fake_name), ret)
def test_absent(self): ret = { "name": self.fake_name, "result": False, "comment": "ipset entry must be specified", "changes": {}, } mock = MagicMock(return_value=True) with patch.dict(ipset.__salt__, {"ipset.check": mock}): self.assertDictEqual(ipset.absent(self.fake_name), ret)
def _runner(self, expected_ret, test=False, check=False, delete=False, delete_assertion=False): mock_check = MagicMock(return_value=check) mock_delete = MagicMock(return_value=delete) with patch.dict(ipset.__opts__, {'test': test}): with patch.dict(ipset.__salt__, {'ipset.check': mock_check, 'ipset.delete': mock_delete}): actual_ret = ipset.absent(self.fake_name, self.fake_entries, set_name=self.fake_name) mock_check.assert_has_calls([call(self.fake_name, e, 'ipv4') for e in self.fake_entries], any_order=True) if delete_assertion: expected_calls = [call(self.fake_name, e, 'ipv4', set_name=self.fake_name) for e in self.fake_entries] if delete is not True: expected_calls = expected_calls[:1] mock_delete.assert_has_calls(expected_calls, any_order=True) else: mock_delete.assert_not_called() self.assertDictEqual(actual_ret, expected_ret)