def test_check_for_changes(self):
        static_backend_entry = backendinfo.BackendEntry(name='static')
        dynamic_backend_entry = backendinfo.BackendEntry(name='dynamic')
        backend_info = backendinfo.BackendInfoExternal(
            backends=[static_backend_entry, dynamic_backend_entry])
        module_config = self.mox.CreateMock(
            application_configuration.ModuleConfiguration)
        self.mox.StubOutWithMock(application_configuration,
                                 'ModuleConfiguration')
        application_configuration.ModuleConfiguration(
            '/appdir/app.yaml', None).AndReturn(module_config)
        application_configuration.BackendsConfiguration._parse_configuration(
            '/appdir/backends.yaml').AndReturn(backend_info)
        module_config.check_for_updates().AndReturn(set())
        module_config.check_for_updates().AndReturn(set([1]))
        module_config.check_for_updates().AndReturn(set([2]))
        module_config.check_for_updates().AndReturn(set())

        self.mox.ReplayAll()
        config = application_configuration.BackendsConfiguration(
            '/appdir/app.yaml', '/appdir/backends.yaml')
        self.assertEqual(set(), config.check_for_updates('dynamic'))
        self.assertEqual(set([1]), config.check_for_updates('static'))
        self.assertEqual(set([1, 2]), config.check_for_updates('dynamic'))
        self.assertEqual(set([2]), config.check_for_updates('static'))
        self.mox.VerifyAll()
    def test_good_configuration(self):
        self.mox.StubOutWithMock(application_configuration,
                                 'ModuleConfiguration')
        static_backend_entry = backendinfo.BackendEntry(name='static')
        dynamic_backend_entry = backendinfo.BackendEntry(name='dynamic')
        backend_info = backendinfo.BackendInfoExternal(
            backends=[static_backend_entry, dynamic_backend_entry])
        module_config = object()
        application_configuration.ModuleConfiguration(
            '/appdir/app.yaml', None).AndReturn(module_config)
        application_configuration.BackendsConfiguration._parse_configuration(
            '/appdir/backends.yaml').AndReturn(backend_info)
        static_configuration = object()
        dynamic_configuration = object()
        application_configuration.BackendConfiguration(
            module_config, mox.IgnoreArg(),
            static_backend_entry).InAnyOrder().AndReturn(static_configuration)
        application_configuration.BackendConfiguration(
            module_config, mox.IgnoreArg(),
            dynamic_backend_entry).InAnyOrder().AndReturn(
                dynamic_configuration)

        self.mox.ReplayAll()
        config = application_configuration.BackendsConfiguration(
            '/appdir/app.yaml', '/appdir/backends.yaml')
        self.assertItemsEqual([static_configuration, dynamic_configuration],
                              config.get_backend_configurations())
        self.mox.VerifyAll()
    def test_no_backends(self):
        self.mox.StubOutWithMock(application_configuration,
                                 'ModuleConfiguration')
        backend_info = backendinfo.BackendInfoExternal()
        module_config = object()
        application_configuration.ModuleConfiguration(
            '/appdir/app.yaml', None).AndReturn(module_config)
        application_configuration.BackendsConfiguration._parse_configuration(
            '/appdir/backends.yaml').AndReturn(backend_info)

        self.mox.ReplayAll()
        config = application_configuration.BackendsConfiguration(
            '/appdir/app.yaml', '/appdir/backends.yaml')
        self.assertEqual([], config.get_backend_configurations())
        self.mox.VerifyAll()