def testWithDifferentBasePath(self):
    file_system = TestFileSystem({
      'chrome_sidenav.json': json.dumps([
        { 'href': '/H1.html' },
        { 'href': '/H2.html' },
        { 'href': '/base/path/H2.html' },
        { 'href': 'https://qualified/X1.html' },
        {
          'href': 'H3.html',
          'items': [{
            'href': 'H4.html'
          }]
        },
      ])
    }, relative_to=JSON_TEMPLATES)

    expected = [
      {'href': '/base/path/H1.html', 'level': 2, 'related': True},
      {'href': '/base/path/H2.html', 'level': 2, 'selected': True, 'related': True},
      {'href': '/base/path/base/path/H2.html', 'level': 2, 'related': True},
      {'href': 'https://qualified/X1.html', 'level': 2, 'related': True},
      {'items': [
        {'href': '/base/path/H4.html', 'level': 3}
      ],
      'href': '/base/path/H3.html', 'level': 2, 'related': True}
    ]

    server_instance = ServerInstance.ForTest(file_system,
                                             base_path='/base/path/')
    sidenav_data_source = SidenavDataSource(server_instance,
                                            Request.ForTest('/H2.html'))

    log_output = CaptureLogging(
        lambda: self.assertEqual(expected, sidenav_data_source.get('chrome')))
    self.assertEqual(2, len(log_output))
  def testSidenavDataSource(self):
    file_system = TestFileSystem({
      'apps_sidenav.json': json.dumps([{
        'title': 'H1',
        'href': 'H1.html',
        'items': [{
          'title': 'H2',
          'href': '/H2.html'
        }]
      }])
    })

    expected = [{
      'level': 2,
      'child_selected': True,
      'title': 'H1',
      'href': '/H1.html',
      'items': [{
        'level': 3,
        'selected': True,
        'title': 'H2',
        'href': '/H2.html'
      }]
    }]

    sidenav_data_source = SidenavDataSource(
        FakeServerInstance(file_system), Request.ForTest('/H2.html'))

    log_output = CaptureLogging(
        lambda: self.assertEqual(expected, sidenav_data_source.get('apps')))

    self.assertEqual(1, len(log_output))
    self.assertTrue(
        log_output[0].msg.startswith('Paths in sidenav must be qualified.'))
Beispiel #3
0
  def testWithDifferentBasePath(self):
    file_system = TestFileSystem({
      'chrome_sidenav.json': json.dumps([
        { 'href': '/H1.html' },
        { 'href': '/H2.html' },
        { 'href': '/base/path/H2.html' },
        { 'href': 'https://qualified/X1.html' },
        {
          'href': 'H3.html',
          'items': [{
            'href': 'H4.html'
          }]
        },
      ])
    }, relative_to=JSON_TEMPLATES)

    expected = [
      {'href': '/base/path/H1.html', 'level': 2, 'related': True},
      {'href': '/base/path/H2.html', 'level': 2, 'selected': True, 'related': True},
      {'href': '/base/path/base/path/H2.html', 'level': 2, 'related': True},
      {'href': 'https://qualified/X1.html', 'level': 2, 'related': True},
      {'items': [
        {'href': '/base/path/H4.html', 'level': 3}
      ],
      'href': '/base/path/H3.html', 'level': 2, 'related': True}
    ]

    server_instance = ServerInstance.ForTest(file_system,
                                             base_path='/base/path/')
    sidenav_data_source = SidenavDataSource(server_instance,
                                            Request.ForTest('/H2.html'))

    log_output = CaptureLogging(
        lambda: self.assertEqual(expected, sidenav_data_source.get('chrome')))
    self.assertEqual(2, len(log_output))
    def testSidenavDataSource(self):
        file_system = MockFileSystem(
            TestFileSystem(
                {
                    'chrome_sidenav.json':
                    json.dumps([{
                        'title': 'H1',
                        'href': 'H1.html',
                        'items': [{
                            'title': 'H2',
                            'href': '/H2.html'
                        }]
                    }])
                },
                relative_to=JSON_TEMPLATES))

        expected = [{
            'level':
            2,
            'child_selected':
            True,
            'title':
            'H1',
            'href':
            '/H1.html',
            'items': [{
                'level': 3,
                'selected': True,
                'related': True,
                'title': 'H2',
                'href': '/H2.html',
                'parent': {
                    'href': '/H1.html',
                    'title': 'H1'
                }
            }]
        }]

        sidenav_data_source = SidenavDataSource(
            ServerInstance.ForTest(file_system), Request.ForTest('/H2.html'))
        self.assertTrue(*file_system.CheckAndReset())

        log_output = CaptureLogging(lambda: self.assertEqual(
            expected, sidenav_data_source.get('chrome')))

        self.assertEqual(1, len(log_output))
        self.assertTrue(log_output[0].msg.startswith(
            'Paths in sidenav must be qualified.'))

        # Test that only a single file is read when creating the sidenav, so that
        # we can be confident in the compiled_file_system.SingleFile annotation.
        self.assertTrue(*file_system.CheckAndReset(
            read_count=1, stat_count=1, read_resolve_count=1))
    def testRefresh(self):
        file_system = TestFileSystem(
            {'chrome_sidenav.json': '[{ "title": "H1" }]'},
            relative_to=JSON_TEMPLATES)

        # Ensure Refresh doesn't rely on request.
        sidenav_data_source = SidenavDataSource(
            ServerInstance.ForTest(file_system), request=None)
        sidenav_data_source.Refresh().Get()

        # If Refresh fails, chrome_sidenav.json will not be cached, and the
        # cache_data access will fail.
        # TODO(jshumway): Make a non hack version of this check.
        sidenav_data_source._cache._file_object_store.Get(
            '%schrome_sidenav.json' % JSON_TEMPLATES).Get().cache_data
Beispiel #6
0
    def __init__(self, channel, object_store_creator_factory, svn_file_system,
                 github_file_system):
        self.svn_file_system = svn_file_system

        self.github_file_system = github_file_system

        self.compiled_fs_factory = CompiledFileSystem.Factory(
            svn_file_system, object_store_creator_factory)

        self.api_list_data_source_factory = APIListDataSource.Factory(
            self.compiled_fs_factory, svn_constants.API_PATH,
            svn_constants.PUBLIC_TEMPLATE_PATH)

        self.api_data_source_factory = APIDataSource.Factory(
            self.compiled_fs_factory, svn_constants.API_PATH)

        self.ref_resolver_factory = ReferenceResolver.Factory(
            self.api_data_source_factory, self.api_list_data_source_factory,
            object_store_creator_factory)

        self.api_data_source_factory.SetReferenceResolverFactory(
            self.ref_resolver_factory)

        # Note: samples are super slow in the dev server because it doesn't support
        # async fetch, so disable them. If you actually want to test samples, then
        # good luck, and modify _IsSamplesDisabled at the top.
        if _IsSamplesDisabled():
            svn_fs_for_samples = EmptyDirFileSystem()
        else:
            svn_fs_for_samples = self.svn_file_system
        self.samples_data_source_factory = SamplesDataSource.Factory(
            channel, svn_fs_for_samples, self.github_file_system,
            self.ref_resolver_factory, object_store_creator_factory,
            svn_constants.EXAMPLES_PATH)

        self.api_data_source_factory.SetSamplesDataSourceFactory(
            self.samples_data_source_factory)

        self.intro_data_source_factory = IntroDataSource.Factory(
            self.compiled_fs_factory, self.ref_resolver_factory,
            [svn_constants.INTRO_PATH, svn_constants.ARTICLE_PATH])

        self.sidenav_data_source_factory = SidenavDataSource.Factory(
            self.compiled_fs_factory, svn_constants.JSON_PATH)

        self.template_data_source_factory = TemplateDataSource.Factory(
            channel, self.api_data_source_factory,
            self.api_list_data_source_factory, self.intro_data_source_factory,
            self.samples_data_source_factory, self.sidenav_data_source_factory,
            self.compiled_fs_factory, self.ref_resolver_factory,
            svn_constants.PUBLIC_TEMPLATE_PATH,
            svn_constants.PRIVATE_TEMPLATE_PATH)

        self.example_zipper = ExampleZipper(self.compiled_fs_factory,
                                            svn_constants.DOCS_PATH)

        self.path_canonicalizer = PathCanonicalizer(channel,
                                                    self.compiled_fs_factory)

        self.content_cache = self.compiled_fs_factory.GetOrCreateIdentity()
  def testCron(self):
    file_system = TestFileSystem({
      'apps_sidenav.json': '[{ "title": "H1" }]' ,
      'extensions_sidenav.json': '[{ "title": "H2" }]'
    }, relative_to=JSON_TEMPLATES)

    # Ensure Cron doesn't rely on request.
    sidenav_data_source = SidenavDataSource(
        ServerInstance.ForTest(file_system), request=None)
    sidenav_data_source.Cron().Get()

    # If Cron fails, apps_sidenav.json will not be cached, and the _cache_data
    # access will fail.
    # TODO(jshumway): Make a non hack version of this check.
    sidenav_data_source._cache._file_object_store.Get(
        '%s/apps_sidenav.json' % JSON_TEMPLATES).Get()._cache_data
Beispiel #8
0
 def testAbsolutePath(self):
     sidenav_data_source = SidenavDataSource.Factory(
         self._compiled_fs_factory, self._json_path,
         '/trunk').Create('absolute_path/test.html')
     sidenav_json = sidenav_data_source.get('absolute_path')
     self.assertEqual(
         sidenav_json,
         json.loads(
             self._ReadLocalFile('absolute_path_sidenav_expected.json')))
  def testSidenavDataSource(self):
    file_system = MockFileSystem(TestFileSystem({
      'chrome_sidenav.json': json.dumps([{
        'title': 'H1',
        'href': 'H1.html',
        'items': [{
          'title': 'H2',
          'href': '/H2.html'
        }]
      }])
    }, relative_to=JSON_TEMPLATES))

    expected = [{
      'level': 2,
      'child_selected': True,
      'title': 'H1',
      'href': '/H1.html',
      'items': [{
        'level': 3,
        'selected': True,
        'related': True,
        'title': 'H2',
        'href': '/H2.html',
        'parent': { 'href': '/H1.html', 'title': 'H1'}
      }]
    }]

    sidenav_data_source = SidenavDataSource(
        ServerInstance.ForTest(file_system), Request.ForTest('/H2.html'))
    self.assertTrue(*file_system.CheckAndReset())

    log_output = CaptureLogging(
        lambda: self.assertEqual(expected, sidenav_data_source.get('chrome')))

    self.assertEqual(1, len(log_output))
    self.assertTrue(
        log_output[0].msg.startswith('Paths in sidenav must be qualified.'))

    # Test that only a single file is read when creating the sidenav, so that
    # we can be confident in the compiled_file_system.SingleFile annotation.
    self.assertTrue(*file_system.CheckAndReset(
        read_count=1, stat_count=1, read_resolve_count=1))
Beispiel #10
0
    def __init__(self, channel, object_store_creator_factory, svn_file_system,
                 github_file_system):
        self.svn_file_system = svn_file_system

        self.github_file_system = github_file_system

        self.compiled_fs_factory = CompiledFileSystem.Factory(
            svn_file_system, object_store_creator_factory)

        self.api_list_data_source_factory = APIListDataSource.Factory(
            self.compiled_fs_factory, svn_constants.API_PATH,
            svn_constants.PUBLIC_TEMPLATE_PATH)

        self.api_data_source_factory = APIDataSource.Factory(
            self.compiled_fs_factory, svn_constants.API_PATH)

        self.ref_resolver_factory = ReferenceResolver.Factory(
            self.api_data_source_factory, self.api_list_data_source_factory,
            object_store_creator_factory)

        self.api_data_source_factory.SetReferenceResolverFactory(
            self.ref_resolver_factory)

        self.samples_data_source_factory = SamplesDataSource.Factory(
            channel, self.svn_file_system, ServerInstance.github_file_system,
            self.ref_resolver_factory, object_store_creator_factory,
            svn_constants.EXAMPLES_PATH)

        self.api_data_source_factory.SetSamplesDataSourceFactory(
            self.samples_data_source_factory)

        self.intro_data_source_factory = IntroDataSource.Factory(
            self.compiled_fs_factory, self.ref_resolver_factory,
            [svn_constants.INTRO_PATH, svn_constants.ARTICLE_PATH])

        self.sidenav_data_source_factory = SidenavDataSource.Factory(
            self.compiled_fs_factory, svn_constants.JSON_PATH)

        self.template_data_source_factory = TemplateDataSource.Factory(
            channel, self.api_data_source_factory,
            self.api_list_data_source_factory, self.intro_data_source_factory,
            self.samples_data_source_factory, self.sidenav_data_source_factory,
            self.compiled_fs_factory, self.ref_resolver_factory,
            svn_constants.PUBLIC_TEMPLATE_PATH,
            svn_constants.PRIVATE_TEMPLATE_PATH)

        self.example_zipper = ExampleZipper(self.compiled_fs_factory,
                                            svn_constants.DOCS_PATH)

        self.path_canonicalizer = PathCanonicalizer(channel,
                                                    self.compiled_fs_factory)

        self.content_cache = self.compiled_fs_factory.GetOrCreateIdentity()
Beispiel #11
0
 def testSelected(self):
     sidenav_data_source = SidenavDataSource.Factory(
         self._compiled_fs_factory, self._base_path).Create('www.b.com')
     sidenav_json = sidenav_data_source.get('test')
     # This will be prettier once JSON is loaded with an OrderedDict.
     for item in sidenav_json:
         if item['title'] == 'Jim':
             self.assertTrue(item.get('child_selected', False))
             for next_item in item['items']:
                 if next_item['title'] == 'B':
                     self.assertTrue(next_item.get('selected', False))
                     return
     # If we didn't return already, we should fail.
     self.fail()
Beispiel #12
0
def _GetInstanceForBranch(channel_name, local_path):
    branch = BRANCH_UTILITY.GetBranchNumberForChannelName(channel_name)

    # The key for the server is a tuple of |channel_name| with |branch|, since
    # sometimes stable and beta point to the same branch.
    instance_key = _MakeInstanceKey(channel_name, branch)
    instance = SERVER_INSTANCES.get(instance_key, None)
    if instance is not None:
        return instance

    branch_memcache = InMemoryObjectStore(branch)
    if branch == 'local':
        file_system = LocalFileSystem(local_path)
    else:
        file_system = _CreateMemcacheFileSystem(branch, branch_memcache)

    cache_factory = CompiledFileSystem.Factory(file_system, branch_memcache)
    api_list_data_source_factory = APIListDataSource.Factory(
        cache_factory, file_system, API_PATH, PUBLIC_TEMPLATE_PATH)
    intro_data_source_factory = IntroDataSource.Factory(
        cache_factory, [INTRO_PATH, ARTICLE_PATH])
    api_data_source_factory = APIDataSource.Factory(cache_factory, API_PATH)

    # Give the ReferenceResolver a memcache, to speed up the lookup of
    # duplicate $refs.
    ref_resolver_factory = ReferenceResolver.Factory(
        api_data_source_factory, api_list_data_source_factory, branch_memcache)
    api_data_source_factory.SetReferenceResolverFactory(ref_resolver_factory)
    samples_data_source_factory = SamplesDataSource.Factory(
        channel_name, file_system, GITHUB_FILE_SYSTEM, cache_factory,
        GITHUB_COMPILED_FILE_SYSTEM, ref_resolver_factory, EXAMPLES_PATH)
    api_data_source_factory.SetSamplesDataSourceFactory(
        samples_data_source_factory)
    sidenav_data_source_factory = SidenavDataSource.Factory(
        cache_factory, JSON_PATH)
    template_data_source_factory = TemplateDataSource.Factory(
        channel_name, api_data_source_factory, api_list_data_source_factory,
        intro_data_source_factory, samples_data_source_factory,
        KNOWN_ISSUES_DATA_SOURCE, sidenav_data_source_factory, cache_factory,
        PUBLIC_TEMPLATE_PATH, PRIVATE_TEMPLATE_PATH)
    example_zipper = ExampleZipper(file_system, cache_factory, DOCS_PATH)

    instance = ServerInstance(template_data_source_factory, example_zipper,
                              cache_factory)
    SERVER_INSTANCES[instance_key] = instance
    return instance
Beispiel #13
0
 def testLevels(self):
     sidenav_data_source = SidenavDataSource.Factory(
         self._compiled_fs_factory, self._base_path).Create('')
     sidenav_json = sidenav_data_source.get('test')
     self._CheckLevels(sidenav_json)
Beispiel #14
0
    def __init__(self, channel, object_store_creator, host_file_system,
                 app_samples_file_system, base_path, compiled_fs_factory):
        self.channel = channel

        self.object_store_creator = object_store_creator

        self.host_file_system = host_file_system

        self.app_samples_file_system = app_samples_file_system

        self.compiled_host_fs_factory = compiled_fs_factory

        self.api_list_data_source_factory = APIListDataSource.Factory(
            self.compiled_host_fs_factory, svn_constants.API_PATH,
            svn_constants.PUBLIC_TEMPLATE_PATH)

        self.api_data_source_factory = APIDataSource.Factory(
            self.compiled_host_fs_factory, svn_constants.API_PATH)

        self.ref_resolver_factory = ReferenceResolver.Factory(
            self.api_data_source_factory, self.api_list_data_source_factory,
            object_store_creator)

        self.api_data_source_factory.SetReferenceResolverFactory(
            self.ref_resolver_factory)

        # Note: samples are super slow in the dev server because it doesn't support
        # async fetch, so disable them.
        if IsDevServer():
            extension_samples_fs = EmptyDirFileSystem()
        else:
            extension_samples_fs = self.host_file_system
        self.samples_data_source_factory = SamplesDataSource.Factory(
            channel, extension_samples_fs,
            CompiledFileSystem.Factory(extension_samples_fs,
                                       object_store_creator),
            self.app_samples_file_system,
            CompiledFileSystem.Factory(self.app_samples_file_system,
                                       object_store_creator),
            self.ref_resolver_factory, svn_constants.EXAMPLES_PATH)

        self.api_data_source_factory.SetSamplesDataSourceFactory(
            self.samples_data_source_factory)

        self.intro_data_source_factory = IntroDataSource.Factory(
            self.compiled_host_fs_factory, self.ref_resolver_factory,
            [svn_constants.INTRO_PATH, svn_constants.ARTICLE_PATH])

        self.sidenav_data_source_factory = SidenavDataSource.Factory(
            self.compiled_host_fs_factory, svn_constants.JSON_PATH, base_path)

        self.template_data_source_factory = TemplateDataSource.Factory(
            channel, self.api_data_source_factory,
            self.api_list_data_source_factory, self.intro_data_source_factory,
            self.samples_data_source_factory, self.sidenav_data_source_factory,
            self.compiled_host_fs_factory, self.ref_resolver_factory,
            svn_constants.PUBLIC_TEMPLATE_PATH,
            svn_constants.PRIVATE_TEMPLATE_PATH, base_path)

        self.example_zipper = ExampleZipper(self.compiled_host_fs_factory,
                                            svn_constants.DOCS_PATH)

        self.path_canonicalizer = PathCanonicalizer(
            channel, self.compiled_host_fs_factory)

        self.content_cache = self.compiled_host_fs_factory.CreateIdentity(
            ServerInstance)
    def __init__(self, object_store_creator, host_file_system,
                 app_samples_file_system, base_path, compiled_fs_factory,
                 branch_utility, host_file_system_creator):
        self.object_store_creator = object_store_creator

        self.host_file_system = host_file_system

        self.app_samples_file_system = app_samples_file_system

        self.compiled_host_fs_factory = compiled_fs_factory

        self.host_file_system_creator = host_file_system_creator

        self.availability_finder_factory = AvailabilityFinder.Factory(
            object_store_creator, self.compiled_host_fs_factory,
            branch_utility, host_file_system_creator)

        self.api_list_data_source_factory = APIListDataSource.Factory(
            self.compiled_host_fs_factory, self.host_file_system,
            svn_constants.API_PATH, svn_constants.PUBLIC_TEMPLATE_PATH)

        self.api_data_source_factory = APIDataSource.Factory(
            self.compiled_host_fs_factory, svn_constants.API_PATH,
            self.availability_finder_factory)

        self.ref_resolver_factory = ReferenceResolver.Factory(
            self.api_data_source_factory, self.api_list_data_source_factory,
            object_store_creator)

        self.api_data_source_factory.SetReferenceResolverFactory(
            self.ref_resolver_factory)

        # Note: samples are super slow in the dev server because it doesn't support
        # async fetch, so disable them.
        if IsDevServer():
            extension_samples_fs = EmptyDirFileSystem()
        else:
            extension_samples_fs = self.host_file_system
        self.samples_data_source_factory = SamplesDataSource.Factory(
            extension_samples_fs,
            CompiledFileSystem.Factory(extension_samples_fs,
                                       object_store_creator),
            self.app_samples_file_system,
            CompiledFileSystem.Factory(self.app_samples_file_system,
                                       object_store_creator),
            self.ref_resolver_factory, svn_constants.EXAMPLES_PATH, base_path)

        self.api_data_source_factory.SetSamplesDataSourceFactory(
            self.samples_data_source_factory)

        self.intro_data_source_factory = IntroDataSource.Factory(
            self.compiled_host_fs_factory, self.ref_resolver_factory,
            [svn_constants.INTRO_PATH, svn_constants.ARTICLE_PATH])

        self.sidenav_data_source_factory = SidenavDataSource.Factory(
            self.compiled_host_fs_factory, svn_constants.JSON_PATH)

        self.manifest_data_source = ManifestDataSource(
            self.compiled_host_fs_factory, host_file_system, '/'.join(
                (svn_constants.JSON_PATH, 'manifest.json')), '/'.join(
                    (svn_constants.API_PATH, '_manifest_features.json')))

        self.template_data_source_factory = TemplateDataSource.Factory(
            self.api_data_source_factory, self.api_list_data_source_factory,
            self.intro_data_source_factory, self.samples_data_source_factory,
            self.sidenav_data_source_factory, self.compiled_host_fs_factory,
            self.ref_resolver_factory, self.manifest_data_source,
            svn_constants.PUBLIC_TEMPLATE_PATH,
            svn_constants.PRIVATE_TEMPLATE_PATH, base_path)

        self.api_data_source_factory.SetTemplateDataSource(
            self.template_data_source_factory)

        self.example_zipper = ExampleZipper(self.compiled_host_fs_factory,
                                            self.host_file_system,
                                            svn_constants.DOCS_PATH)

        self.path_canonicalizer = PathCanonicalizer(
            self.compiled_host_fs_factory)

        self.redirector = Redirector(self.compiled_host_fs_factory,
                                     self.host_file_system,
                                     svn_constants.PUBLIC_TEMPLATE_PATH)