def test_should_get_interconnects_by_interconnect_name(self):
        self.resource.data = MOCK_INTERCONNECTS[0]
        self.resource.get_by_name.return_value = self.resource

        self.mock_ansible_module.params = PARAMS_FOR_GET_BY_NAME

        InterconnectFactsModule().run()

        self.resource.get_by_name.assert_called_once_with(INTERCONNECT_NAME)

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=False,
            ansible_facts=dict(interconnects=MOCK_INTERCONNECTS))
    def test_should_get_all_interconnects(self):
        fake_interconnects = [dict(uidState='On', name=INTERCONNECT_NAME)]
        self.resource.get_all.return_value = fake_interconnects

        self.mock_ansible_module.params = PARAMS_FOR_GET_ALL

        InterconnectFactsModule().run()

        self.resource.get_all.assert_called_once_with()

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=False,
            ansible_facts=dict(interconnects=fake_interconnects))
    def test_should_get_pluggable_module_information(self):
        fake_sfp_info = [dict(t=1), dict(t=2)]
        self.resource.data = MOCK_INTERCONNECTS[0]
        self.resource.get_by_name.return_value = self.resource
        self.resource.get_pluggable_module_information.return_value = fake_sfp_info

        self.mock_ansible_module.params = PARAMS_PLUGGABLE_MODULE

        InterconnectFactsModule().run()

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=False,
            ansible_facts=dict(
                interconnects=MOCK_INTERCONNECTS,
                interconnect_pluggable_module_information=fake_sfp_info))
    def test_should_get_interconnect_ports(self, testing_module):
        fake_ports = [dict(t=1), dict(t=2)]
        self.resource.data = MOCK_INTERCONNECTS[0]
        self.resource.get_by_name.return_value = self.resource
        self.resource.get_ports.return_value = fake_ports

        self.mock_ansible_module.params = PARAMS_FOR_GET_PORTS

        InterconnectFactsModule().run()

        self.resource.get_by_name.assert_called_once_with(INTERCONNECT_NAME)
        self.resource.get_ports.assert_called_once()

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=False,
            ansible_facts=dict(interconnects=MOCK_INTERCONNECTS,
                               interconnect_ports=fake_ports))
    def test_should_gather_facts_about_interconnect_subport_statistics(self):
        fake_statistics = dict(name='test')
        self.resource.data = MOCK_INTERCONNECTS[0]
        self.resource.get_by_name.return_value = self.resource
        self.resource.get_subport_statistics.return_value = fake_statistics

        self.mock_ansible_module.params = PARAMS_FOR_SUBPORT_STATISTICS

        InterconnectFactsModule().run()

        self.resource.get_subport_statistics.assert_called_once_with(
            PORT_NAME, SUBPORT_NUMBER)

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=False,
            ansible_facts=dict(
                interconnects=MOCK_INTERCONNECTS,
                interconnect_subport_statistics=fake_statistics))
    def test_should_get_interconnect_statistics_by_interconnect_name(self):
        self.resource.data = MOCK_INTERCONNECTS[0]
        self.resource.get_by_name.return_value = self.resource

        fake_statistics = dict()
        self.resource.get_statistics.return_value = fake_statistics

        self.mock_ansible_module.params = PARAMS

        InterconnectFactsModule().run()

        self.resource.get_statistics.assert_called_once()

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=False,
            ansible_facts=dict(
                interconnects=MOCK_INTERCONNECTS,
                interconnect_statistics=fake_statistics,
            ))
    def test_should_get_interconnect_port_using_id(self, testing_module):
        fake_port = dict(t=1)
        port_id = "53fa7d35-1cc8-46c1-abf0-6af091a1aed3:d1"
        self.resource.data = MOCK_INTERCONNECTS_ID[0]
        self.resource.get_by_name.return_value = self.resource

        self.resource.get_by_name.return_value = self.resource
        self.resource.get_port.return_value = fake_port

        self.mock_ansible_module.params = PARAMS_FOR_GET_PORT

        InterconnectFactsModule().run()

        self.resource.get_by_name.assert_called_once_with(INTERCONNECT_NAME)
        self.resource.get_port.assert_called_once_with(port_id)

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=False,
            ansible_facts=dict(interconnects=MOCK_INTERCONNECTS_ID,
                               interconnect_port=fake_port))