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])
예제 #2
0
  def test_module_for_request(self):

    class FakeDict(dict):
      def __contains__(self, key):
        return True

      def __getitem__(self, key):
        return key

    self.dispatcher._module_name_to_module = FakeDict()
    self.dispatch_config.dispatch = [
        (dispatchinfo.ParsedURL('*/path'), '1'),
        (dispatchinfo.ParsedURL('*/other_path/*'), '2'),
        (dispatchinfo.ParsedURL('*/other_path/'), '3'),
        (dispatchinfo.ParsedURL('*/other_path'), '3'),
        ]
    self.assertEqual('1', self.dispatcher._module_for_request('/path'))
    self.assertEqual('2', self.dispatcher._module_for_request('/other_path/'))
    self.assertEqual('2', self.dispatcher._module_for_request('/other_path/a'))
    self.assertEqual('3',
                     self.dispatcher._module_for_request('/other_path'))
    self.assertEqual('default',
                     self.dispatcher._module_for_request('/undispatched'))
예제 #3
0
 def _process_dispatch_entries(self, dispatch_info_external):
     path_only_entries = []
     hostname_entries = []
     for entry in dispatch_info_external.dispatch:
         parsed_url = dispatchinfo.ParsedURL(entry.url)
         if parsed_url.host:
             hostname_entries.append(entry)
         else:
             path_only_entries.append((parsed_url, entry.module))
     if hostname_entries:
         logging.warning(
             'Hostname routing is not supported by the development server. The '
             'following dispatch entries will not match any requests:\n%s',
             '\n\t'.join(str(entry) for entry in hostname_entries))
     self._entries = path_only_entries