Esempio n. 1
0
 def _GetInstanceForBranch(self, branch):
     if branch in SERVER_INSTANCES:
         return SERVER_INSTANCES[branch]
     if branch == 'local':
         fetcher = LocalFetcher(EXTENSIONS_PATH)
         # No cache for local doc server.
         cache_timeout_seconds = 0
     else:
         fetcher = SubversionFetcher(branch, EXTENSIONS_PATH, urlfetch)
         cache_timeout_seconds = 300
     cache_builder = FetcherCache.Builder(fetcher, cache_timeout_seconds)
     api_data_source = APIDataSource(cache_builder, API_PATH)
     intro_data_source = IntroDataSource(cache_builder,
                                         [INTRO_PATH, ARTICLE_PATH])
     samples_data_source = SamplesDataSource(fetcher, cache_builder,
                                             EXAMPLES_PATH)
     template_data_source = TemplateDataSource(
         branch, api_data_source, intro_data_source, samples_data_source,
         cache_builder, [PUBLIC_TEMPLATE_PATH, PRIVATE_TEMPLATE_PATH])
     example_zipper = ExampleZipper(fetcher, cache_builder, DOCS_PATH,
                                    EXAMPLES_PATH)
     SERVER_INSTANCES[branch] = ServerInstance(template_data_source,
                                               example_zipper,
                                               cache_builder)
     return SERVER_INSTANCES[branch]
 def testPartials(self):
   self._base_path = os.path.join(self._base_path, 'partials')
   fetcher = LocalFetcher(self._base_path)
   cache_builder = FetcherCache.Builder(fetcher, 0)
   t_data_source = self._CreateTemplateDataSource(self._fake_api_data_source,
                                                   cache_builder)
   self.assertEqual(self._ReadLocalFile('test_expected.html'),
       t_data_source['test_tmpl'].render(
           json.loads(self._ReadLocalFile('input.json')), t_data_source).text)
Esempio n. 3
0
  def testSimple(self):
    fetcher = LocalFetcher(self._base_path)
    cache_builder = FetcherCache.Builder(fetcher, 0)
    data_source = APIDataSource(cache_builder, './')

    # Take the dict out of the list.
    expected = json.loads(self._ReadLocalFile('expected_test_file.json'))
    self.assertEqual(expected, data_source['test_file'])
    self.assertEqual(expected, data_source['testFile'])
    self.assertEqual(expected, data_source['testFile.html'])

    self.assertEqual(None, data_source['junk'])
 def testRender(self):
   self._base_path = os.path.join(self._base_path, 'render')
   fetcher = LocalFetcher(self._base_path)
   context = json.loads(self._ReadLocalFile('test1.json'))
   cache_builder = FetcherCache.Builder(fetcher, 0)
   self._RenderTest(
       'test1',
       self._CreateTemplateDataSource(
           json.loads(self._ReadLocalFile('test1.json')),
                          cache_builder))
   self._RenderTest(
       'test2',
       self._CreateTemplateDataSource(
           json.loads(self._ReadLocalFile('test2.json')),
                          cache_builder))
  def testSimple(self):
    self._base_path = os.path.join(self._base_path, 'simple')
    fetcher = LocalFetcher(self._base_path)
    cache_builder = FetcherCache.Builder(fetcher, 0)
    t_data_source = self._CreateTemplateDataSource(self._fake_api_data_source,
                                                    cache_builder)
    template_a1 = Handlebar(self._ReadLocalFile('test1.html'))
    self.assertEqual(template_a1.render({}, {'templates': {}}).text,
        t_data_source['test1'].render({}, {'templates': {}}).text)

    template_a2 = Handlebar(self._ReadLocalFile('test2.html'))
    self.assertEqual(template_a2.render({}, {'templates': {}}).text,
        t_data_source['test2'].render({}, {'templates': {}}).text)

    self.assertEqual(None, t_data_source['junk.html'])
Esempio n. 6
0
 def _GetInstanceForBranch(self, branch):
   if branch in SERVER_INSTANCES:
     return SERVER_INSTANCES[branch]
   if branch == 'local':
     fetcher = LocalFetcher(EXTENSIONS_PATH)
     # No cache for local doc server.
     cache_timeout_seconds = 0
   else:
     fetcher = SubversionFetcher(branch, EXTENSIONS_PATH, urlfetch)
     cache_timeout_seconds = 300
   cache_builder = FetcherCache.Builder(fetcher, cache_timeout_seconds)
   api_data_source = APIDataSource(cache_builder, API_PATH)
   template_data_source = TemplateDataSource(
       branch,
       api_data_source,
       cache_builder,
       [PUBLIC_TEMPLATE_PATH, PRIVATE_TEMPLATE_PATH])
   SERVER_INSTANCES[branch] = ServerInstance(
       template_data_source,
       cache_builder)
   return SERVER_INSTANCES[branch]