def test_yaml_files_with_backends_and_dispatch_yaml(self):
        os.path.isdir('/appdir/app.yaml').AndReturn(False)
        module_config = ModuleConfigurationStub(module_name='default')
        application_configuration.ModuleConfiguration(
            '/appdir/app.yaml', None).AndReturn(module_config)

        os.path.isdir('/appdir/backends.yaml').AndReturn(False)
        backend_config = ModuleConfigurationStub(module_name='backend')
        backends_config = self.mox.CreateMock(
            application_configuration.BackendsConfiguration)
        backends_config.get_backend_configurations().AndReturn(
            [backend_config])
        application_configuration.BackendsConfiguration(
            os.path.join('/appdir', 'app.yaml'),
            os.path.join('/appdir', 'backends.yaml'),
            None).AndReturn(backends_config)
        os.path.isdir('/appdir/dispatch.yaml').AndReturn(False)
        dispatch_config = DispatchConfigurationStub([(None, 'default'),
                                                     (None, 'backend')])
        application_configuration.DispatchConfiguration(
            '/appdir/dispatch.yaml').AndReturn(dispatch_config)

        self.mox.ReplayAll()
        config = application_configuration.ApplicationConfiguration([
            '/appdir/app.yaml', '/appdir/backends.yaml',
            '/appdir/dispatch.yaml'
        ])
        self.mox.VerifyAll()
        self.assertEqual('myapp', config.app_id)
        self.assertSequenceEqual([module_config, backend_config],
                                 config.modules)
        self.assertEqual(dispatch_config, config.dispatch)
    def test_good_configuration(self):
        info = dispatchinfo.DispatchInfoExternal(
            application='appid',
            dispatch=[
                dispatchinfo.DispatchEntry(url='*/path', module='foo'),
                dispatchinfo.DispatchEntry(url='domain.com/path',
                                           module='bar'),
                dispatchinfo.DispatchEntry(url='*/path/*', module='baz'),
                dispatchinfo.DispatchEntry(url='*.domain.com/path/*',
                                           module='foo'),
            ])

        os.path.getmtime('/appdir/dispatch.yaml').AndReturn(123.456)
        application_configuration.DispatchConfiguration._parse_configuration(
            '/appdir/dispatch.yaml').AndReturn(info)

        self.mox.ReplayAll()
        config = application_configuration.DispatchConfiguration(
            '/appdir/dispatch.yaml')
        self.mox.VerifyAll()

        self.assertEqual(123.456, config._mtime)
        self.assertEqual(2, len(config.dispatch))
        self.assertEqual(vars(dispatchinfo.ParsedURL('*/path')),
                         vars(config.dispatch[0][0]))
        self.assertEqual('foo', config.dispatch[0][1])
        self.assertEqual(vars(dispatchinfo.ParsedURL('*/path/*')),
                         vars(config.dispatch[1][0]))
        self.assertEqual('baz', config.dispatch[1][1])
    def test_check_for_updates_with_modification(self):
        info = dispatchinfo.DispatchInfoExternal(
            application='appid',
            dispatch=[
                dispatchinfo.DispatchEntry(url='*/path', module='bar'),
            ])
        new_info = dispatchinfo.DispatchInfoExternal(
            application='appid',
            dispatch=[
                dispatchinfo.DispatchEntry(url='*/path', module='foo'),
            ])

        os.path.getmtime('/appdir/dispatch.yaml').AndReturn(123.456)
        application_configuration.DispatchConfiguration._parse_configuration(
            '/appdir/dispatch.yaml').AndReturn(info)
        os.path.getmtime('/appdir/dispatch.yaml').AndReturn(124.456)
        application_configuration.DispatchConfiguration._parse_configuration(
            '/appdir/dispatch.yaml').AndReturn(new_info)

        self.mox.ReplayAll()
        config = application_configuration.DispatchConfiguration(
            '/appdir/dispatch.yaml')
        self.assertEqual('bar', config.dispatch[0][1])
        config.check_for_updates()
        self.mox.VerifyAll()
        self.assertEqual('foo', config.dispatch[0][1])
  def test_config_with_yaml_and_xml(self):
    absnames = self._make_file_hierarchy(
        ['module1/app.yaml', 'module1/dispatch.yaml',
         'module2/WEB-INF/appengine-web.xml', 'module2/WEB-INF/web.xml'])
    app_yaml = absnames[0]
    dispatch_yaml = absnames[1]
    appengine_web_xml = absnames[2]
    module2 = os.path.dirname(os.path.dirname(appengine_web_xml))

    module1_config = ModuleConfigurationStub(module_name='default')
    application_configuration.ModuleConfiguration(
        app_yaml, None).AndReturn(module1_config)
    dispatch_config = DispatchConfigurationStub(
        [(None, 'default'), (None, 'module2')])
    application_configuration.DispatchConfiguration(
        dispatch_yaml).AndReturn(dispatch_config)
    module2_config = ModuleConfigurationStub(module_name='module2')
    application_configuration.ModuleConfiguration(
        appengine_web_xml, None).AndReturn(module2_config)

    self.mox.ReplayAll()
    with _java_temporarily_supported():
      config = application_configuration.ApplicationConfiguration(
          [app_yaml, dispatch_yaml, module2])
    self.mox.VerifyAll()

    self.assertEqual('myapp', config.app_id)
    self.assertSequenceEqual(
        [module1_config, module2_config], config.modules)
    self.assertEqual(dispatch_config, config.dispatch)
  def test_yaml_files_with_backends_and_dispatch_yaml(self):
    absnames = self._make_file_hierarchy(
        ['appdir/app.yaml', 'appdir/backends.yaml', 'appdir/dispatch.yaml'])

    module_config = ModuleConfigurationStub(module_name='default')
    application_configuration.ModuleConfiguration(
        absnames[0], None).AndReturn(module_config)

    backend_config = ModuleConfigurationStub(module_name='backend')
    backends_config = self.mox.CreateMock(
        application_configuration.BackendsConfiguration)
    backends_config.get_backend_configurations().AndReturn([backend_config])
    application_configuration.BackendsConfiguration(
        absnames[0], absnames[1], None).AndReturn(backends_config)
    dispatch_config = DispatchConfigurationStub(
        [(None, 'default'), (None, 'backend')])
    application_configuration.DispatchConfiguration(
        absnames[2]).AndReturn(dispatch_config)

    self.mox.ReplayAll()
    config = application_configuration.ApplicationConfiguration(absnames)
    self.mox.VerifyAll()
    self.assertEqual('myapp', config.app_id)
    self.assertSequenceEqual([module_config, backend_config], config.modules)
    self.assertEqual(dispatch_config, config.dispatch)
    def test_check_for_updates_no_modification(self):
        info = dispatchinfo.DispatchInfoExternal(application='appid',
                                                 dispatch=[])

        os.path.getmtime('/appdir/dispatch.yaml').AndReturn(123.456)
        application_configuration.DispatchConfiguration._parse_configuration(
            '/appdir/dispatch.yaml').AndReturn(info)
        os.path.getmtime('/appdir/dispatch.yaml').AndReturn(123.456)

        self.mox.ReplayAll()
        config = application_configuration.DispatchConfiguration(
            '/appdir/dispatch.yaml')
        config.check_for_updates()
        self.mox.VerifyAll()
    def test_yaml_files_dispatch_yaml_and_no_default_module(self):
        os.path.isdir('/appdir/app.yaml').AndReturn(False)
        module_config = ModuleConfigurationStub(module_name='not-default')
        application_configuration.ModuleConfiguration(
            '/appdir/app.yaml', None).AndReturn(module_config)

        os.path.isdir('/appdir/dispatch.yaml').AndReturn(False)
        dispatch_config = DispatchConfigurationStub([(None, 'default')])
        application_configuration.DispatchConfiguration(
            '/appdir/dispatch.yaml').AndReturn(dispatch_config)

        self.mox.ReplayAll()
        self.assertRaises(errors.InvalidAppConfigError,
                          application_configuration.ApplicationConfiguration,
                          ['/appdir/app.yaml', '/appdir/dispatch.yaml'])
        self.mox.VerifyAll()
Пример #8
0
  def test_yaml_files_dispatch_yaml_and_missing_dispatch_target(self):
    os.path.isdir('/appdir/app.yaml').AndReturn(False)
    server_config = ServerConfigurationStub(server_name='default')
    application_configuration.ServerConfiguration(
        '/appdir/app.yaml').AndReturn(server_config)

    os.path.isdir('/appdir/dispatch.yaml').AndReturn(False)
    dispatch_config = DispatchConfigurationStub(
        [(None, 'default'), (None, 'fake-server')])
    application_configuration.DispatchConfiguration(
        '/appdir/dispatch.yaml').AndReturn(dispatch_config)

    self.mox.ReplayAll()
    self.assertRaises(errors.InvalidAppConfigError,
                      application_configuration.ApplicationConfiguration,
                      ['/appdir/app.yaml', '/appdir/dispatch.yaml'])
    self.mox.VerifyAll()
  def test_yaml_files_dispatch_yaml_and_no_default_module(self):
    absnames = self._make_file_hierarchy(
        ['appdir/app.yaml', 'appdir/dispatch.yaml'])

    module_config = ModuleConfigurationStub(module_name='not-default')
    application_configuration.ModuleConfiguration(
        absnames[0], None).AndReturn(module_config)

    dispatch_config = DispatchConfigurationStub([(None, 'default')])
    application_configuration.DispatchConfiguration(
        absnames[1]).AndReturn(dispatch_config)

    self.mox.ReplayAll()
    self.assertRaises(errors.InvalidAppConfigError,
                      application_configuration.ApplicationConfiguration,
                      absnames)
    self.mox.VerifyAll()