Commits

Tom Willis  committed 5e22882

new unit test files

  • Participants
  • Parent commits b1fea61

Comments (0)

Files changed (5)

File tests/test_as_bfg.py

+"""
+functionality specific to when identity.model ia a part of a bfg application
+"""
+from identity.model.apps.auth.models import appmaker as auth_appmaker
+from identity.model.apps.register.models import appmaker as register_appmaker
+from identity.model.apps.password.models import appmaker as password_appmaker
+from identity.model.apps.manager.models import appmaker as manage_appmaker
+from repoze.bfg.configuration import Configurator
+from identity.model.apps.auth import login_url, logout_url
+from identity.model.apps.register import register_url
+from identity.model.apps.password import reset_url
+from settings import GLOBAL_APP_CONFIG, \
+     REGISTER_APP_CONFIG,\
+     RESET_APP_CONFIG,\
+     MANAGER_APP_CONFIG, \
+     AUTH_APP_CONFIG
+from webtest import TestApp
+from repoze.tm import make_tm
+import os
+import sys
+from webob import Response,Request
+from repoze.bfg.registry import global_registry
+
+pardir = os.path.dirname(__file__)
+sys.path.append(pardir)
+
+CONFIG = {}
+CONFIG.update(AUTH_APP_CONFIG)
+CONFIG.update(MANAGER_APP_CONFIG)
+CONFIG.update(RESET_APP_CONFIG)
+CONFIG.update(REGISTER_APP_CONFIG)
+CONFIG["debug_all"] = True
+GLOBAL_APP_CONFIG["debug_all"] = True
+
+
+class AppRoot(object):
+    __name__=None
+    __parent__ = None
+
+    def __init__(self, config):
+
+        self.models = {
+            "auth": auth_appmaker(config)(None),
+            "register": register_appmaker(config)(None),
+            "reset": password_appmaker(config)(None),
+            "manage": manage_appmaker(config)(None)}
+
+        for k, v in self.models.items():
+            v.__name__ = k
+            v.__parent__ = self
+
+    def __getitem__(self, key):
+        print key
+        return self.models[key]
+
+    def current_user(self, request):
+        from identity.model.apps.auth import get_current_user
+        return get_current_user(request)
+
+    def _login_url(self, request):
+        return login_url(request)
+
+    def _logout_url(self, request):
+        return logout_url(request)
+
+    def _register_url(self, request):
+        return register_url(request)
+
+    def _reset_url(self, request):
+        return reset_url(request)
+
+PAGE = u"""
+<html>
+ <head>
+  <title>Mah Site</title>
+ </head>
+ <body>
+   <ul>
+    <li><a href="%(link_url)s">%(link_label)s</a></li>
+    <li><a href="%(reset_url)s">%(reset_label)s</a></li>
+    <li><a href="%(register_url)s">%(register_label)s</a></li>
+   </ul>
+   <h1> HI %(user)s</h1>
+ </body>
+</html>
+"""
+
+
+def view_bfg_root(context, request):
+    """
+    no really this is the view to call
+    """
+    raise
+    user = context.current_user(request)
+    if user:
+        user = user.user_name
+    else:
+        user = None
+
+    if user:
+        page = PAGE % dict(
+            link_label = "Logout",
+            link_url = context._logout_url(request),
+            reset_label = "Reset", reset_url = context._reset_url(request),
+            register_url = "", register_label = "", user = user)
+    else:
+        page = PAGE % dict(
+            link_label = "Login",
+            link_url = context._login_url(request),
+            reset_label = "Reset",
+            reset_url = context._reset_url(request),
+            register_url = context._register_url(request),
+            register_label = "Register",
+            user = user)
+
+    return Response(page)
+
+
+def app(global_config, **settings):
+    _config = {}
+    _config.update(global_config)
+    _config.update(settings)
+
+    app_root = AppRoot(_config)
+
+    def _x(request):
+        return app_root
+
+    registry = global_registry
+    config = Configurator(
+        registry = registry)
+    config.setup_registry(root_factory = _x)
+    config.load_zcml('test_as_bfg.zcml')
+    return config.make_wsgi_app()
+
+
+class TestAsBfg(object):
+#    def setup(self):
+#        from repoze.bfg.testing import setUp
+#        setUp()
+#    def teardown(self):
+#        from repoze.bfg.testing import tearDown
+#        tearDown()
+
+    def test_pages(self):
+        req = Request.blank("/")
+        reg_url = register_url(req)
+        l_url = login_url(req)
+        lo_url = logout_url(req)
+        re_url = reset_url(req)
+        

File tests/test_as_bfg.pyc

Binary file added.

File tests/test_as_bfg.py~

+"""
+functionality specific to when identity.model ia a part of a bfg application
+"""
+"""
+from identity.model.apps.auth.models import appmaker as auth_appmaker
+from identity.model.apps.register.models import appmaker as register_appmaker
+from identity.model.apps.password.models import appmaker as password_appmaker
+from identity.model.apps.manager.models import appmaker as manage_appmaker
+from repoze.bfg.configuration import Configurator
+from repoze.bfg.wsgi import wsgiapp
+from webob import Response, Request
+from identity.model.apps.auth import login_url, logout_url
+from identity.model.apps.register import register_url
+from identity.model.apps.password import reset_url
+
+
+class AppRoot(object):
+    __name__=None
+    __parent__ = None
+
+    def __init__(self, config):
+
+        self.models = {
+            "auth": auth_appmaker(config)(None),
+            "register":register_appmaker(config)(None),
+            "reset": password_appmaker(config)(None),
+            "manage": manage_appmaker(config)(None)}
+
+        for k,v in self.models.items():
+            v.__name__ = k
+            v.__parent__ = self
+
+    def __getitem__(self,key):
+        print key
+        return self.models[key]
+    def current_user(self, request):
+        from identity.model.apps.auth import get_current_user
+        return get_current_user(request)

File tests/test_as_bfg.zcml

+<configure xmlns="http://namespaces.repoze.org/bfg">
+  <!-- this must be included for the view declarations to work -->
+  <include package="repoze.bfg.includes" />
+  <include package="identity.model.apps.auth"/>
+  <include package="identity.model.apps.register"/>
+  <include package="identity.model.apps.password"/>
+  <include package="identity.model.apps.manager"/>
+  <view for="test_as_bfg.AppRoot" view="test_as_bfg.view_bfg_root"/>
+</configure>

File tests/test_as_bfg.zcml~

+<configure xmlns="http://namespaces.repoze.org/bfg">
+  <!-- this must be included for the view declarations to work -->
+  <include package="repoze.bfg.includes" />
+  <include package="identity.model.apps.auth"/>
+  <include package="identity.model.apps.register"/>
+  <include package="identity.model.apps.password"/>
+  <include package="identity.model.apps.manager"/>
+  <view for="test_as_bfg.AppRoot" view="test_as_bfg.view_root"/>
+</configure>