<filename>tests/cli/v1_3_0/test_non_fabric_wireless.py
# -*- coding: utf-8 -*-
"""DNACenterAPI Non-Fabric Wireless API fixtures and tests.

Copyright (c) 2019 Cisco and/or its affiliates.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
"""

import click
import pytest
from json import loads
from tests.environment import DNA_CENTER_VERSION


pytestmark = pytest.mark.skipif(DNA_CENTER_VERSION != '1.3.0', reason='version does not match')


def is_valid_provision(result):
    data = result.output.strip()
    return True if data else False


@pytest.mark.non_fabric_wireless
def test_provision(runner, cli, auth_options):
    result = runner.invoke(cli, ['-v', '1.3.0', *auth_options,
                                 'non-fabric-wireless', 'provision',
                                 """--active_validation=True""",
                                 """--payload='{"deviceName": "string", "site": "string", "managedAPLocations": ["string"], "dynamicInterfaces": [{"interfaceIPAddress": "string", "interfaceNetmaskInCIDR": 0, "interfaceGateway": "string", "lagOrPortNumber": 0, "vlanId": 0, "interfaceName": "string"}]}'"""])
    assert not result.exception
    assert is_valid_provision(result)


def is_valid_update_wireless_profile(result):
    data = result.output.strip()
    return True if data else False


@pytest.mark.non_fabric_wireless
def test_update_wireless_profile(runner, cli, auth_options):
    result = runner.invoke(cli, ['-v', '1.3.0', *auth_options,
                                 'non-fabric-wireless', 'update-wireless-profile',
                                 """--active_validation=True""",
                                 """--payload=None""",
                                 """--profiledetails='{"name": "string", "sites": ["string"], "ssidDetails": [{"name": "string", "type": "Guest", "enableFabric": true, "flexConnect": {"enableFlexConnect": true, "localToVlan": 0}, "interfaceName": "string"}]}'"""])
    assert not result.exception
    assert is_valid_update_wireless_profile(result)


def is_valid_get_wireless_profile(result):
    data = result.output.strip()
    return True if data else False


@pytest.mark.non_fabric_wireless
def test_get_wireless_profile(runner, cli, auth_options):
    result = runner.invoke(cli, ['-v', '1.3.0', *auth_options,
                                 'non-fabric-wireless', 'get-wireless-profile',
                                 """--profile_name='string'"""])
    assert not result.exception
    assert is_valid_get_wireless_profile(result)


def is_valid_update_provision(result):
    data = result.output.strip()
    return True if data else False


@pytest.mark.non_fabric_wireless
def test_update_provision(runner, cli, auth_options):
    result = runner.invoke(cli, ['-v', '1.3.0', *auth_options,
                                 'non-fabric-wireless', 'update-provision',
                                 """--active_validation=True""",
                                 """--payload='{"deviceName": "string", "managedAPLocations": ["string"], "dynamicInterfaces": [{"interfaceIPAddress": "string", "interfaceNetmaskInCIDR": 0, "interfaceGateway": "string", "lagOrPortNumber": 0, "vlanId": 0, "interfaceName": "string"}]}'"""])
    assert not result.exception
    assert is_valid_update_provision(result)


def is_valid_delete_wireless_profile(result):
    data = result.output.strip()
    return True if data else False


@pytest.mark.non_fabric_wireless
def test_delete_wireless_profile(runner, cli, auth_options):
    result = runner.invoke(cli, ['-v', '1.3.0', *auth_options,
                                 'non-fabric-wireless', 'delete-wireless-profile',
                                 """--wireless_profile_name='string'"""])
    assert not result.exception
    assert is_valid_delete_wireless_profile(result)


def is_valid_create_wireless_profile(result):
    data = result.output.strip()
    return True if data else False


@pytest.mark.non_fabric_wireless
def test_create_wireless_profile(runner, cli, auth_options):
    result = runner.invoke(cli, ['-v', '1.3.0', *auth_options,
                                 'non-fabric-wireless', 'create-wireless-profile',
                                 """--active_validation=True""",
                                 """--payload=None""",
                                 """--profiledetails='{"name": "string", "sites": ["string"], "ssidDetails": [{"name": "string", "type": "Guest", "enableFabric": true, "flexConnect": {"enableFlexConnect": true, "localToVlan": 0}, "interfaceName": "string"}]}'"""])
    assert not result.exception
    assert is_valid_create_wireless_profile(result)


def is_valid_create_and_provision_ssid(result):
    data = result.output.strip()
    return True if data else False


@pytest.mark.non_fabric_wireless
def test_create_and_provision_ssid(runner, cli, auth_options):
    result = runner.invoke(cli, ['-v', '1.3.0', *auth_options,
                                 'non-fabric-wireless', 'create-and-provision-ssid',
                                 """--active_validation=True""",
                                 """--enablefabric=True""",
                                 """--flexconnect='{"enableFlexConnect": true, "localToVlan": 0}'""",
                                 """--managedaplocations='string'""",
                                 """--payload=None""",
                                 """--ssiddetails='{"name": "string", "securityLevel": "WPA2_ENTERPRISE", "enableFastLane": true, "passphrase": "<PASSWORD>", "trafficType": "data", "enableBroadcastSSID": true, "radioPolicy": "Dual band operation (2.4GHz and 5GHz)", "enableMACFiltering": true, "fastTransition": "Adaptive", "webAuthURL": "string"}'""",
                                 """--ssidtype='Guest'"""])
    assert not result.exception
    assert is_valid_create_and_provision_ssid(result)


def is_valid_delete_enterprise_ssid(result):
    data = result.output.strip()
    return True if data else False


@pytest.mark.non_fabric_wireless
def test_delete_enterprise_ssid(runner, cli, auth_options):
    result = runner.invoke(cli, ['-v', '1.3.0', *auth_options,
                                 'non-fabric-wireless', 'delete-enterprise-ssid',
                                 """--ssid_name='string'"""])
    assert not result.exception
    assert is_valid_delete_enterprise_ssid(result)


def is_valid_delete_and_provision_ssid(result):
    data = result.output.strip()
    return True if data else False


@pytest.mark.non_fabric_wireless
def test_delete_and_provision_ssid(runner, cli, auth_options):
    result = runner.invoke(cli, ['-v', '1.3.0', *auth_options,
                                 'non-fabric-wireless', 'delete-and-provision-ssid',
                                 """--managed_aplocations='string'""",
                                 """--ssid_name='string'"""])
    assert not result.exception
    assert is_valid_delete_and_provision_ssid(result)


def is_valid_get_enterprise_ssid(result):
    data = result.output.strip()
    return True if data else False


@pytest.mark.non_fabric_wireless
def test_get_enterprise_ssid(runner, cli, auth_options):
    result = runner.invoke(cli, ['-v', '1.3.0', *auth_options,
                                 'non-fabric-wireless', 'get-enterprise-ssid',
                                 """--ssid_name='string'"""])
    assert not result.exception
    assert is_valid_get_enterprise_ssid(result)


def is_valid_create_enterprise_ssid(result):
    data = result.output.strip()
    return True if data else False


@pytest.mark.non_fabric_wireless
def test_create_enterprise_ssid(runner, cli, auth_options):
    result = runner.invoke(cli, ['-v', '1.3.0', *auth_options,
                                 'non-fabric-wireless', 'create-enterprise-ssid',
                                 """--active_validation=True""",
                                 """--enablebroadcastssid=True""",
                                 """--enablefastlane=True""",
                                 """--enablemacfiltering=True""",
                                 """--fasttransition='Adaptive'""",
                                 """--name='********************************'""",
                                 """--passphrase='********'""",
                                 """--payload=None""",
                                 """--radiopolicy='Dual band operation (2.4GHz and 5GHz)'""",
                                 """--securitylevel='WPA2_ENTERPRISE'""",
                                 """--traffictype='voicedata'"""])
    assert not result.exception
    assert is_valid_create_enterprise_ssid(result)
