From 06abff80643756319d54449f0a3ce61b65362dbb Mon Sep 17 00:00:00 2001 From: shivamcandela Date: Fri, 25 Jun 2021 23:19:20 +0530 Subject: [PATCH] uci api test cases Signed-off-by: shivamcandela --- libs/controller/ucentral_ctlr.py | 28 +++++++++--------- tests/configuration.py | 6 ++-- .../ucentral_gateway/__init__.py | 0 .../ucentral_gateway/test_authentication.py | 29 +++++++++++++++++++ .../ucentral_gateway/test_commands.py | 0 .../ucentral_gateway/test_devices.py | 0 6 files changed, 47 insertions(+), 16 deletions(-) create mode 100644 tests/controller_tests/ucentral_gateway/__init__.py create mode 100644 tests/controller_tests/ucentral_gateway/test_authentication.py create mode 100644 tests/controller_tests/ucentral_gateway/test_commands.py create mode 100644 tests/controller_tests/ucentral_gateway/test_devices.py diff --git a/libs/controller/ucentral_ctlr.py b/libs/controller/ucentral_ctlr.py index 06c293668..146d084bc 100644 --- a/libs/controller/ucentral_ctlr.py +++ b/libs/controller/ucentral_ctlr.py @@ -20,7 +20,7 @@ class ConfigureController: self.password = controller_data["password"] self.host = urlparse(controller_data["url"]) self.access_token = "" - self.login() + self.login_resp = self.login() def build_uri(self, path): new_uri = 'https://%s:%d/api/v1/%s' % (self.host.hostname, self.host.port, path) @@ -34,6 +34,7 @@ class ConfigureController: self.check_response("POST", resp, "", payload, uri) token = resp.json() self.access_token = token["access_token"] + return resp def logout(self): global access_token @@ -41,6 +42,7 @@ class ConfigureController: resp = requests.delete(uri, headers=self.make_headers(), verify=False) self.check_response("DELETE", resp, self.make_headers(), "", uri) print('Logged out:', resp.status_code) + return resp def make_headers(self): headers = {'Authorization': 'Bearer %s' % self.access_token} @@ -390,8 +392,8 @@ class UProfileUtility: # } # controller = { - 'url': "https://tip-f34.candelatech.com:16001/api/v1/oauth2", # API base url for the controller - # 'url': 'https://restapi-ucentral-2.cicd.lab.wlan.tip.build/api/v1/oauth2', + # 'url': "https://tip-f34.candelatech.com:16001/api/v1/oauth2", # API base url for the controller + 'url': 'https://sdk-ucentral-2.cicd.lab.wlan.tip.build:16001/api/v1/oauth2', 'username': "tip@ucentral.com", 'password': 'openwifi', # 'version': "1.1.0-SNAPSHOT", @@ -408,19 +410,19 @@ profile_data = { "radius": False } obj = UController(controller_data=controller) -print(obj.get_devices()) +# print(obj.get_devices()) +# print(obj.get_device_uuid(serial_number="903cb3944873")) # obj.get_device_uuid(serial_number="c4411ef53f23") -# obj.get_device_uuid(serial_number="c4411ef53f23") -profile_client = UProfileUtility(sdk_client=obj) -profile_client.set_radio_config() -profile_client.set_mode(mode="VLAN") -ssid_data = {"ssid_name": "ssid_wpa_test_3", "vlan": 200, "appliedRadios": ["2G", "5G"], "security_key": "something", "security": "none"} -profile_client.add_ssid(ssid_data=ssid_data) -print(profile_client.base_profile_config) -profile_client.push_config(serial_number="c4411ef53f23") +# profile_client = UProfileUtility(sdk_client=obj) +# profile_client.set_radio_config() +# profile_client.set_mode(mode="VLAN") +# ssid_data = {"ssid_name": "ssid_wpa_test_3_vlan", "vlan": 100, "appliedRadios": ["2G", "5G"], "security_key": "something", "security": "none"} +# profile_client.add_ssid(ssid_data=ssid_data) +# print(profile_client.base_profile_config) +# profile_client.push_config(serial_number="903cb3944873") # print(profile_client.base_profile_config) # equipments = obj.get_devices() -# # print(equipments) +# print(equipments) # for i in equipments: # for j in equipments[i]: # for k in j: diff --git a/tests/configuration.py b/tests/configuration.py index 29a3f8840..9ed3f5a00 100644 --- a/tests/configuration.py +++ b/tests/configuration.py @@ -174,18 +174,18 @@ CONFIGURATION = { 'mode': 'wifi5', 'serial': 'c4411ef53f23', 'jumphost': True, - 'ip': "192.168.100.164", # localhost + 'ip': "192.168.52.100", # localhost 'username': "lanforge", 'password': "lanforge", 'port': 22, # 22, - 'jumphost_tty': '/dev/ttyUSB0', + 'jumphost_tty': '/dev/ttyAP1', 'version': "https://tip.jfrog.io/artifactory/tip-wlan-ap-firmware/ecw5410/trunk/ecw5410-1.1.0.tar.gz" } ], "traffic_generator": { "name": "lanforge", "details": { - "ip": "192.168.100.209", # localhost, + "ip": "192.168.52.100", # localhost, "port": 8080, # 8802, "ssh_port": 22, "2.4G-Radio": ["wiphy4"], diff --git a/tests/controller_tests/ucentral_gateway/__init__.py b/tests/controller_tests/ucentral_gateway/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/controller_tests/ucentral_gateway/test_authentication.py b/tests/controller_tests/ucentral_gateway/test_authentication.py new file mode 100644 index 000000000..f13427c54 --- /dev/null +++ b/tests/controller_tests/ucentral_gateway/test_authentication.py @@ -0,0 +1,29 @@ +""" + + UCI Rest API Tests: Test Login, Logout API's + +""" +import pytest + + +class TestUCIAUTHDEAUTH(object): + """ + pytest -m "uci_login or uci_logout" --ucentral + """ + + @pytest.mark.uci_login + def test_uci_auth(self, setup_controller): + """ + pytest -m "uci_login" --ucentral + """ + print(setup_controller.login_resp) + assert setup_controller.login_resp.status_code == 200 + + @pytest.mark.uci_logout + def test_uci_deauth(self, setup_controller): + """ + pytest -m "uci_logout" --ucentral + """ + resp = setup_controller.logout() + print(resp) + assert resp.status_code == 200 diff --git a/tests/controller_tests/ucentral_gateway/test_commands.py b/tests/controller_tests/ucentral_gateway/test_commands.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/controller_tests/ucentral_gateway/test_devices.py b/tests/controller_tests/ucentral_gateway/test_devices.py new file mode 100644 index 000000000..e69de29bb