コード例 #1
0
    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'],
        )
コード例 #2
0
    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'],
        )
コード例 #3
0
    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'],
        )
コード例 #4
0
    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'],
        )
コード例 #5
0
    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,
        )
コード例 #6
0
    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)
コード例 #7
0
ファイル: tests.py プロジェクト: cptBuggy/ansible-cloudflare
    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'],
        )
コード例 #8
0
ファイル: tests.py プロジェクト: cptBuggy/ansible-cloudflare
    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)