Пример #1
0
    def test_should_get_fc_network_by_name(self):
        self.fc_networks.get_by.return_value = PRESENT_NETWORKS
        self.mock_ansible_module.params = PARAMS_GET_BY_NAME

        FcNetworkFactsModule().run()

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=False,
            ansible_facts=dict(fc_networks=(PRESENT_NETWORKS))
        )
Пример #2
0
    def test_should_load_config_from_file(self, mock_ansible_module,
                                          mock_ov_client_from_env_vars,
                                          mock_ov_client_from_json_file):
        mock_ov_instance = mock.Mock()
        mock_ov_client_from_json_file.return_value = mock_ov_instance
        mock_ansible_instance = create_ansible_mock(PARAMS_GET_ALL)
        mock_ansible_module.return_value = mock_ansible_instance

        FcNetworkFactsModule()

        mock_ov_client_from_json_file.assert_called_once_with('config.json')
        mock_ov_client_from_env_vars.not_been_called()
Пример #3
0
    def test_should_fail_when_get_all_raises_exception(
            self, mock_ansible_module, mock_ov_client_from_json_file):
        mock_ov_instance = mock.Mock()
        mock_ov_instance.fc_networks.get_all.side_effect = Exception(ERROR_MSG)

        mock_ov_client_from_json_file.return_value = mock_ov_instance

        mock_ansible_instance = create_ansible_mock(PARAMS_GET_ALL)
        mock_ansible_module.return_value = mock_ansible_instance

        FcNetworkFactsModule().run()

        mock_ansible_instance.fail_json.assert_called_once()
Пример #4
0
    def test_should_get_all_fc_networks(self, mock_ansible_module,
                                        mock_ov_client_from_json_file):
        mock_ov_instance = mock.Mock()
        mock_ov_instance.fc_networks.get_all.return_value = PRESENT_NETWORKS

        mock_ov_client_from_json_file.return_value = mock_ov_instance

        mock_ansible_instance = create_ansible_mock(PARAMS_GET_ALL)
        mock_ansible_module.return_value = mock_ansible_instance

        FcNetworkFactsModule().run()

        mock_ansible_instance.exit_json.assert_called_once_with(
            changed=False, ansible_facts=dict(fc_networks=(PRESENT_NETWORKS)))
Пример #5
0
    def test_should_load_config_from_environment(
            self, mock_ansible_module, mock_ov_client_from_env_vars,
            mock_ov_client_from_json_file):
        mock_ov_instance = mock.Mock()

        params_with_no_config = PARAMS_GET_ALL.copy()
        params_with_no_config['config'] = None

        mock_ov_client_from_env_vars.return_value = mock_ov_instance
        mock_ansible_instance = create_ansible_mock(params_with_no_config)
        mock_ansible_module.return_value = mock_ansible_instance

        FcNetworkFactsModule()

        mock_ov_client_from_env_vars.assert_called_once()
        mock_ov_client_from_json_file.not_been_called()