Skip to content

Commit e5c0363

Browse files
authored
Handle empty expiration date and make id required in admin banner update cmd (#868)
* Handle empty expiration date * Makinf id param mandatory for banner update command * Fixing back compat check * Minor * minor refactoring
1 parent 2ed0e26 commit e5c0363

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

azure-devops/azext_devops/dev/admin/banner.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def banner_add(message, banner_type=None, id=None, expiration=None, organization
6464
return {id: entries[setting_key]}
6565

6666

67-
def banner_update(message=None, banner_type=None, id=None, expiration=None, organization=None, detect=None): # pylint: disable=redefined-builtin
67+
def banner_update(id, message=None, banner_type=None, expiration=None, organization=None, detect=None): # pylint: disable=redefined-builtin
6868
"""Update the message, level, or expiration date for a banner.
6969
:param message: Message (string) to show in the banner.
7070
:type message: str
@@ -81,10 +81,10 @@ def banner_update(message=None, banner_type=None, id=None, expiration=None, orga
8181
if message is None and banner_type is None and expiration is None:
8282
raise ValueError('At least one of the following arguments need to be supplied: --message, --type, '
8383
'--expiration.')
84-
if expiration is not None:
84+
if expiration is not None and expiration != '':
8585
expiration_iso8601 = convert_date_string_to_iso8601(value=expiration, argument='expiration')
8686
else:
87-
expiration_iso8601 = None
87+
expiration_iso8601 = expiration
8888
existing_entries = setting_list(user_scope='host',
8989
key=GLOBAL_MESSAGE_BANNERS_KEY,
9090
organization=organization,

scripts/backCompatChecker.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717

1818
allowedNewMandatoryArguments = {}
19+
allowedNewMandatoryArguments['devops admin banner update'] = ['--id']
1920

2021

2122
# Do not compare these commands

tests/test_adminBannerTest.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import os
77
import unittest
88

9+
from datetime import datetime
910
from azure_devtools.scenario_tests import AllowLargeResponse
1011
from .utilities.helper import DevopsScenarioTest, disable_telemetry, set_authentication, get_test_org_from_env_variable
1112

@@ -23,26 +24,33 @@ def test_admin_banner_addUpdateShowListRemove(self):
2324
admin_banner_updated_message = 'Sample updated banner message'
2425
admin_banner_updated_type = 'error'
2526
admin_banner_id = self.create_random_name(prefix='banner-id-', length=15)
27+
admin_banner_expiration_date = datetime.today().strftime('%Y-%m-%d')
2628

2729
try:
2830
#add a banner to the project
2931
add_admin_banner_command = ('az devops admin banner add --id ' + admin_banner_id + ' --message "' + admin_banner_message + '" --type ' + admin_banner_type +
32+
' --expiration ' + admin_banner_expiration_date +
3033
' --output json --detect false --debug')
3134
add_admin_banner_output = self.cmd(add_admin_banner_command).get_output_in_json()
3235
assert len(add_admin_banner_output) > 0
3336
assert add_admin_banner_output[admin_banner_id]["level"] == admin_banner_type
3437
assert add_admin_banner_output[admin_banner_id]["message"] == admin_banner_message
38+
from azext_devops.dev.common.arguments import convert_date_string_to_iso8601
39+
iso_date = convert_date_string_to_iso8601(admin_banner_expiration_date)
40+
assert add_admin_banner_output[admin_banner_id]["expirationDate"] == iso_date
3541

3642
#Test was failing without adding a sleep here. Though the create was successful when queried after few seconds.
3743
self.sleep_in_live_run(5)
3844

3945
#update banner
4046
update_admin_banner_command = ('az devops admin banner update --id ' + admin_banner_id + ' --message "' + admin_banner_updated_message +
41-
'" --type ' + admin_banner_updated_type + ' --output json --detect false')
47+
'" --expiration ' + '""' +
48+
' --type ' + admin_banner_updated_type + ' --output json --detect false')
4249
update_admin_banner_output = self.cmd(update_admin_banner_command).get_output_in_json()
4350
assert len(update_admin_banner_output[admin_banner_id]) > 0
4451
assert update_admin_banner_output[admin_banner_id]["level"] == admin_banner_updated_type
4552
assert update_admin_banner_output[admin_banner_id]["message"] == admin_banner_updated_message
53+
assert update_admin_banner_output[admin_banner_id]["expirationDate"] == ''
4654

4755
#Test was failing without adding a sleep here. Though the update was successful when queried after few seconds.
4856
self.sleep_in_live_run(5)

0 commit comments

Comments
 (0)