def test_str_with_meta(self): resp = fakes.create_response() obj = resource.StrWithMeta('test-str', resp) self.assertEqual('test-str', obj) # Check request_id attribute is added to obj self.assertTrue(hasattr(obj, 'request_id')) self.assertEqual(fakes.FAKE_REQUEST_ID, obj.request_id)
def test_disable_redirection_options(self, mocked_put): args = [ "--disable-usb-port-redirection", "--enable-usb-image", "--enable-usb-video", "--enable-usb-printer", "--enable-usb-storage", "--enable-usb-smart-card", "--disable-printer-redirection", "--enable-sync-client-default-printer", "--universal-printer-driver", "Universal Printing PCL 6", "--file-redirection-mode", "DISABLED", "--enable-fixed-drive", "--enable-removable-drive", "--enable-cd-rom-drive", "--enable-network-drive", "--enable-network-drive", "--clipboard-redirection", "DISABLED", ] verify_args = [ ("enable_usb_port_redirection", False), ("enable_usb_image", True), ("enable_usb_video", True), ("enable_usb_printer", True), ("enable_usb_storage", True), ("enable_usb_smart_card", True), ("enable_printer_redirection", False), ("enable_sync_client_default_printer", True), ("universal_printer_driver", "Universal Printing PCL 6"), ("file_redirection_mode", "DISABLED"), ("enable_fixed_drive", True), ("enable_removable_drive", True), ("enable_cd_rom_drive", True), ("enable_network_drive", True), ("clipboard_redirection", "DISABLED"), ] parsed_args = self.check_parser(self.cmd, args, verify_args) mocked_put.return_value = base_resource.StrWithMeta("", "Request-Id") result = self.cmd.take_action(parsed_args) json = { "policies": { "usb_port_redirection": { "enable": False, }, "printer_redirection": { "enable": False, }, "file_redirection": { "redirection_mode": "DISABLED", }, "clipboard_redirection": "DISABLED", } } mocked_put.assert_called_once_with("/policies", json=json) self.assertEqual('done', result)
def test_desktop_list(self, mocked): args = ["desktop-id-1"] verify_args = [ ("desktop_id", "desktop-id-1"), ] parsed_args = self.check_parser(self.cmd, args, verify_args) with self.mocked_find: mocked.return_value = base_resource.StrWithMeta("", "Request-ID") result = self.cmd.take_action(parsed_args) mocked.assert_called_once_with("/desktops/" + self._desktop.desktop_id) self.assertEquals("done", result)
def _update_all(self, url, json, key=None, raw=False, headers={}): """update resource with PUT method""" resp, body = self.http_client.put(url, json=json, headers=headers) # PATCH requests may not return a body if body: # get required body part content = self.get_data(body, key) if raw: return self.mixin_meta(content, resp) else: return self.resource_class(self, content, resp=resp) else: return resource.StrWithMeta(resp.text, resp)
def mixin_meta(item, resp): if isinstance(item, six.string_types): if six.PY2 and isinstance(item, six.text_type): return resource.UnicodeWithMeta(item, resp) else: return resource.StrWithMeta(item, resp) elif isinstance(item, six.binary_type): return resource.BytesWithMeta(item, resp) elif isinstance(item, list): return resource.ListWithMeta(item, resp) elif isinstance(item, tuple): return resource.TupleWithMeta(item, resp) elif item is None: return resource.TupleWithMeta((), resp) else: return resource.DictWithMeta(item, resp)
def test_soft_reboot(self, mocked): args = ["desktop-id-1", "--soft"] verify_args = [ ("desktop_id", "desktop-id-1"), ("force", False), ] parsed_args = self.check_parser(self.cmd, args, verify_args) with self.mocked_find: mocked.return_value = base_resource.StrWithMeta("", "Request-ID") result = self.cmd.take_action(parsed_args) mocked.assert_called_once_with("/desktops/%s/action" % self._desktop.desktop_id, json={"reboot": { "type": "SOFT" }}) self.assertEquals("done", result)
def test_stop_desktop(self, mocked): args = ["desktop-id-1", "--computer-name", "computer02"] verify_args = [ ("desktop_id", "desktop-id-1"), ("computer_name", "computer02"), ] parsed_args = self.check_parser(self.cmd, args, verify_args) with self.mocked_find: mocked.return_value = base_resource.StrWithMeta("", "Request-ID") result = self.cmd.take_action(parsed_args) mocked.assert_called_once_with( "/desktops/%s" % self._desktop.desktop_id, json={"desktop": { "computer_name": "computer02" }}) self.assertEquals("done", result)
def _get(self, url, params={}, key=None, raw=False, resource_class=None, headers={}): resp, body = self.http_client.get(url, params=params, headers=headers) # get required body part if body: content = self.get_data(body, key) if raw: return self.mixin_meta(content, resp) else: rc = resource_class if resource_class else self.resource_class return self.resource_class(self, content, resp=resp, attached=True) else: return resource.StrWithMeta(resp.text, resp)
def test_hdp_plus_disable(self, mocked_put): args = [ "--disable-hdp-plus", "--display-level", "QUALITY_FIRST", "--bandwidth", "24315", "--frame-rate", "18", "--video-frame-rate", "20", "--smoothing-factor", "58", "--lossy-compression-quality", "88" ] verify_args = [ ("enable_hdp_plus", False), ("display_level", "QUALITY_FIRST"), ("bandwidth", 24315), ("frame_rate", 18), ("video_frame_rate", 20), ("smoothing_factor", 58), ("lossy_compression_quality", 88), ] parsed_args = self.check_parser(self.cmd, args, verify_args) mocked_put.return_value = base_resource.StrWithMeta("", "Request-Id") result = self.cmd.take_action(parsed_args) json = { "policies": { "hdp_plus": { "hdp_plus_enable": False, "display_level": "QUALITY_FIRST", "options": { "bandwidth": 24315, "frame_rate": 18, "video_frame_rate": 20, "smoothing_factor": 58, } } } } mocked_put.assert_called_once_with("/policies", json=json) self.assertEqual('done', result)
def test_edit_local_ad_workspace(self, mocked): args = [ "--domain-type", "LITE_AD", "--domain-admin-account", "account", "--domain-password", "p1", ] verify_args = ( ("domain_type", "LITE_AD"), ("domain_password", "p1"), ("domain_admin_account", "account"), ) parsed_args = self.check_parser(self.cmd, args, verify_args) mocked.return_value = base_resource.StrWithMeta('', 'Request-ID') result = self.cmd.take_action(parsed_args) json = { "ad_domains": { "domain_type": "LITE_AD", "domain_admin_account": "account", "domain_password": "******" } } mocked.assert_called_once_with("/workspaces", json=json, raw=True) self.assertEquals("done", result)
def test_enable_redirection_options(self, mocked_put): args = [ "--enable-usb-port-redirection", "--enable-usb-image", "--enable-usb-video", "--enable-usb-printer", "--enable-usb-storage", "--enable-usb-smart-card", "--enable-printer-redirection", "--enable-sync-client-default-printer", "--universal-printer-driver", "Universal Printing PCL 6", "--file-redirection-mode", "READ_AND_WRITE", "--enable-fixed-drive", "--enable-removable-drive", "--enable-cd-rom-drive", "--enable-network-drive", "--enable-network-drive", "--clipboard-redirection", "DISABLED", "--enable-hdp-plus", "--display-level", "QUALITY_FIRST", "--bandwidth", "24315", "--frame-rate", "18", "--video-frame-rate", "20", "--smoothing-factor", "58", "--lossy-compression-quality", "88" ] verify_args = [ ("enable_usb_port_redirection", True), ("enable_usb_image", True), ("enable_usb_video", True), ("enable_usb_printer", True), ("enable_usb_storage", True), ("enable_usb_smart_card", True), ("enable_printer_redirection", True), ("enable_sync_client_default_printer", True), ("universal_printer_driver", "Universal Printing PCL 6"), ("file_redirection_mode", "READ_AND_WRITE"), ("enable_fixed_drive", True), ("enable_removable_drive", True), ("enable_cd_rom_drive", True), ("enable_network_drive", True), ("clipboard_redirection", "DISABLED"), ("enable_hdp_plus", True), ("display_level", "QUALITY_FIRST"), ("bandwidth", 24315), ("frame_rate", 18), ("video_frame_rate", 20), ("smoothing_factor", 58), ("lossy_compression_quality", 88), ] parsed_args = self.check_parser(self.cmd, args, verify_args) mocked_put.return_value = base_resource.StrWithMeta("", "Request-Id") result = self.cmd.take_action(parsed_args) json = { "policies": { "usb_port_redirection": { "enable": True, "options": { "usb_image_enable": True, "usb_video_enable": True, "usb_printer_enable": True, "usb_storage_enable": True, "usb_smart_card_enable": True, } }, "printer_redirection": { "enable": True, "options": { "sync_client_default_printer_enable": True, "universal_printer_driver": "Universal Printing PCL 6" } }, "file_redirection": { "redirection_mode": "READ_AND_WRITE", "options": { "fixed_drive_enable": True, "removable_drive_enable": True, "cd_rom_drive_enable": True, "network_drive_enable": True } }, "clipboard_redirection": "DISABLED", "hdp_plus": { "hdp_plus_enable": True, "display_level": "QUALITY_FIRST", "options": { "lossy_compression_quality": 88 } } } } mocked_put.assert_called_once_with("/policies", json=json) self.assertEqual('done', result)