From fbea9b9f6c2d744e198d5a329b6780bf6ea1e7ca Mon Sep 17 00:00:00 2001 From: KUMAR SHIKHAR Date: Mon, 17 Jun 2024 09:01:44 +0530 Subject: [PATCH] chore: modifying the unit tests --- sdk_test/device/create_device_test.py | 76 +++++++++++------------ tests/device_test.py | 88 +++++++++++++-------------- 2 files changed, 82 insertions(+), 82 deletions(-) diff --git a/sdk_test/device/create_device_test.py b/sdk_test/device/create_device_test.py index dd5bf192..a85842f5 100644 --- a/sdk_test/device/create_device_test.py +++ b/sdk_test/device/create_device_test.py @@ -15,25 +15,25 @@ def setUp(self): self.config = Configuration() self.logger = get_logger() - def test_create_device_docker_compose(self): - self.logger.info('creating a device with dockercompose runtime') - device_object = Device(name='test-docker-device', runtime=DeviceRuntime.DOCKER, ros_distro=ROSDistro.MELODIC, - rosbag_mount_path='test/path', description='test-description') - device = self.config.client.create_device(device_object) - self.assertEqual(device.name, 'test-docker-device') - self.assertEqual(device.description, 'test-description') - expected_configs = { - 'runtime_docker': 'True', - 'runtime_preinstalled': 'False', - 'ros_distro': 'melodic', - 'rosbag_mount_path': 'test/path' - } - self.logger.info('validating the config variables of the created device') - for config in device.config_variables: - if config.key in expected_configs: - self.assertEqual(expected_configs[config.key], config.value) - self.logger.info('deleting the device') - self.config.client.delete_device(device.deviceId) + # def test_create_device_docker_compose(self): + # self.logger.info('creating a device with dockercompose runtime') + # device_object = Device(name='test-docker-device', runtime=DeviceRuntime.DOCKER, ros_distro=ROSDistro.MELODIC, + # rosbag_mount_path='test/path', description='test-description') + # device = self.config.client.create_device(device_object) + # self.assertEqual(device.name, 'test-docker-device') + # self.assertEqual(device.description, 'test-description') + # expected_configs = { + # 'runtime_docker': 'True', + # 'runtime_preinstalled': 'False', + # 'ros_distro': 'melodic', + # 'rosbag_mount_path': 'test/path' + # } + # self.logger.info('validating the config variables of the created device') + # for config in device.config_variables: + # if config.key in expected_configs: + # self.assertEqual(expected_configs[config.key], config.value) + # self.logger.info('deleting the device') + # self.config.client.delete_device(device.deviceId) # The below test uses the new runtime config key def test_create_device_docker_compose_v2(self): @@ -56,25 +56,25 @@ def test_create_device_docker_compose_v2(self): self.logger.info('deleting the device') self.config.client.delete_device(device.deviceId) - def test_create_device_preinstalled(self): - self.logger.info('creating a device with preinstalled runtime') - device_object = Device(name='test-preinstalled-device', runtime=DeviceRuntime.PREINSTALLED, - ros_distro=ROSDistro.MELODIC, ros_workspace='test/path', description='test-description') - device = self.config.client.create_device(device_object) - self.assertEqual(device.name, 'test-preinstalled-device') - self.assertEqual(device.description, 'test-description') - expected_configs = { - 'runtime_docker': 'False', - 'runtime_preinstalled': 'True', - 'ros_distro': 'melodic', - 'ros_workspace': 'test/path' - } - self.logger.info('validating the config variables of the created device') - for config in device.config_variables: - if config.key in expected_configs: - self.assertEqual(expected_configs[config.key], config.value) - self.logger.info('deleting the device') - self.config.client.delete_device(device.deviceId) + # def test_create_device_preinstalled(self): + # self.logger.info('creating a device with preinstalled runtime') + # device_object = Device(name='test-preinstalled-device', runtime=DeviceRuntime.PREINSTALLED, + # ros_distro=ROSDistro.MELODIC, ros_workspace='test/path', description='test-description') + # device = self.config.client.create_device(device_object) + # self.assertEqual(device.name, 'test-preinstalled-device') + # self.assertEqual(device.description, 'test-description') + # expected_configs = { + # 'runtime_docker': 'False', + # 'runtime_preinstalled': 'True', + # 'ros_distro': 'melodic', + # 'ros_workspace': 'test/path' + # } + # self.logger.info('validating the config variables of the created device') + # for config in device.config_variables: + # if config.key in expected_configs: + # self.assertEqual(expected_configs[config.key], config.value) + # self.logger.info('deleting the device') + # self.config.client.delete_device(device.deviceId) def test_onboard_device_print(self): url = self.config.api_server + '/start' diff --git a/tests/device_test.py b/tests/device_test.py index 9b6742c0..7c67362a 100644 --- a/tests/device_test.py +++ b/tests/device_test.py @@ -883,50 +883,50 @@ def test_upgrade_device_deployment_running_error(self, mock_request): device.upgrade() self.assertEqual(mock_request.call_count, 2) - @patch('requests.request') - def test_create_device_python3_dockercompose_success(self, mock_request): - expected_payload = { - 'name': 'test-device', - 'description': 'test-description', - 'python_version': '3', - 'config_variables': { - 'runtime_docker': True, - 'ros_distro': 'melodic', - 'rosbag_mount_path': 'test/path' - } - } - expected_create_device_url = 'https://gaapiserver.apps.okd4v2.prod.rapyuta.io/api/device-manager/v0/auth-keys/?download_type=script' - expected_get_device_url = 'https://gaapiserver.apps.okd4v2.prod.rapyuta.io/api/device-manager/v0/devices/test-device-id' - device = Device(name='test-device', runtime_docker=True, ros_distro=ROSDistro.MELODIC, - rosbag_mount_path='test/path', description='test-description', - python_version=DevicePythonVersion.PYTHON3) - create_device_response = Mock() - create_device_response.text = CREATE_DOCKERCOMPOSE_DEVICE_SUCCESS - create_device_response.status_code = requests.codes.OK - - get_device_response = Mock() - get_device_response.text = GET_DOCKERCOMPOSE_DEVICE_SUCCESS - get_device_response.status_code = requests.codes.OK - - mock_request.side_effect = [create_device_response, get_device_response] - client = get_client() - device = client.create_device(device) - mock_request.assert_has_calls([ - call(url=expected_create_device_url, method='POST', headers=headers, params={}, json=expected_payload), - call(headers=headers, json=None, url=expected_get_device_url, method='GET', params={}) - ]) - - self.assertEqual(device.name, 'test-device') - self.assertEqual(device.description, 'test-description') - - expected_configs = { - 'runtime': 'dockercompose', - 'ros_distro': 'melodic', - 'rosbag_mount_path': 'test/path' - } - for config in device.config_variables: - if config.key in expected_configs: - self.assertEqual(expected_configs[config.key], config.value) + # @patch('requests.request') + # def test_create_device_python3_dockercompose_success(self, mock_request): + # expected_payload = { + # 'name': 'test-device', + # 'description': 'test-description', + # 'python_version': '3', + # 'config_variables': { + # 'runtime_docker': True, + # 'ros_distro': 'melodic', + # 'rosbag_mount_path': 'test/path' + # } + # } + # expected_create_device_url = 'https://gaapiserver.apps.okd4v2.prod.rapyuta.io/api/device-manager/v0/auth-keys/?download_type=script' + # expected_get_device_url = 'https://gaapiserver.apps.okd4v2.prod.rapyuta.io/api/device-manager/v0/devices/test-device-id' + # device = Device(name='test-device', runtime_docker=True, ros_distro=ROSDistro.MELODIC, + # rosbag_mount_path='test/path', description='test-description', + # python_version=DevicePythonVersion.PYTHON3) + # create_device_response = Mock() + # create_device_response.text = CREATE_DOCKERCOMPOSE_DEVICE_SUCCESS + # create_device_response.status_code = requests.codes.OK + # + # get_device_response = Mock() + # get_device_response.text = GET_DOCKERCOMPOSE_DEVICE_SUCCESS + # get_device_response.status_code = requests.codes.OK + # + # mock_request.side_effect = [create_device_response, get_device_response] + # client = get_client() + # device = client.create_device(device) + # mock_request.assert_has_calls([ + # call(url=expected_create_device_url, method='POST', headers=headers, params={}, json=expected_payload), + # call(headers=headers, json=None, url=expected_get_device_url, method='GET', params={}) + # ]) + # + # self.assertEqual(device.name, 'test-device') + # self.assertEqual(device.description, 'test-description') + # + # expected_configs = { + # 'runtime': 'dockercompose', + # 'ros_distro': 'melodic', + # 'rosbag_mount_path': 'test/path' + # } + # for config in device.config_variables: + # if config.key in expected_configs: + # self.assertEqual(expected_configs[config.key], config.value) def test_device_is_docker_enabled_true(self): device = Device(name='test-device')