Commits

Chris McDonough  committed 793c6c7

make all tests pass and normalize

  • Participants
  • Parent commits 8e84ba3

Comments (0)

Files changed (10)

File src/layout/tutorial/__init__.py

         'tutorial:templates/static'
         )
     config.add_handler(
-        'tutorial.handlers:WikiHandler',
+        'tutorial.handlers:MyHandler',
         pattern='/{action}'
         )
     config.add_handler(
-        'tutorial.handlers:WikiHandler',
+        'tutorial.handlers:MyHandler',
         pattern='/',
         route_name='home',
         action='index'

File src/layout/tutorial/handlers.py

 from tutorial.models import DBSession
 from tutorial.models import Model
 
-class WikiHandler(object):
+class MyHandler(object):
     def __init__(self, request):
         self.request = request
 

File src/layout/tutorial/templates/mytemplate.mak

 	href="http://pylonshq.com">Pylons</a> web
 	application framework.</h1>
       </div>
+      <div>The root object's name is "${root.name}"</div>
     </div>
     <!-- end content -->
     <!-- start sidebar -->

File src/layout/tutorial/tests.py

 import unittest
 
-from pylons.configuration import Configurator
-
 class WikiHandlerTests(unittest.TestCase):
     def setUp(self):
+        from pylons.configuration import Configurator
+        from tutorial.models import initialize_sql
+        self.session = initialize_sql('sqlite://')
         self.config = Configurator()
         self.config.begin()
 
         self.config.end()
 
     def _makeOne(self, request):
-        from tutorial.handlers import WikiHandler
-        return WikiHandler(request)
+        from tutorial.handlers import MyHandler
+        return MyHandler(request)
 
     def test_index(self):
         request = DummyRequest()
         handler = self._makeOne(request)
         info = handler.index()
         self.assertEqual(info['project'], 'tutorial')
+        self.assertEqual(info['root'].name, 'root')
 
 class DummyRequest(object):
     pass

File src/models/tutorial/__init__.py

         'tutorial:templates/static'
         )
     config.add_handler(
-        'tutorial.handlers:WikiHandler',
+        'tutorial.handlers:MyHandler',
         pattern='/{action}'
         )
     config.add_handler(
-        'tutorial.handlers:WikiHandler',
+        'tutorial.handlers:MyHandler',
         pattern='/',
         route_name='home',
         action='index'

File src/models/tutorial/handlers.py

 from tutorial.models import DBSession
 from tutorial.models import Model
 
-class WikiHandler(object):
+class MyHandler(object):
     def __init__(self, request):
         self.request = request
 

File src/models/tutorial/templates/mytemplate.mak

 	href="http://pylonshq.com">Pylons</a> web
 	application framework.</h1>
       </div>
+      <div>The root object's name is "${root.name}"</div>
     </div>
     <!-- end content -->
     <!-- start sidebar -->

File src/models/tutorial/tests.py

 import unittest
 
-from pylons.configuration import Configurator
-
 class WikiHandlerTests(unittest.TestCase):
     def setUp(self):
+        from pylons.configuration import Configurator
+        from tutorial.models import initialize_sql
+        self.session = initialize_sql('sqlite://')
         self.config = Configurator()
         self.config.begin()
 
         self.config.end()
 
     def _makeOne(self, request):
-        from tutorial.handlers import WikiHandler
-        return WikiHandler(request)
+        from tutorial.handlers import MyHandler
+        return MyHandler(request)
 
     def test_index(self):
         request = DummyRequest()
         handler = self._makeOne(request)
         info = handler.index()
         self.assertEqual(info['project'], 'tutorial')
+        self.assertEqual(info['root'].name, 'root')
 
 class DummyRequest(object):
     pass

File src/views/tutorial/templates/mytemplate.mak

-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml"
-      xmlns:tal="http://xml.zope.org/namespaces/tal">
-<head>
-<meta http-equiv="content-type" content="text/html; charset=utf-8" />
-<title>${project} Application</title>
-<meta name="keywords" content="python web application" />
-<meta name="description" content="Pylons web application" />
-<link href="${request.application_url}/static/default.css" rel="stylesheet" type="text/css" />
-</head>
-<body>
-<!-- start header -->
-<div id="logo">
-  <h2><code>${project}</code>, a <code>Pylons</code> application</h2>
-</div>
-<div id="header">
-  <div id="menu">
-  </div>
-</div>
-<!-- end header -->
-<div id="wrapper">
-  <!-- start page -->
-  <div id="page">
-    <!-- start content -->
-    <div id="content">
-      <div class="post">
-	<h1 class="title">Welcome to <code>${project}</code>, an
-	application generated by the <a
-	href="http://pylonshq.com">Pylons</a> web
-	application framework.</h1>
-      </div>
-    </div>
-    <!-- end content -->
-    <!-- start sidebar -->
-    <div id="sidebar"></div>
-    <!-- end sidebar -->
-    <div style="clear: both;">&nbsp;</div>
-  </div>
-</div>
-<!-- end page -->
-<!-- start footer -->
-<div id="footer">
-  <p id="legal">( c ) 2008. All Rights Reserved. Template design
-  by <a href="http://www.freecsstemplates.org/">Free CSS
-  Templates</a>.</p>
-</div>
-<!-- end footer -->
-</body>
-</html>

File src/views/tutorial/tests.py

 import unittest
 
 from pylons.configuration import Configurator
+from repoze.bfg import testing
 
-class WikiHandlerTests(unittest.TestCase):
+class TestWikiHandler(unittest.TestCase):
     def setUp(self):
+        self.session = self._initTestingDB()
         self.config = Configurator()
         self.config.begin()
+        self.config.add_route('root', '/')
+        self.config.add_route('wiki_action', '/wiki/{pagename}/{action}')
 
     def tearDown(self):
+        self.session.remove()
         self.config.end()
 
+    def _initTestingDB(self):
+        from tutorial.models import DBSession
+        from tutorial.models import Base
+        from sqlalchemy import create_engine
+        engine = create_engine('sqlite://')
+        DBSession.configure(bind=engine)
+        Base.metadata.bind = engine
+        Base.metadata.create_all(engine)
+        return DBSession
+
     def _makeOne(self, request):
         from tutorial.handlers import WikiHandler
         return WikiHandler(request)
+        
+    def test___call__(self):
+        request = testing.DummyRequest()
+        handler = self._makeOne(request)
+        response = handler()
+        self.assertEqual(response.location,
+                         'http://example.com/wiki/FrontPage/view')
 
-    def test_index(self):
-        request = DummyRequest()
+    def test_view(self):
+        request = testing.DummyRequest()
         handler = self._makeOne(request)
-        info = handler.index()
-        self.assertEqual(info['project'], 'tutorial')
+        from tutorial.models import Page
+        request.matchdict['pagename'] = 'IDoExist'
+        page = Page('IDoExist', 'Hello CruelWorld IDoExist')
+        self.session.add(page)
+        info = handler.view()
+        self.assertEqual(info['page'], page)
+        self.assertEqual(
+            info['content'], 
+            '<div class="document">\n'
+            '<p>Hello <a href="http://example.com/wiki/CruelWorld/add">'
+            'CruelWorld</a> '
+            '<a href="http://example.com/wiki/IDoExist/view">'
+            'IDoExist</a>'
+            '</p>\n</div>\n')
+        self.assertEqual(info['edit_url'],
+                         'http://example.com/wiki/IDoExist/edit')
+        
+    
+    def test_add_notsubmitted(self):
+        request = testing.DummyRequest()
+        request.matchdict = {'pagename':'AnotherPage'}
+        handler = self._makeOne(request)
+        info = handler.add()
+        self.assertEqual(info['page'].data,'')
+        self.assertEqual(info['save_url'],
+                         'http://example.com/wiki/AnotherPage/add')
+        
+    def test_add_submitted(self):
+        from tutorial.models import Page
+        request = testing.DummyRequest({'form.submitted':True,
+                                        'body':'Hello yo!'})
+        request.matchdict = {'pagename':'AnotherPage'}
+        handler = self._makeOne(request)
+        handler.add()
+        page = self.session.query(Page).filter_by(name='AnotherPage').one()
+        self.assertEqual(page.data, 'Hello yo!')
 
-class DummyRequest(object):
-    pass
+    def test_edit_notsubmitted(self):
+        from tutorial.models import Page
+        request = testing.DummyRequest()
+        request.matchdict = {'pagename':'abc'}
+        page = Page('abc', 'hello')
+        self.session.add(page)
+        handler = self._makeOne(request)
+        info = handler.edit()
+        self.assertEqual(info['page'], page)
+        self.assertEqual(info['save_url'],
+                         'http://example.com/wiki/abc/edit')
+        
+    def test_edit_submitted(self):
+        from tutorial.models import Page
+        request = testing.DummyRequest({'form.submitted':True,
+                                        'body':'Hello yo!'})
+        request.matchdict = {'pagename':'abc'}
+        page = Page('abc', 'hello')
+        self.session.add(page)
+        handler = self._makeOne(request)
+        response = handler.edit()
+        self.assertEqual(response.location, 'http://example.com/wiki/abc/view')
+        self.assertEqual(page.data, 'Hello yo!')