Skip to content

Commit

Permalink
chore: modifying the unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rrkumarshikhar committed Jun 17, 2024
1 parent 3348162 commit fbea9b9
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 82 deletions.
76 changes: 38 additions & 38 deletions sdk_test/device/create_device_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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'
Expand Down
88 changes: 44 additions & 44 deletions tests/device_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down

0 comments on commit fbea9b9

Please sign in to comment.