def show_work_item(id, as_of=None, expand='all', fields=None, open=False, organization=None, detect=None): # pylint: disable=redefined-builtin """Show details for a work item. :param id: The ID of the work item :type id: int :param as_of: Work item details as of a particular date and time. Provide a date or date time string. Assumes local time zone. Example: '2019-01-20', '2019-01-20 00:20:00'. For UTC, append 'UTC' to the date time string, '2019-01-20 00:20:00 UTC'. :type as_of:string :param expand: The expand parameters for work item attributes. :type expand:str :param fields: Comma-separated list of requested fields. Example:System.Id,System.AreaPath. Refer https://aka.ms/azure-devops-cli-field-api for more details on fields. :type fields: str :param open: Open the work item in the default web browser. :type open: bool :rtype: :class:`<WorkItem> <v5_0.work-item-tracking.models.WorkItem>` """ organization = resolve_instance(detect=detect, organization=organization) try: client = get_work_item_tracking_client(organization) as_of_iso = None if as_of: as_of_iso = convert_date_string_to_iso8601(value=as_of, argument='as-of') if fields: fields = fields.split(',') work_item = client.get_work_item(id, as_of=as_of_iso, fields=fields, expand=expand) except AzureDevOpsServiceError as ex: _handle_vsts_service_error(ex) if open: _open_work_item(work_item, organization) return work_item
def banner_update(message=None, banner_type=None, id=None, expiration=None, organization=None, detect=None): # pylint: disable=redefined-builtin """Update the message, level, or expiration date for a banner. :param message: Message (string) to show in the banner. :type message: str :param banner_type: Type of banner to present. Defaults is "info". :type banner_type: str :param id: ID of the banner to update. :type id: str :param expiration: Date/time when the banner should no longer be presented to users. To unset the expiration for the banner, supply an empty value to this argument. Example : "2019-06-10 17:21:00 UTC", "2019-06-10" :type expiration: date :rtype: [object] """ if message is None and banner_type is None and expiration is None: raise ValueError( 'At least one of the following arguments need to be supplied: --message, --type, ' '--expiration.') if expiration is not None: expiration_iso8601 = convert_date_string_to_iso8601( value=expiration, argument='expiration') else: expiration_iso8601 = None existing_entries = setting_list(user_scope='host', key=GLOBAL_MESSAGE_BANNERS_KEY, organization=organization, detect=detect) if id not in existing_entries: raise ValueError('The following banner was not found: %s' % id) existing_entry = existing_entries[id] setting_key = _get_banner_key(id) entries = {setting_key: {"message": message}} if message is not None: entries[setting_key]['message'] = message elif 'message' in existing_entry: entries[setting_key]['message'] = existing_entry['message'] if banner_type is not None: entries[setting_key]['level'] = banner_type elif 'level' in existing_entry: entries[setting_key]['level'] = existing_entry['level'] if expiration_iso8601 is not None: entries[setting_key]['expirationDate'] = expiration_iso8601 elif 'expirationDate' in existing_entry: entries[setting_key]['expirationDate'] = existing_entry[ 'expirationDate'] setting_add_or_update(entries=entries, user_scope=USER_SCOPE_HOST, organization=organization, detect=detect) return {id: entries[setting_key]}
def banner_add(message, banner_type=None, id=None, expiration=None, organization=None, detect=None): # pylint: disable=redefined-builtin """Add a new banner and immediately show it. :param message: Message (string) to show in the banner. :type message: str :param banner_type: Type of banner to present. Defaults is "info". :type banner_type: str :param id: Identifier for the new banner. This identifier is needed to change or remove the message later. A unique identifier is automatically created if one is not specified. :type id: str :param expiration: Date/time when the banner should no longer be presented to users. If not set, the banner does not automatically expire and must be removed with the remove command. Example : "2019-06-10 17:21:00 UTC", "2019-06-10" :type expiration: date :param organization: Azure Devops organization URL. Example: https://dev.azure.com/MyOrganizationName/ :type organization: str :param detect: Automatically detect organization and project. Default is "on". :type detect: str :rtype: [object] """ try: if expiration is not None: expiration_iso8601 = convert_date_string_to_iso8601( value=expiration, argument='expiration') else: expiration_iso8601 = None if id is None or id == '': import uuid id = str(uuid.uuid4()) setting_key = _get_banner_key(id) entries = {setting_key: {"message": message}} if banner_type is not None: entries[setting_key]['level'] = banner_type if expiration_iso8601 is not None: entries[setting_key]['expirationDate'] = expiration_iso8601 setting_add_or_update(entries=entries, user_scope=USER_SCOPE_HOST, organization=organization, detect=detect) return {id: entries[setting_key]} except VstsServiceError as ex: raise CLIError(ex)
def test_show_work_item_correct_id_as_of(self): test_work_item_id = 1 # set return values self.mock_get_WI.return_value.id = test_work_item_id as_of_date = '2019-01-01' response = show_work_item(id=test_work_item_id, as_of=as_of_date, organization=self._TEST_DEVOPS_ORGANIZATION) # assert self.mock_validate_token.assert_not_called() from azext_devops.dev.common.arguments import convert_date_string_to_iso8601 iso_date = convert_date_string_to_iso8601(as_of_date) self.mock_get_WI.assert_called_once_with(test_work_item_id, as_of=iso_date, expand='all', fields=None) assert response.id == test_work_item_id
def test_admin_banner_addUpdateShowListRemove(self): self.cmd('az devops configure --defaults organization=' + DEVOPS_CLI_TEST_ORGANIZATION) admin_banner_message = 'Sample banner message' admin_banner_type = 'warning' admin_banner_updated_message = 'Sample updated banner message' admin_banner_updated_type = 'error' admin_banner_id = self.create_random_name(prefix='banner-id-', length=15) admin_banner_expiration_date = datetime.today().strftime('%Y-%m-%d') try: #add a banner to the project add_admin_banner_command = ('az devops admin banner add --id ' + admin_banner_id + ' --message "' + admin_banner_message + '" --type ' + admin_banner_type + ' --expiration ' + admin_banner_expiration_date + ' --output json --detect false --debug') add_admin_banner_output = self.cmd(add_admin_banner_command).get_output_in_json() assert len(add_admin_banner_output) > 0 assert add_admin_banner_output[admin_banner_id]["level"] == admin_banner_type assert add_admin_banner_output[admin_banner_id]["message"] == admin_banner_message from azext_devops.dev.common.arguments import convert_date_string_to_iso8601 iso_date = convert_date_string_to_iso8601(admin_banner_expiration_date) assert add_admin_banner_output[admin_banner_id]["expirationDate"] == iso_date #Test was failing without adding a sleep here. Though the create was successful when queried after few seconds. self.sleep_in_live_run(5) #update banner update_admin_banner_command = ('az devops admin banner update --id ' + admin_banner_id + ' --message "' + admin_banner_updated_message + '" --expiration ' + '""' + ' --type ' + admin_banner_updated_type + ' --output json --detect false') update_admin_banner_output = self.cmd(update_admin_banner_command).get_output_in_json() assert len(update_admin_banner_output[admin_banner_id]) > 0 assert update_admin_banner_output[admin_banner_id]["level"] == admin_banner_updated_type assert update_admin_banner_output[admin_banner_id]["message"] == admin_banner_updated_message assert update_admin_banner_output[admin_banner_id]["expirationDate"] == '' #Test was failing without adding a sleep here. Though the update was successful when queried after few seconds. self.sleep_in_live_run(5) #list banner command list_admin_banner_command = 'az devops admin banner list --output json --detect false' list_admin_banner_output = self.cmd(list_admin_banner_command).get_output_in_json() assert len(list_admin_banner_output[admin_banner_id]) > 0 assert list_admin_banner_output[admin_banner_id]["level"] == admin_banner_updated_type assert list_admin_banner_output[admin_banner_id]["message"] == admin_banner_updated_message #show banner command show_admin_banner_command = 'az devops admin banner show --id ' + admin_banner_id + ' --output json --detect false' show_admin_banner_output = self.cmd(show_admin_banner_command).get_output_in_json() assert len(show_admin_banner_output[admin_banner_id]) > 0 assert show_admin_banner_output[admin_banner_id]["level"] == admin_banner_updated_type assert show_admin_banner_output[admin_banner_id]["message"] == admin_banner_updated_message finally: #TestCleanup - remove admin banner remove_admin_banner_command = 'az devops admin banner remove --id ' + admin_banner_id + ' --output json --detect false' self.cmd(remove_admin_banner_command) #Verify remove #Test was failing without adding a sleep here. Though the remove was successful. self.sleep_in_live_run(5) list_admin_banner_command = 'az devops admin banner list --output json --detect false' list_admin_banner_output = self.cmd(list_admin_banner_command).get_output_in_json() assert admin_banner_id not in list(list_admin_banner_output.keys())