def test_get_subnet_details(self, subnet_module_mock):
        subnet_module_mock.module.params = self.subnet_args
        subnet_module_mock.groupnet_api.get_groupnet_subnet(self.subnet_name).to_dict \
            = MagicMock(return_value=MockSubnetApi.get_subnet_details(self.subnet_name))
        subnet_module_mock.perform_module_operation()

        assert (MockSubnetApi.get_subnet_details(
            self.subnet_name)['subnets'][0] == subnet_module_mock.module.
                exit_json.call_args[1]["subnet_details"])
        assert subnet_module_mock.module.exit_json.call_args[1][
            "changed"] is False
    def test_modify_subnet_invalid_sc_ip(self, subnet_module_mock):
        self.subnet_args.update({
            'subnet_params': {
                'gateway':
                'a.1.1.1',
                'vlan_id':
                None,
                'mtu':
                None,
                'vlan_enabled':
                None,
                'sc_service_addrs': [{
                    'start_range': 'a.1.1.1',
                    'end_range': '1.1.1.2'
                }],
                'sc_service_addrs_state':
                'add'
            }
        })

        subnet_module_mock.module.params = self.subnet_args
        subnet_module_mock.get_subnet_details \
            = MagicMock(return_value=MockSubnetApi.get_subnet_details(self.subnet_name)['subnets'][0])
        subnet_module_mock.groupnet_api.update_groupnet_subnet = MagicMock(
            return_value=None)
        subnet_module_mock.perform_module_operation()
        assert MockSubnetApi.get_invalid_sc_ip() in \
            subnet_module_mock.module.fail_json.call_args[1]['msg']
    def test_modify_subnet_add_sc_ips(self, subnet_module_mock):
        self.subnet_args.update({
            'netmask': '1.1.1.1',
            'gateway_priority': 1,
            'subnet_params': {
                'gateway':
                None,
                'vlan_id':
                None,
                'mtu':
                None,
                'vlan_enabled':
                False,
                'sc_service_addrs': [{
                    'start_range': '1.1.1.1',
                    'end_range': '1.1.1.2'
                }],
                'sc_service_addrs_state':
                'add'
            }
        })

        subnet_module_mock.module.params = self.subnet_args
        subnet_module_mock.get_subnet_details \
            = MagicMock(return_value=MockSubnetApi.get_subnet_details(self.subnet_name)['subnets'][0])
        subnet_module_mock.groupnet_api.update_groupnet_subnet = MagicMock(
            return_value=None)
        subnet_module_mock.perform_module_operation()

        assert subnet_module_mock.module.exit_json.call_args[1][
            "changed"] is True
        assert subnet_module_mock.module.exit_json.call_args[1][
            "modify_subnet"] is True
    def test_delete_subnet_throws_exception(self, subnet_module_mock):
        self.subnet_args.update({'state': 'absent'})
        subnet_module_mock.module.params = self.subnet_args
        subnet_module_mock.get_subnet_details \
            = MagicMock(return_value=MockSubnetApi.get_subnet_details(self.subnet_name)['subnets'][0])
        subnet_module_mock.groupnet_api.delete_groupnet_subnet \
            = MagicMock(side_effect=utils.ApiException)
        subnet_module_mock.perform_module_operation()

        assert MockSubnetApi.delete_subnet_ex_msg(self.subnet_name) in \
            subnet_module_mock.module.fail_json.call_args[1]['msg']
    def test_delete_subnet_details(self, subnet_module_mock):
        self.subnet_args.update({'state': 'absent'})
        subnet_module_mock.module.params = self.subnet_args
        subnet_module_mock.get_subnet_details \
            = MagicMock(return_value=MockSubnetApi.get_subnet_details(self.subnet_name)['subnets'][0])
        subnet_module_mock.groupnet_api.delete_groupnet_subnet = MagicMock(
            return_value=None)
        subnet_module_mock.perform_module_operation()

        assert subnet_module_mock.module.exit_json.call_args[1][
            "changed"] is True
        assert subnet_module_mock.module.exit_json.call_args[1][
            "delete_subnet"] is True