def MockSiteConfig():
    """Create a SiteConfig object for convenient testing pleasure.

  Shared amoung a number of unittest files, so be careful if changing it.
  """
    result = config_lib.SiteConfig()

    # Add a single, simple build config.
    result.Add(
        'x86-generic-paladin',
        active_waterfall='chromiumos',
        boards=['x86-generic'],
        build_type='paladin',
        chrome_sdk=True,
        chrome_sdk_build_chrome=False,
        description='Commit Queue',
        doc='http://mock_url/',
        image_test=True,
        images=['base', 'test'],
        important=True,
        manifest_version=True,
        prebuilts='public',
        trybot_list=True,
        upload_standalone_images=False,
        vm_tests=[config_lib.VMTestConfig('smoke_suite')],
    )

    return result
    def testSaveLoadEmpty(self):
        config = config_lib.SiteConfig(defaults={}, site_params={})
        config_str = config.SaveConfigToString()
        loaded = config_lib.LoadConfigFromString(config_str)

        self.assertEqual(config, loaded)

        self.assertEqual(loaded.keys(), [])
        self.assertEqual(loaded._templates.keys(), [])
        self.assertEqual(loaded.GetDefault(), config_lib.DefaultSettings())
        self.assertEqual(
            loaded.params,
            config_lib.SiteParameters(config_lib.DefaultSiteParameters()))

        self.assertNotEqual(loaded.SaveConfigToString(), '')

        # Make sure we can dump debug content without crashing.
        self.assertNotEqual(loaded.DumpExpandedConfigToString(), '')
 def _GetTestConfig(self):
   test_config = config_lib.SiteConfig()
   test_config.Add(
       'master',
       config_lib.BuildConfig(),
       boards=[],
       build_type=self.build_type,
       master=True,
       manifest_version=True,
   )
   test_config.Add(
       'test1',
       config_lib.BuildConfig(),
       boards=['x86-generic'],
       manifest_version=True,
       build_type=constants.PFQ_TYPE,
       overlays='public',
       important=False,
       chrome_rev=None,
       branch=False,
       internal=False,
       master=False,
   )
   test_config.Add(
       'test2',
       config_lib.BuildConfig(),
       boards=['x86-generic'],
       manifest_version=False,
       build_type=constants.PFQ_TYPE,
       overlays='public',
       important=True,
       chrome_rev=None,
       branch=False,
       internal=False,
       master=False,
   )
   test_config.Add(
       'test3',
       config_lib.BuildConfig(),
       boards=['x86-generic'],
       manifest_version=True,
       build_type=constants.PFQ_TYPE,
       overlays='both',
       important=True,
       chrome_rev=None,
       branch=False,
       internal=True,
       master=False,
   )
   test_config.Add(
       'test4',
       config_lib.BuildConfig(),
       boards=['x86-generic'],
       manifest_version=True,
       build_type=constants.PFQ_TYPE,
       overlays='both',
       important=True,
       chrome_rev=None,
       branch=True,
       internal=True,
       master=False,
   )
   test_config.Add(
       'test5',
       config_lib.BuildConfig(),
       boards=['x86-generic'],
       manifest_version=True,
       build_type=constants.PFQ_TYPE,
       overlays='public',
       important=True,
       chrome_rev=None,
       branch=False,
       internal=False,
       master=False,
   )
   return test_config
    def testAdd(self):
        """Test the SiteConfig.Add behavior."""

        minimal_defaults = {
            'name': None,
            '_template': None,
            'value': 'default',
        }

        site_config = config_lib.SiteConfig(defaults=minimal_defaults)
        template = site_config.AddTemplate('template', value='template')
        mixin = config_lib.BuildConfig(value='mixin')

        site_config.Add('default')

        site_config.Add('default_with_override', value='override')

        site_config.Add('default_with_mixin', mixin)

        site_config.Add('mixin_with_override', mixin, value='override')

        site_config.Add('default_with_template', template)

        site_config.Add('template_with_override', template, value='override')

        site_config.Add('template_with_mixin', template, mixin)

        site_config.Add('template_with_mixin_override',
                        template,
                        mixin,
                        value='override')

        expected = {
            'default': {
                '_template': None,
                'name': 'default',
                'value': 'default',
            },
            'default_with_override': {
                '_template': None,
                'name': 'default_with_override',
                'value': 'override',
            },
            'default_with_mixin': {
                '_template': None,
                'name': 'default_with_mixin',
                'value': 'mixin',
            },
            'mixin_with_override': {
                '_template': None,
                'name': 'mixin_with_override',
                'value': 'override',
            },
            'default_with_template': {
                '_template': 'template',
                'name': 'default_with_template',
                'value': 'template',
            },
            'template_with_override': {
                '_template': 'template',
                'name': 'template_with_override',
                'value': 'override'
            },
            'template_with_mixin': {
                '_template': 'template',
                'name': 'template_with_mixin',
                'value': 'mixin',
            },
            'template_with_mixin_override': {
                '_template': 'template',
                'name': 'template_with_mixin_override',
                'value': 'override'
            },
        }

        self.maxDiff = None
        self.assertDictEqual(site_config, expected)