Exemple #1
0
    def testIsSecondaryHostName(self):
        """Tests if a request is from a secondary hostname."""
        test_data = request_data.RequestData(None, None, None)
        test_data._site = site_model.Site(link_id="test", hostname="test_host")

        try:
            os.environ["HTTP_HOST"] = "some.testing.host.tld"
            self.assertFalse(site.isSecondaryHostname())

            self.assertFalse(site.isSecondaryHostname(data=test_data))

            test_data.site.hostname = "testing"
            self.assertTrue(site.isSecondaryHostname(data=test_data))
        finally:
            if self.default_host is None:
                del os.environ["HTTP_HOST"]
            else:
                os.environ["HTTP_HOST"] = self.default_host
Exemple #2
0
  def testIsSecondaryHostName(self):
    """Tests if a request is from a secondary hostname."""
    test_data = request_data.RequestData(None, None, None)
    test_data._site = site_model.Site(link_id='test', hostname='test_host')

    try:
      os.environ['HTTP_HOST'] = 'some.testing.host.tld'
      self.assertFalse(site.isSecondaryHostname())

      self.assertFalse(site.isSecondaryHostname(data=test_data))

      test_data.site.hostname = "testing"
      self.assertTrue(site.isSecondaryHostname(data=test_data))
    finally:
      if self.default_host is None:
        del os.environ['HTTP_HOST']
      else:
        os.environ['HTTP_HOST'] = self.default_host
Exemple #3
0
def default(data):
  """Returns a context dictionary with default values set.

  The following values are available:
      app_version: the current version string of the application
      is_local: whether we are running locally
      posted: if this was a post/redirect-after-post request
      xsrf_token: the xstrf_token for this request
      google_api_key: the google api key for this website
      ga_tracking_num: the google tracking number for this website
      ds_write_disabled: if datastore writes are disabled
      css_path: part of the path to the css files to distinguish modules
  """
  app_version = system.getMelangeVersion()

  posted = data.request.POST or 'validated' in data.request.GET

  xsrf_secret_key = site.xsrfSecretKey(data.site)
  xsrf_token = xsrfutil.getGeneratedTokenForCurrentUser(xsrf_secret_key)

  if site.isSecondaryHostname(data):
    google_api_key = data.site.secondary_google_api_key
  else:
    google_api_key = data.site.google_api_key

  css_path = '/'.join([
      'soc', 'content', app_version, 'css', data.css_path])

  return {
      'app_version': app_version,
      'is_local': system.isLocal(),
      'posted': posted,
      'xsrf_token': xsrf_token,
      'google_api_key': google_api_key,
      'ga_tracking_num': data.site.ga_tracking_num,
      'ds_write_disabled': data.ds_write_disabled,
      'css_path': css_path,
      'site_description': data.site.description,
  }
Exemple #4
0
def default(data):
    """Returns a context dictionary with default values set.

  The following values are available:
      app_version: the current version string of the application
      is_local: whether we are running locally
      posted: if this was a post/redirect-after-post request
      xsrf_token: the xstrf_token for this request
      google_api_key: the google api key for this website
      ga_tracking_num: the google tracking number for this website
      ds_write_disabled: if datastore writes are disabled
      css_path: part of the path to the css files to distinguish modules
  """
    app_version = system.getMelangeVersion()

    posted = data.request.POST or 'validated' in data.request.GET

    xsrf_secret_key = site.xsrfSecretKey(data.site)
    xsrf_token = xsrfutil.getGeneratedTokenForCurrentUser(xsrf_secret_key)

    if site.isSecondaryHostname(data):
        google_api_key = data.site.secondary_google_api_key
    else:
        google_api_key = data.site.google_api_key

    css_path = '/'.join(['soc', 'content', app_version, 'css', data.css_path])

    return {
        'app_version': app_version,
        'is_local': system.isLocal(),
        'posted': posted,
        'xsrf_token': xsrf_token,
        'google_api_key': google_api_key,
        'ga_tracking_num': data.site.ga_tracking_num,
        'ds_write_disabled': data.ds_write_disabled,
        'css_path': css_path,
        'site_description': data.site.description,
    }