Commit 0bb5ad3a authored by gfeher@chromium.org's avatar gfeher@chromium.org

Fix generating descriptions of policy template strings

BUG=none
TEST=python:PolicyJsonUnittest.*

Review URL: http://codereview.chromium.org/6312006

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@71808 0039d316-1c4b-4281-b951-d872f2087c98
parent 8d0418a4
...@@ -147,11 +147,13 @@ class PolicyJson(skeleton_gatherer.SkeletonGatherer): ...@@ -147,11 +147,13 @@ class PolicyJson(skeleton_gatherer.SkeletonGatherer):
'caption': 'Caption', 'caption': 'Caption',
'label': 'Label', 'label': 'Label',
} }
if type == 'policy': if item_type == 'policy':
return '%s of the policy named %s' % (key_map[key], item['name']) return '%s of the policy named %s' % (key_map[key], item['name'])
elif type == 'enum_item': elif item_type == 'enum_item':
return ('%s of the option named %s in policy %s' % return ('%s of the option named %s in policy %s' %
(key_map[key], item['name'], parent_item['name'])) (key_map[key], item['name'], parent_item['name']))
else:
raise Exception('Unexpected type %s' % item_type)
def _AddPolicyKey(self, item, item_type, parent_item, key, depth): def _AddPolicyKey(self, item, item_type, parent_item, key, depth):
'''Given a policy/enumeration item and a key, adds that key and its value '''Given a policy/enumeration item and a key, adds that key and its value
......
...@@ -65,8 +65,10 @@ class PolicyJsonUnittest(unittest.TestCase): ...@@ -65,8 +65,10 @@ class PolicyJsonUnittest(unittest.TestCase):
"{" "{"
" 'policy_definitions': [" " 'policy_definitions': ["
" {" " {"
" 'name': 'Policy1',"
" 'items': [" " 'items': ["
" {" " {"
" 'name': 'Item1',"
" 'caption': 'nothing special'," " 'caption': 'nothing special',"
" }" " }"
" ]" " ]"
...@@ -88,6 +90,7 @@ class PolicyJsonUnittest(unittest.TestCase): ...@@ -88,6 +90,7 @@ class PolicyJsonUnittest(unittest.TestCase):
" {" " {"
" 'policies': [" " 'policies': ["
" {" " {"
" 'name': 'Policy1',"
" 'caption': 'nothing special'," " 'caption': 'nothing special',"
" }" " }"
" ]" " ]"
...@@ -150,6 +153,7 @@ with a newline?''', ...@@ -150,6 +153,7 @@ with a newline?''',
original = """{ original = """{
'policy_definitions': [ 'policy_definitions': [
{ {
'name': 'Policy1',
'caption': '''Please install 'caption': '''Please install
<ph name="PRODUCT_NAME">$1<ex>Google Chrome</ex></ph>.''', <ph name="PRODUCT_NAME">$1<ex>Google Chrome</ex></ph>.''',
}, },
...@@ -170,7 +174,22 @@ with a newline?''', ...@@ -170,7 +174,22 @@ with a newline?''',
self.failUnless(ph.GetPresentation() == 'PRODUCT_NAME') self.failUnless(ph.GetPresentation() == 'PRODUCT_NAME')
self.failUnless(ph.GetExample() == 'Google Chrome') self.failUnless(ph.GetExample() == 'Google Chrome')
def testGetDescription(self):
gatherer = policy_json.PolicyJson({})
self.assertEquals(
gatherer._GetDescription({'name': 'Policy1'}, 'policy', None, 'desc'),
'Description of the policy named Policy1')
self.assertEquals(
gatherer._GetDescription({'name': 'Plcy2'}, 'policy', None, 'caption'),
'Caption of the policy named Plcy2')
self.assertEquals(
gatherer._GetDescription({'name': 'Plcy3'}, 'policy', None, 'label'),
'Label of the policy named Plcy3')
self.assertEquals(
gatherer._GetDescription({'name': 'Item'}, 'enum_item',
{'name': 'Policy'}, 'caption'),
'Caption of the option named Item in policy Policy')
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment