def test_revoke_security_group_failed(self): with mock.patch('requests.post', self.mockRequestsPostRevokeSecurityGroup): with mock.patch('niftycloud_fw.describe_security_group', self.mockDescribeSecurityGroup): with self.assertRaises(Exception) as cm: niftycloud_fw.revoke_security_group( self.mockModule, self.result['present'], self.security_group_info ) self.assertEqual(cm.exception.message, 'failed')
def test_revoke_security_group_success(self): security_group_info = dict( copy.deepcopy(self.security_group_info), ip_permissions = list( self.security_group_info['ip_permissions'] + self.mockModule.params['ip_permissions'], ), ) changed_security_group_info = dict( copy.deepcopy(self.security_group_info), ip_permissions = self.mockModule.params['ip_permissions'], ) mock_describe_security_group = mock.MagicMock( return_value=( self.result['present'], changed_security_group_info, )) with mock.patch('requests.post', self.mockRequestsPostRevokeSecurityGroup): with mock.patch('niftycloud_fw.describe_security_group', mock_describe_security_group): (result, info) = niftycloud_fw.revoke_security_group( self.mockModule, self.result['present'], security_group_info ) self.assertEqual(result, dict( created = False, changed_attributes = dict( number_of_revoke_rules = len(self.security_group_info['ip_permissions']), ), state = 'present', )) self.assertEqual(info, changed_security_group_info)
def test_revoke_security_group_request_failed(self): with mock.patch('requests.post', self.mockRequestsInternalServerError): with self.assertRaises(Exception) as cm: (result, info) = niftycloud_fw.revoke_security_group( self.mockModule, self.result['present'], self.security_group_info ) self.assertEqual(cm.exception.message, 'failed')
def test_revoke_security_group_absent(self): (result, info) = niftycloud_fw.revoke_security_group( self.mockModule, self.result['absent'], None ) self.assertEqual(result, self.result['absent']) self.assertIsNone(info)
def test_revoke_security_group_skip(self): security_group_info = dict( copy.deepcopy(self.security_group_info), ip_permissions = self.mockModule.params['ip_permissions'], ) (result, info) = niftycloud_fw.revoke_security_group( self.mockModule, self.result['present'], security_group_info ) self.assertEqual(result, self.result['present']) self.assertEqual(info, security_group_info)
def test_revoke_security_group_purge_skip(self): security_group_info = dict( copy.deepcopy(self.security_group_info), ip_permissions = self.mockModule.params['ip_permissions'], ) mock_ip_permissions_removed = self.mockModule mock_ip_permissions_removed.params['ip_permissions'] = [] mock_ip_permissions_removed.params['purge_ip_permissions'] = False (result, info) = niftycloud_fw.revoke_security_group( mock_ip_permissions_removed, self.result['present'], security_group_info ) self.assertEqual(result, self.result['present']) self.assertEqual(info, security_group_info)