def test_create_new_record(self, mock_cloudflare_cls): mock_cloudflare_cls.return_value = self.mock_cloudflare_instance mock_module = self.get_mock_module( zone='example.com', name='home', state='present', type='A', content='127.0.0.1' ) # Perform the actual tests. with self.assertRaises(ModuleExit): cloudflare_domain(mock_module) # Call rec_load_all to determine whether we're creating a new entry or # editing an existing one. self.assertTrue(self.mock_cloudflare_instance.rec_load_all.called) # Since we're creating a new record, assert that rec_new() was called. self.mock_cloudflare_instance.rec_new.assert_called_once_with( mock_module.params['type'], mock_module.params['name'], mock_module.params['content'], ) # Make sure that the module reported that changes were made. mock_module.exit_json.assert_called_once_with( changed=True, type=mock_module.params['type'], name=mock_module.params['name'], content=mock_module.params['content'], )
def test_remove_star_content(self, mock_cloudflare_cls): mock_cloudflare_cls.return_value = self.mock_cloudflare_instance mock_module = self.get_mock_module(zone='example.com', name='www', state='absent', type='A', content='*') # Perform the actual tests. with self.assertRaises(ModuleExit): cloudflare_domain(mock_module) # Call rec_load_all to determine whether we're creating a new entry or # editing an existing one. self.assertTrue(self.mock_cloudflare_instance.rec_load_all.called) self.assertFalse(self.mock_cloudflare_instance.rec_new.called) self.assertFalse(self.mock_cloudflare_instance.rec_edit.called) self.assertEquals(self.mock_cloudflare_instance.rec_delete.call_count, 2) self.mock_cloudflare_instance.rec_delete.assert_any_call("16606009") self.mock_cloudflare_instance.rec_delete.assert_any_call("16606010") # Make sure that the module reported that no changes were made. mock_module.exit_json.assert_called_once_with( changed=True, type=mock_module.params['type'], name=mock_module.params['name'], content=mock_module.params['content'], )
def test_existing_record_idempotency(self, mock_cloudflare_cls): mock_cloudflare_cls.return_value = self.mock_cloudflare_instance mock_module = self.get_mock_module( zone='example.com', name='www', state='present', type='A', content='127.0.0.1' ) # Perform the actual tests. with self.assertRaises(ModuleExit): cloudflare_domain(mock_module) # Call rec_load_all to determine whether we're creating a new entry or # editing an existing one. self.assertTrue(self.mock_cloudflare_instance.rec_load_all.called) # Make sure that we're never calling rec_new or rec_edit, since no # changes have been made. self.assertFalse(self.mock_cloudflare_instance.rec_new.called) self.assertFalse(self.mock_cloudflare_instance.rec_edit.called) # Make sure that the module reported that no changes were made. mock_module.exit_json.assert_called_once_with( changed=False, type=mock_module.params['type'], name=mock_module.params['name'], content=mock_module.params['content'], )
def test_remove_non_existing_record(self, mock_cloudflare_cls): mock_cloudflare_cls.return_value = self.mock_cloudflare_instance mock_module = self.get_mock_module(zone='example.com', name='foo', state='absent', type='A', content='127.0.0.1') # Perform the actual tests. with self.assertRaises(ModuleExit): cloudflare_domain(mock_module) # Call rec_load_all to determine whether we're creating a new entry or # editing an existing one. self.assertTrue(self.mock_cloudflare_instance.rec_load_all.called) # Make sure that we're never calling rec_new, rec_edit, or rec_delete # since no changes have been made. self.assertFalse(self.mock_cloudflare_instance.rec_new.called) self.assertFalse(self.mock_cloudflare_instance.rec_edit.called) self.assertFalse(self.mock_cloudflare_instance.rec_delete.called) # Make sure that the module reported that no changes were made. mock_module.exit_json.assert_called_once_with( changed=False, type=mock_module.params['type'], name=mock_module.params['name'], content=mock_module.params['content'], )
def test_create_new_record(self, mock_cloudflare_cls): mock_cloudflare_cls.return_value = self.mock_cloudflare_instance mock_module = self.get_mock_module(zone='example.com', name='home', state='present', type='A', content='127.0.0.1') # Perform the actual tests. with self.assertRaises(ModuleExit): cloudflare_domain(mock_module) # Call rec_load_all to determine whether we're creating a new entry or # editing an existing one. self.assertTrue(self.mock_cloudflare_instance.rec_load_all.called) # Since we're creating a new record, assert that rec_new() was called. self.mock_cloudflare_instance.rec_new.assert_called_once_with( mock_module.params['type'], mock_module.params['name'], mock_module.params['content'], mode=None) # Make sure that the module reported that changes were made. mock_module.exit_json.assert_called_once_with( changed=True, type=mock_module.params['type'], name=mock_module.params['name'], content=mock_module.params['content'], service_mode=None, )
def test_create_star_content(self, mock_cloudflare_cls): mock_cloudflare_cls.return_value = self.mock_cloudflare_instance mock_module = self.get_mock_module(zone='example.com', name='www', state='present', type='A', content='*') # Perform the actual tests. with self.assertRaises(ModuleFail): cloudflare_domain(mock_module) # Call rec_load_all to determine whether we're creating a new entry or # editing an existing one. self.assertTrue(self.mock_cloudflare_instance.rec_load_all.called) self.assertFalse(self.mock_cloudflare_instance.rec_new.called) self.assertFalse(self.mock_cloudflare_instance.rec_edit.called) self.assertFalse(self.mock_cloudflare_instance.rec_delete.called) # Make sure that the module failed self.assertTrue(mock_module.fail_json.called)
def test_remove_star_content(self, mock_cloudflare_cls): mock_cloudflare_cls.return_value = self.mock_cloudflare_instance mock_module = self.get_mock_module( zone='example.com', name='www', state='absent', type='A', content='*' ) # Perform the actual tests. with self.assertRaises(ModuleExit): cloudflare_domain(mock_module) # Call rec_load_all to determine whether we're creating a new entry or # editing an existing one. self.assertTrue(self.mock_cloudflare_instance.rec_load_all.called) self.assertFalse(self.mock_cloudflare_instance.rec_new.called) self.assertFalse(self.mock_cloudflare_instance.rec_edit.called) self.assertEquals( self.mock_cloudflare_instance.rec_delete.call_count, 2 ) self.mock_cloudflare_instance.rec_delete.assert_any_call( "16606009" ) self.mock_cloudflare_instance.rec_delete.assert_any_call( "16606010" ) # Make sure that the module reported that no changes were made. mock_module.exit_json.assert_called_once_with( changed=True, type=mock_module.params['type'], name=mock_module.params['name'], content=mock_module.params['content'], )
def test_create_star_content(self, mock_cloudflare_cls): mock_cloudflare_cls.return_value = self.mock_cloudflare_instance mock_module = self.get_mock_module( zone='example.com', name='www', state='present', type='A', content='*' ) # Perform the actual tests. with self.assertRaises(ModuleFail): cloudflare_domain(mock_module) # Call rec_load_all to determine whether we're creating a new entry or # editing an existing one. self.assertTrue(self.mock_cloudflare_instance.rec_load_all.called) self.assertFalse(self.mock_cloudflare_instance.rec_new.called) self.assertFalse(self.mock_cloudflare_instance.rec_edit.called) self.assertFalse(self.mock_cloudflare_instance.rec_delete.called) # Make sure that the module failed self.assertTrue(mock_module.fail_json.called)