Example #1
0
    def testSidebarBuilds(self):
        """Test that the sidebar builds and does not return None.
    """

        callback.getCore().startNewRequest(None)
        self.assertNotEqual(None, callback.getCore().getSidebar('id', None))
        callback.getCore().endRequest(None, False)
Example #2
0
  def testSidebarBuilds(self):
    """Test that the sidebar builds and does not return None.
    """

    account = users.User()
    callback.getCore().startNewRequest(None)
    self.assertNotEqual(None, callback.getCore().getSidebar(account, None))
    callback.getCore().endRequest(None, False)
Example #3
0
def main():
    sys.path = extra_paths + sys.path
    os.environ['SERVER_SOFTWARE'] = 'Development via nose'
    os.environ['SERVER_NAME'] = 'Foo'
    os.environ['SERVER_PORT'] = '8080'
    os.environ['APPLICATION_ID'] = 'test-app-run'
    os.environ['USER_EMAIL'] = '*****@*****.**'
    os.environ['CURRENT_VERSION_ID'] = 'testing-version'
    os.environ['HTTP_HOST'] = 'some.testing.host.tld'
    import main as app_main
    from google.appengine.api import apiproxy_stub_map
    from google.appengine.api import datastore_file_stub
    from google.appengine.api import mail_stub
    from google.appengine.api import user_service_stub
    from google.appengine.api import urlfetch_stub
    from google.appengine.api.memcache import memcache_stub
    apiproxy_stub_map.apiproxy = apiproxy_stub_map.APIProxyStubMap()
    apiproxy_stub_map.apiproxy.RegisterStub(
        'urlfetch', urlfetch_stub.URLFetchServiceStub())
    apiproxy_stub_map.apiproxy.RegisterStub(
        'user', user_service_stub.UserServiceStub())
    apiproxy_stub_map.apiproxy.RegisterStub(
        'datastore',
        datastore_file_stub.DatastoreFileStub('test-app-run', None, None))
    apiproxy_stub_map.apiproxy.RegisterStub(
        'memcache', memcache_stub.MemcacheServiceStub())
    apiproxy_stub_map.apiproxy.RegisterStub('mail',
                                            mail_stub.MailServiceStub())
    import django.test.utils
    django.test.utils.setup_test_environment()

    # register a core for the test modules to use
    from soc.modules import callback
    from soc.modules import core

    callback.registerCore(core.Core())
    callback.getCore().registerModuleCallbacks()

    plugins = [AppEngineDatastoreClearPlugin()]

    if '--coverage' in sys.argv:
        from nose.plugins import cover
        plugin = cover.Coverage()
        plugins.append(plugin)

        args = [
            '--with-coverage', '--cover-package=soc', '--cover-erase',
            '--cover-html', '--cover-html-dir=coverageResults'
        ]

        sys.argv.remove('--coverage')
        sys.argv += args

    nose.main(plugins=plugins)
Example #4
0
def load_melange():
  """Prepare Melange for usage.

  Registers a core, the GSoC and GCI modules, and calls the sitemap, sidebar
  and rights services.
  """
  from soc.modules import callback
  from soc.modules.core import Core

  # Register a core for the test modules to use
  callback.registerCore(Core())
  current_core = callback.getCore()

  callback_module_names = [
      'codein.callback',
      'melange.callback',
      'soc.modules.soc_core.callback',
      'soc.modules.gsoc.callback',
      'soc.modules.gci.callback',
      'summerofcode.callback'
      ]

  current_core.registerModuleCallbacks(callback_module_names)

  # Make sure all services are called
  current_core.callService('registerViews', True)
  current_core.callService('registerWithSitemap', True)
  current_core.callService('registerWithSidebar', True)
  current_core.callService('registerRights', True)
Example #5
0
def load_melange():
    """Prepare Melange for usage.

  Registers a core, the GSoC and GCI modules, and calls the sitemap, sidebar
  and rights services.
  """
    from soc.modules import callback
    from soc.modules.core import Core

    # Register a core for the test modules to use
    callback.registerCore(Core())
    current_core = callback.getCore()

    callback_module_names = [
        'codein.callback', 'melange.callback', 'soc.modules.soc_core.callback',
        'soc.modules.gsoc.callback', 'soc.modules.gci.callback',
        'summerofcode.callback'
    ]

    current_core.registerModuleCallbacks(callback_module_names)

    # Make sure all services are called
    current_core.callService('registerViews', True)
    current_core.callService('registerWithSitemap', True)
    current_core.callService('registerWithSidebar', True)
    current_core.callService('registerRights', True)
Example #6
0
def real_main():
  """Main program without profiling.
  """
  import django.core.handlers.wsgi

  # Create a Django application for WSGI.
  application = django.core.handlers.wsgi.WSGIHandler()

  from soc.modules import callback
  from soc.modules import core

  callback.registerCore(core.Core())
  callback.getCore().registerModuleCallbacks()

  # Run the WSGI CGI handler with that application.
  util.run_wsgi_app(application)
Example #7
0
def real_main():
    """Main program without profiling.
  """
    import django.core.handlers.wsgi

    # Create a Django application for WSGI.
    application = django.core.handlers.wsgi.WSGIHandler()

    from soc.modules import callback
    from soc.modules import core

    callback.registerCore(core.Core())
    callback.getCore().registerModuleCallbacks()

    # Run the WSGI CGI handler with that application.
    util.run_wsgi_app(application)
Example #8
0
  def start(self, request):
    """Sets up the value store.

    Args:
      request: a Django HttpRequest object
    """

    core = callback.getCore()
    core.startNewRequest(request)
Example #9
0
def getProgramMap():
    # TODO(nathaniel): Magic string? This isn't a program.
    choices = [('', '-----')]

    # TODO(nathaniel): Eliminate the circularity behind this non-top-level
    # import.
    from soc.modules import callback
    choices += callback.getCore().getProgramMap()
    return choices
Example #10
0
def getUniversalContext(request):
  """Constructs a template context dict will many common variables defined.
  
  Args:
    request: the Django HTTP request object

  Returns:
    a new context dict containing:
    
    {
      'request': the Django HTTP request object passed in by the caller
      'account': the logged-in Google Account if there is one
      'user': the User entity corresponding to the Google Account in
        context['account']
      'is_admin': True if users.is_current_user_admin() is True
      'is_debug': True if system.isDebug() is True
      'sign_in': a Google Account login URL
      'sign_out': a Google Account logout URL
      'sidebar_menu_html': an HTML string that renders the sidebar menu
    }
  """

  account = accounts.getCurrentAccount()
  user = None
  is_admin = False

  context = {}
  context['request'] = request

  if account:
    user = user_logic.getForAccount(account)
    is_admin = user_logic.isDeveloper(account=account, user=user)

  context['account'] = account
  context['user'] = user
  context['is_admin'] = is_admin

  context['is_local'] = system.isLocal()
  context['is_debug'] = system.isDebug()
  context['sign_in'] = users.create_login_url(request.path)
  context['sign_out'] = users.create_logout_url(request.path)

  context['sidebar_menu_items'] = callback.getCore().getSidebar(account, user)

  context['gae_version'] = system.getAppVersion()
  context['soc_release'] = system.getMelangeVersion()

  settings = site.logic.getSingleton()

  context['ga_tracking_num'] = settings.ga_tracking_num
  context['gmaps_api_key'] = settings.gmaps_api_key
  context['site_name'] = settings.site_name
  context['site_notice'] = settings.site_notice
  context['tos_link'] = redirects.getToSRedirect(settings)
  context['in_maintenance'] = timeline.isActivePeriod(site, 'maintenance')
 
  return context
Example #11
0
def getProgramMap():
  # TODO(nathaniel): Magic string? This isn't a program.
  choices = [('', '-----')]

  # TODO(nathaniel): Eliminate the circularity behind this non-top-level
  # import.
  from soc.modules import callback
  choices += callback.getCore().getProgramMap()
  return choices
Example #12
0
  def end(self, request, optional):
    """Empties the value store.

    Args:
      request: a Django HttpRequest object
    """

    core = callback.getCore()
    core.endRequest(request, optional)
Example #13
0
def load_melange():
    """Prepare Melange for usage.

  Registers a core, the GSoC and GCI modules, and calls the sitemap, sidebar
  and rights services.
  """

    from soc.modules import callback
    from soc.modules.core import Core

    # Register a core for the test modules to use
    callback.registerCore(Core())
    current_core = callback.getCore()
    modules = ['gsoc', 'gci', 'seeder', 'statistic']
    fmt = 'soc.modules.%s.callback'
    current_core.registerModuleCallbacks(modules, fmt)

    # Make sure all services are called
    current_core.callService('registerViews', True)
    current_core.callService('registerWithSitemap', True)
    current_core.callService('registerWithSidebar', True)
    current_core.callService('registerRights', True)
Example #14
0
def load_melange():
  """Prepare Melange for usage.

  Registers a core, the GSoC and GCI modules, and calls the sitemap, sidebar
  and rights services.
  """

  from soc.modules import callback
  from soc.modules.core import Core

  # Register a core for the test modules to use
  callback.registerCore(Core())
  current_core = callback.getCore()
  modules = ['gsoc', 'gci', 'seeder', 'statistic']
  fmt = 'soc.modules.%s.callback'
  current_core.registerModuleCallbacks(modules, fmt)

  # Make sure all services are called
  current_core.callService('registerViews', True)
  current_core.callService('registerWithSitemap', True)
  current_core.callService('registerWithSidebar', True)
  current_core.callService('registerRights', True)
Example #15
0
    def start(self):
        """Readies the core for a new request.
    """

        core = callback.getCore()
        core.startNewRequest(self)
Example #16
0
    def end(self):
        """Finishes up the current request.
    """

        core = callback.getCore()
        core.endRequest(self, False)
Example #17
0
# Copyright 2008 the Melange authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Module containing Melange URL patterns definition.
"""

from soc.modules import callback

urlpatterns = callback.getCore().getPatterns()

# define the error handlers
handler404 = 'soc.views.errors.handle404'
handler500 = 'soc.views.errors.handle500'
Example #18
0
def getProgramMap():
    choices = [('', 'Active program')]
    choices += callback.getCore().getProgramMap()
    return choices
Example #19
0
def getUniversalContext(request):
    """Constructs a template context dict will many common variables defined.

  Args:
    request: the Django HTTP request object

  Returns:
    a new context dict containing:

    {
      'request': the Django HTTP request object passed in by the caller
      'account': the logged-in Google Account if there is one
      'user': the User entity corresponding to the Google Account in
        context['account']
      'is_admin': True if users.is_current_user_admin() is True
      'is_debug': True if system.isDebug() is True
      'sign_in': a Google Account login URL
      'sign_out': a Google Account logout URL
      'sidebar_menu_html': an HTML string that renders the sidebar menu
    }
  """

    core = callback.getCore()

    context = core.getRequestValue('context', {})

    if context:
        return context

    account = accounts.getCurrentAccount()
    user = None
    is_admin = False

    context['request'] = request

    if account:
        user = user_logic.getForAccount(account)
        is_admin = user_logic.isDeveloper(account=account, user=user)

    context['account'] = account
    context['user'] = user
    context['is_admin'] = is_admin

    context['is_local'] = system.isLocal()
    context['is_debug'] = system.isDebug()
    context['sign_in'] = users.create_login_url(request.path)
    context['sign_out'] = users.create_logout_url(request.path)

    context['sidebar_menu_items'] = core.getSidebar(account, user)

    context['gae_version'] = system.getAppVersion()
    context['soc_release'] = system.getMelangeVersion()

    settings = site.logic.getSingleton()

    context['ga_tracking_num'] = settings.ga_tracking_num
    context['gmaps_api_key'] = settings.gmaps_api_key
    context['site_name'] = settings.site_name
    context['site_notice'] = settings.site_notice
    context['tos_link'] = redirects.getToSRedirect(settings)
    context['in_maintenance'] = timeline.isActivePeriod(
        settings, 'maintenance')

    # Only one xsrf_token is generated per request.
    xsrf_secret_key = site.logic.getXsrfSecretKey(settings)
    context['xsrf_token'] = xsrfutil.getGeneratedTokenForCurrentUser(
        xsrf_secret_key)

    core.setRequestValue('context', context)

    return context
Example #20
0
    def end(self):
        """Finishes up the current request.
    """

        core = callback.getCore()
        core.endRequest(self, False)
Example #21
0
    def start(self):
        """Readies the core for a new request.
    """

        core = callback.getCore()
        core.startNewRequest(self)
Example #22
0
# Copyright 2008 the Melange authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Module containing Melange URL patterns definition.
"""


from soc.modules import callback

urlpatterns = callback.getCore().getPatterns()

# define the error handlers
handler404 = 'django.views.defaults.page_not_found'
handler500 = 'django.views.defaults.server_error'
Example #23
0
def getProgramMap():
  choices = [('', 'Active program')]
  choices += callback.getCore().getProgramMap()
  return choices