def setUp(self):
     self.helper = ModuleHelper()
class ModuleHelperTestCase(unittest.TestCase):
    def setUp(self):
        self.helper = ModuleHelper()

    @mock.patch.object(ModuleHelper, 'get_response')
    @mock.patch.object(AnsibleModule, 'exit_json')
    @mock.patch.object(KongConsumer, 'add')
    @mock.patch.object(ModuleHelper, 'get_module')
    @mock.patch.object(ModuleHelper, 'prepare_inputs')
    def test_main_add(self, mock_prepare_inputs, mock_module, mock_add,
                      mock_exit_json, mock_get_response):

        mock_prepare_inputs.return_value = (mock_kong_admin_url, "1",
                                            "joesoap", "present", None, None)
        mock_get_response.return_value = (True, requests.Response())
        main()

        assert mock_add.called

    @mock.patch.object(ModuleHelper, 'get_response')
    @mock.patch.object(AnsibleModule, 'exit_json')
    @mock.patch.object(KongConsumer, 'delete')
    @mock.patch.object(ModuleHelper, 'get_module')
    @mock.patch.object(ModuleHelper, 'prepare_inputs')
    def test_main_delete(self, mock_prepare_inputs, mock_module, mock_delete,
                         mock_exit_json, mock_get_response):

        mock_prepare_inputs.return_value = (mock_kong_admin_url, "1",
                                            "joesoap", "absent", None, None)
        mock_get_response.return_value = (True, requests.Response())
        main()

        assert mock_delete.called

    @mock.patch.object(ModuleHelper, 'get_response')
    @mock.patch.object(AnsibleModule, 'exit_json')
    @mock.patch.object(KongConsumer, 'list')
    @mock.patch.object(ModuleHelper, 'get_module')
    @mock.patch.object(ModuleHelper, 'prepare_inputs')
    def test_main_list(self, mock_prepare_inputs, mock_module, mock_list,
                       mock_exit_json, mock_get_response):

        mock_prepare_inputs.return_value = (mock_kong_admin_url, "1",
                                            "joesoap", "list", None, None)
        mock_get_response.return_value = (True, requests.Response())
        main()

        assert mock_list.called

    @mock.patch.object(ModuleHelper, 'get_response')
    @mock.patch.object(AnsibleModule, 'exit_json')
    @mock.patch.object(KongConsumer, 'configure_for_plugin')
    @mock.patch.object(ModuleHelper, 'get_module')
    @mock.patch.object(ModuleHelper, 'prepare_inputs')
    def test_main_list(self, mock_prepare_inputs, mock_module,
                       mock_configure_for_plugin, mock_exit_json,
                       mock_get_response):

        mock_prepare_inputs.return_value = (mock_kong_admin_url, "1",
                                            "joesoap", "configure", "auth-key",
                                            {
                                                "key": "123"
                                            })
        mock_get_response.return_value = (True, requests.Response())
        main()

        assert mock_configure_for_plugin.called

        expected_call = call('1', 'auth-key', {'key': '123'})
        assert mock_configure_for_plugin.call_args_list[0] == expected_call

    def test_prepare_inputs(self):
        class MockModule:
            pass

        mock_module = MockModule()
        mock_module.params = {
            'kong_admin_uri': mock_kong_admin_url,
            'state': 'present',
            'username': '******',
        }
        url, username, id, state, api_name, data = self.helper.prepare_inputs(
            mock_module)

        assert url == mock_kong_admin_url
        assert state == 'present'
        assert username == 'joesoap'
        assert id == None
        assert data is None
예제 #3
0
class ModuleHelperTestCase(unittest.TestCase):

	def setUp(self):
		self.helper = ModuleHelper()

	@mock.patch.object(ModuleHelper, 'get_response')
	@mock.patch.object(AnsibleModule, 'exit_json')
	@mock.patch.object(KongConsumer, 'add')
	@mock.patch.object(ModuleHelper, 'get_module')
	@mock.patch.object(ModuleHelper, 'prepare_inputs')
	def test_main_add(self, mock_prepare_inputs, mock_module, mock_add, mock_exit_json, mock_get_response):

		mock_prepare_inputs.return_value = (mock_kong_admin_url, "1","joesoap", "present", None, None)
		mock_get_response.return_value = (True, requests.Response())
		main()

		assert mock_add.called		

	@mock.patch.object(ModuleHelper, 'get_response')
	@mock.patch.object(AnsibleModule, 'exit_json')
	@mock.patch.object(KongConsumer, 'delete')
	@mock.patch.object(ModuleHelper, 'get_module')
	@mock.patch.object(ModuleHelper, 'prepare_inputs')
	def test_main_delete(self, mock_prepare_inputs, mock_module, mock_delete, mock_exit_json, mock_get_response):

		mock_prepare_inputs.return_value = (mock_kong_admin_url, "1","joesoap", "absent", None, None)
		mock_get_response.return_value = (True, requests.Response())
		main()

		assert mock_delete.called		
	
	@mock.patch.object(ModuleHelper, 'get_response')
	@mock.patch.object(AnsibleModule, 'exit_json')
	@mock.patch.object(KongConsumer, 'list')
	@mock.patch.object(ModuleHelper, 'get_module')
	@mock.patch.object(ModuleHelper, 'prepare_inputs')
	def test_main_list(self, mock_prepare_inputs, mock_module, mock_list, mock_exit_json, mock_get_response):

		mock_prepare_inputs.return_value = (mock_kong_admin_url, "1","joesoap", "list", None, None)
		mock_get_response.return_value = (True, requests.Response())
		main()

		assert mock_list.called			

	@mock.patch.object(ModuleHelper, 'get_response')
	@mock.patch.object(AnsibleModule, 'exit_json')
	@mock.patch.object(KongConsumer, 'configure_for_plugin')
	@mock.patch.object(ModuleHelper, 'get_module')
	@mock.patch.object(ModuleHelper, 'prepare_inputs')
	def test_main_list(self, mock_prepare_inputs, mock_module, mock_configure_for_plugin, mock_exit_json, mock_get_response):

		mock_prepare_inputs.return_value = (mock_kong_admin_url, "1","joesoap", "configure", "auth-key", {"key": "123"})
		mock_get_response.return_value = (True, requests.Response())
		main()

		assert mock_configure_for_plugin.called				

		expected_call = call('1', 'auth-key', {'key': '123'})
		assert mock_configure_for_plugin.call_args_list[0] == expected_call


	def test_prepare_inputs(self):
		class MockModule:
			pass

		mock_module = MockModule()
		mock_module.params = {
			'kong_admin_uri': mock_kong_admin_url,
			'state': 'present',
			'username': '******',
		}
		url, username, id, state, api_name, data = self.helper.prepare_inputs(mock_module)

		assert url == mock_kong_admin_url
		assert state == 'present'
		assert username == 'joesoap'
		assert id == None
		assert data is None
예제 #4
0
	def setUp(self):
		self.helper = ModuleHelper()
class ModuleHelperTestCase(unittest.TestCase):

	def setUp(self):
		self.helper = ModuleHelper()

	@mock.patch.object(ModuleHelper, 'get_response')
	@mock.patch.object(AnsibleModule, 'exit_json')
	@mock.patch.object(KongConsumer, 'add')
	@mock.patch.object(ModuleHelper, 'get_module')
	@mock.patch.object(ModuleHelper, 'prepare_inputs')
	def test_main_add(self, mock_prepare_inputs, mock_module, mock_add, mock_exit_json, mock_get_response):

		mock_prepare_inputs.return_value = (mock_kong_admin_url, "1","joesoap", "present")
		mock_get_response.return_value = (True, requests.Response())
		main()

		assert mock_add.called		

	@mock.patch.object(ModuleHelper, 'get_response')
	@mock.patch.object(AnsibleModule, 'exit_json')
	@mock.patch.object(KongConsumer, 'delete')
	@mock.patch.object(ModuleHelper, 'get_module')
	@mock.patch.object(ModuleHelper, 'prepare_inputs')
	def test_main_delete(self, mock_prepare_inputs, mock_module, mock_delete, mock_exit_json, mock_get_response):

		mock_prepare_inputs.return_value = (mock_kong_admin_url, "1","joesoap", "absent")
		mock_get_response.return_value = (True, requests.Response())
		main()

		assert mock_delete.called		
	
	@mock.patch.object(ModuleHelper, 'get_response')
	@mock.patch.object(AnsibleModule, 'exit_json')
	@mock.patch.object(KongConsumer, 'list')
	@mock.patch.object(ModuleHelper, 'get_module')
	@mock.patch.object(ModuleHelper, 'prepare_inputs')
	def test_main_list(self, mock_prepare_inputs, mock_module, mock_list, mock_exit_json, mock_get_response):

		mock_prepare_inputs.return_value = (mock_kong_admin_url, "1","joesoap", "list")
		mock_get_response.return_value = (True, requests.Response())
		main()

		assert mock_list.called				


	def test_prepare_inputs(self):
		class MockModule:
			pass

		mock_module = MockModule()
		mock_module.params = {
			'kong_admin_uri': mock_kong_admin_url,
			'state': 'present',
			'username': '******',
		}
		url, username, id, state = self.helper.prepare_inputs(mock_module)

		assert url == mock_kong_admin_url
		assert state == 'present'
		assert username == 'joesoap'
		assert id == None