<commit_before>#!/usr/bin/python
# -*- coding: utf-8 -*-
###
# Copyright (2016-2017) Hewlett Packard Enterprise Development LP
#
# Licensed under the Apache License, Version 2.0 (the "License");
# You may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
###

import unittest
from oneview_module_loader import StorageSystemFactsModule
from hpe_test_utils import FactsParamsTestCase

ERROR_MSG = 'Fake message error'

PARAMS_GET_ALL = dict(
    config='config.json',
    name=None
)

PARAMS_GET_BY_NAME = dict(
    config='config.json',
    name="Test Storage Systems"
)

PARAMS_GET_BY_IP_HOSTNAME = dict(
    config='config.json',
    ip_hostname='10.0.0.0'
)

PARAMS_GET_BY_HOSTNAME = dict(
    config='config.json',
    hostname='10.0.0.0'
)

PARAMS_GET_HOST_TYPES = dict(
    config='config.json',
    options=["hostTypes"]

)

HOST_TYPES = [
    "Citrix Xen Server 5.x/6.x",
    "IBM VIO Server",
]

PARAMS_GET_POOL_BY_NAME = dict(
    config='config.json',
    name="Test Storage Systems",
    options=["storagePools"]
)

PARAMS_GET_POOL_BY_IP_HOSTNAME = dict(
    config='config.json',
    ip_hostname='10.0.0.0',
    options=["storagePools"]
)


class StorageSystemFactsSpec(unittest.TestCase,
                             FactsParamsTestCase):
    def setUp(self):
        self.configure_mocks(self, StorageSystemFactsModule)
        self.storage_systems = self.mock_ov_client.storage_systems
        self.mock_ov_client.api_version = 300
        FactsParamsTestCase.configure_client_mock(self, self.storage_systems)

    def test_should_get_all_storage_system(self):
        self.storage_systems.get_all.return_value = {"name": "Storage System Name"}
        self.mock_ansible_module.params = PARAMS_GET_ALL

        StorageSystemFactsModule().run()

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=False,
            ansible_facts=dict(storage_systems=({"name": "Storage System Name"}))
        )

    def test_should_get_storage_system_by_name(self):
        self.storage_systems.get_by_name.return_value = {"name": "Storage System Name"}
        self.mock_ansible_module.params = PARAMS_GET_BY_NAME

        StorageSystemFactsModule().run()

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=False,
            ansible_facts=dict(storage_systems=({"name": "Storage System Name"}))
        )

    def test_should_get_storage_system_by_ip_hostname(self):
        self.storage_systems.get_by_ip_hostname.return_value = {"ip_hostname": "10.0.0.0"}
        self.mock_ansible_module.params = PARAMS_GET_BY_IP_HOSTNAME

        StorageSystemFactsModule().run()

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=False,
            ansible_facts=dict(storage_systems=({"ip_hostname": "10.0.0.0"}))
        )

    def test_should_get_storage_system_by_hostname(self):
        self.mock_ov_client.api_version = 500
        self.storage_systems.get_by_hostname.return_value = {"hostname": "10.0.0.0"}
        self.mock_ansible_module.params = PARAMS_GET_BY_HOSTNAME

        StorageSystemFactsModule().run()

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=False,
            ansible_facts=dict(storage_systems=({"hostname": "10.0.0.0"}))
        )

    def test_should_get_all_host_types(self):
        self.storage_systems.get_host_types.return_value = HOST_TYPES
        self.storage_systems.get_all.return_value = [{"name": "Storage System Name"}]
        self.mock_ansible_module.params = PARAMS_GET_HOST_TYPES

        StorageSystemFactsModule().run()

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=False,
            ansible_facts=dict(
                storage_system_host_types=HOST_TYPES,
                storage_systems=[{"name": "Storage System Name"}])
        )

    def test_should_get_storage_pools_system_by_name(self):
        self.storage_systems.get_by_name.return_value = {"name": "Storage System Name", "uri": "uri"}
        self.storage_systems.get_storage_pools.return_value = {"name": "Storage Pool"}
        self.mock_ansible_module.params = PARAMS_GET_POOL_BY_NAME

        StorageSystemFactsModule().run()

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=False,
            ansible_facts=dict(
                storage_system_pools=({"name": "Storage Pool"}),
                storage_systems={"name": "Storage System Name", "uri": "uri"}
            )
        )

    def test_should_get_storage_system_pools_by_ip_hostname(self):
        self.storage_systems.get_by_ip_hostname.return_value = {"ip_hostname": "10.0.0.0", "uri": "uri"}<commit_msg>Adds fact unit tests to Storage System<commit_after>#!/usr/bin/python
# -*- coding: utf-8 -*-
###
# Copyright (2016-2017) <NAME> Development LP
#
# Licensed under the Apache License, Version 2.0 (the "License");
# You may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
###

import unittest
from oneview_module_loader import StorageSystemFactsModule
from hpe_test_utils import FactsParamsTestCase

ERROR_MSG = 'Fake message error'

PARAMS_GET_ALL = dict(
    config='config.json',
    name=None
)

PARAMS_GET_BY_NAME = dict(
    config='config.json',
    name="Test Storage Systems"
)

PARAMS_GET_BY_IP_HOSTNAME = dict(
    config='config.json',
    ip_hostname='10.0.0.0'
)

PARAMS_GET_BY_HOSTNAME = dict(
    config='config.json',
    hostname='10.0.0.0'
)

PARAMS_GET_HOST_TYPES = dict(
    config='config.json',
    options=["hostTypes"]
)

PARAMS_GET_REACHABLE_PORTS = dict(
    config='config.json',
    hostname='10.0.0.0',
    options=["reachablePorts"]
)

PARAMS_GET_TEMPLATES = dict(
    config='config.json',
    hostname='10.0.0.0',
    options=["templates"]
)

HOST_TYPES = [
    "Citrix Xen Server 5.x/6.x",
    "IBM VIO Server",
]

PARAMS_GET_POOL_BY_NAME = dict(
    config='config.json',
    name="Test Storage Systems",
    options=["storagePools"]
)

PARAMS_GET_POOL_BY_IP_HOSTNAME = dict(
    config='config.json',
    ip_hostname='10.0.0.0',
    options=["storagePools"]
)


class StorageSystemFactsSpec(unittest.TestCase,
                             FactsParamsTestCase):
    def setUp(self):
        self.configure_mocks(self, StorageSystemFactsModule)
        self.storage_systems = self.mock_ov_client.storage_systems
        self.mock_ov_client.api_version = 300
        FactsParamsTestCase.configure_client_mock(self, self.storage_systems)

    def test_should_get_all_storage_system(self):
        self.storage_systems.get_all.return_value = {"name": "Storage System Name"}
        self.mock_ansible_module.params = PARAMS_GET_ALL

        StorageSystemFactsModule().run()

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=False,
            ansible_facts=dict(storage_systems=({"name": "Storage System Name"}))
        )

    def test_should_get_storage_system_by_name(self):
        self.storage_systems.get_by_name.return_value = {"name": "Storage System Name"}
        self.mock_ansible_module.params = PARAMS_GET_BY_NAME

        StorageSystemFactsModule().run()

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=False,
            ansible_facts=dict(storage_systems=({"name": "Storage System Name"}))
        )

    def test_should_get_storage_system_by_ip_hostname(self):
        self.storage_systems.get_by_ip_hostname.return_value = {"ip_hostname": "10.0.0.0"}
        self.mock_ansible_module.params = PARAMS_GET_BY_IP_HOSTNAME

        StorageSystemFactsModule().run()

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=False,
            ansible_facts=dict(storage_systems=({"ip_hostname": "10.0.0.0"}))
        )

    def test_should_get_storage_system_by_hostname(self):
        self.mock_ov_client.api_version = 500
        self.storage_systems.get_by_hostname.return_value = {"hostname": "10.0.0.0"}
        self.mock_ansible_module.params = PARAMS_GET_BY_HOSTNAME

        StorageSystemFactsModule().run()

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=False,
            ansible_facts=dict(storage_systems=({"hostname": "10.0.0.0"}))
        )

    def test_should_get_all_host_types(self):
        self.storage_systems.get_host_types.return_value = HOST_TYPES
        self.storage_systems.get_all.return_value = [{"name": "Storage System Name"}]
        self.mock_ansible_module.params = PARAMS_GET_HOST_TYPES

        StorageSystemFactsModule().run()

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=False,
            ansible_facts=dict(
                storage_system_host_types=HOST_TYPES,
                storage_systems=[{"name": "Storage System Name"}])
        )

    def test_should_get_reachable_ports(self):
        self.mock_ov_client.api_version = 500
        self.storage_systems.get_reachable_ports.return_value = [{'port': 'port1'}]
        self.storage_systems.get_by_hostname.return_value = {"name": "Storage System Name", "uri": "rest/123"}
        self.mock_ansible_module.params = PARAMS_GET_REACHABLE_PORTS

        StorageSystemFactsModule().run()

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=False,
            ansible_facts=dict(
                storage_system_reachable_ports=[{'port': 'port1'}],
                storage_systems={"name": "Storage System Name", "uri": "rest/123"})
        )

    def test_should_get_templates(self):
        self.mock_ov_client.api_version = 500
        self.storage_systems.get_templates.return_value = [{'template': 'temp'}]
        self.storage_systems.get_by_hostname.return_value = {"name": "Storage System Name", "uri": "rest/123"}
        self.mock_ansible_module.params = PARAMS_GET_TEMPLATES

        StorageSystemFactsModule().run()

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=False,
            ansible_facts=dict(
                storage_system_templates=[{'template': 'temp'}],
                storage_systems={"name": "Storage System Name", "uri": "rest/123"})
        )

    def test_should_get_storage_pools_system_by_name(self):
        self.storage_systems.get_by_name.return_value = {"name": "Storage System Name", "uri": "uri"}
        self.storage_systems.get_storage_pools.return_value = {"name": "Storage Pool"}
        self.mock_ansible_module.params = PARAMS_GET_POOL_BY_NAME

        StorageSystemFactsModule().run()

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=False,
            ansible_facts=dict(
                storage_system_pools=({"name": "Storage Pool"}),
                storage_systems={"name": "Storage System Name", "uri": "uri"}
            )
        )

    def test_should_get_storage_system_pools_by_ip_hostname(self):
        self.storage_systems.get_by_ip_hostname.return_value = {"ip_hostname": "10.0.0.0", "uri": "uri"}
{'fraction_non_alphanumeric': 0.10671169269734065, 'fraction_numerical': 0.012832418742085268, 'mean_word_length': 3.4135618479880776, 'pattern_counts': {'":': 44, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 18, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5205066', 'n_tokens_mistral': 3908, 'n_tokens_neox': 3740, 'n_words': 609}