#!/usr/bin/env python # Copyright 2015 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. import unittest import pretty_print PRETTY_XML = """ Fake type for tests. user1@chromium.org user2@chromium.org A fake metric summary. """.strip() BASIC_METRIC = { 'comments': [], 'name': 'Test.Rappor.Metric', 'type': 'TEST_RAPPOR_TYPE', 'owners': ['user1@chromium.org', 'user2@chromium.org'], 'summary': 'A fake metric summary.', } class ActionXmlTest(unittest.TestCase): def testIsPretty(self): result = pretty_print.UpdateXML(PRETTY_XML) self.assertEqual(PRETTY_XML, result) def testParsing(self): comments, config = pretty_print.RAPPOR_XML_TYPE.Parse(PRETTY_XML) self.assertEqual(BASIC_METRIC, config['metrics']['metrics'][0]) self.assertEqual(set(['TEST_RAPPOR_TYPE']), pretty_print.GetTypeNames(config)) def testMissingOwners(self): self.assertFalse(pretty_print.HasMissingOwners([BASIC_METRIC])) no_owners = BASIC_METRIC.copy() no_owners['owners'] = [] self.assertTrue(pretty_print.HasMissingOwners([no_owners])) def testInvalidTypes(self): self.assertFalse(pretty_print.HasInvalidTypes( set(['TEST_RAPPOR_TYPE']), [BASIC_METRIC])) self.assertTrue(pretty_print.HasInvalidTypes( set(['OTHER_TYPE']), [BASIC_METRIC])) if __name__ == '__main__': unittest.main()