2 # Copyright 2015 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
14 <rappor-configuration>
17 <rappor-parameter-types>
20 <rappor-parameters name="TEST_RAPPOR_TYPE">
24 <parameters num-cohorts="128" bytes="1" hash-functions="2" fake-prob="0.5"
25 fake-one-prob="0.5" one-coin-prob="0.75" zero-coin-prob="0.25"
26 reporting-level="COARSE"/>
29 </rappor-parameter-types>
34 <rappor-metric name="Test.Rappor.Metric" type="TEST_RAPPOR_TYPE">
35 <owner>user1@chromium.org</owner>
36 <owner>user2@chromium.org</owner>
38 A fake metric summary.
42 <rappor-metric name="Test.Rappor.Metric2" type="TEST_RAPPOR_TYPE">
43 <owner>user1@chromium.org</owner>
44 <owner>user2@chromium.org</owner>
46 A fake metric summary.
48 <string-field name="Url">
53 <flags-field name="Flags">
54 <flag>Flag bit #1</flag>
55 <flag>Flag bit #2</flag>
61 </rappor-configuration>
66 'name': 'Test.Rappor.Metric',
67 'type': 'TEST_RAPPOR_TYPE',
68 'owners': ['user1@chromium.org', 'user2@chromium.org'],
69 'summary': 'A fake metric summary.',
74 MULTI_FIELD_METRIC
= {
76 'name': 'Test.Rappor.Metric2',
77 'type': 'TEST_RAPPOR_TYPE',
78 'owners': ['user1@chromium.org', 'user2@chromium.org'],
79 'summary': 'A fake metric summary.',
83 'summary': 'The url of the event.',
96 class ActionXmlTest(unittest
.TestCase
):
98 def testIsPretty(self
):
99 result
= pretty_print
.UpdateXML(PRETTY_XML
)
100 self
.assertMultiLineEqual(PRETTY_XML
, result
.strip())
102 def testParsing(self
):
103 comments
, config
= pretty_print
.RAPPOR_XML_TYPE
.Parse(PRETTY_XML
)
104 self
.assertEqual(BASIC_METRIC
, config
['metrics']['metrics'][0])
105 self
.assertEqual(MULTI_FIELD_METRIC
, config
['metrics']['metrics'][1])
106 self
.assertEqual(set(['TEST_RAPPOR_TYPE']),
107 pretty_print
.GetTypeNames(config
))
109 def testMissingOwners(self
):
110 self
.assertFalse(pretty_print
.GetMissingOwnerErrors([BASIC_METRIC
]))
111 no_owners
= BASIC_METRIC
.copy()
112 no_owners
['owners'] = []
113 self
.assertTrue(pretty_print
.GetMissingOwnerErrors([no_owners
]))
115 def testInvalidTypes(self
):
116 self
.assertFalse(pretty_print
.GetInvalidTypeErrors(
117 set(['TEST_RAPPOR_TYPE']), [BASIC_METRIC
]))
118 self
.assertTrue(pretty_print
.GetInvalidTypeErrors(
119 set(['OTHER_TYPE']), [BASIC_METRIC
]))
122 if __name__
== '__main__':