Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

Having issues with chapter 4 and getting the tests to run. Errors.

0 views
Skip to first unread message

pkraus

unread,
Aug 26, 2007, 2:33:16 PM8/26/07
to tg.book
test_controllers.py ...
import unittest
import turbogears
from turbogears import database, testutil
from bookmarker.model import Bookmark
from bookmarker.controllers import Root
import cherrypy

database.set_db_uri("sqlite:///:memory:")


class test_full_stack(testutil.DBTest):
def get_model(self):
return Bookmark

def test_list_template(self):
"""Checks to see that our template is applied"""
testutil.createRequest("/list")
assert '<title>Bookmarker</title>' in
cherrypy.response.body[0]

def test_list_contents(self):
"""If we add a record to the model, it should show up in the
final page text"""
Bookmark(name="Compound Thinking",
link="http://www.compoundthinking.com",
description="A {not so} random link.")
testutil.createRequest("/list")
assert '<a href="http://www.compoundthinking.com"> ' in
cherrpy.response.body[0]


def test_list_controller():
"""List method should return a set of bookmark objects called
bookmarks."""
cherrypy.root = Root()
output = testutil.call(cherrypy.root.list)
assert output.has_key('bookmarks')


controllers.py
import logging
import cherrypy
import turbogears
from turbogears import controllers, expose, flash, validate, redirect
from bookmarker import json
# import logging
log = logging.getLogger("bookmarker.controllers")

class Root(controllers.RootController):
@expose(template="bookmarker.templates.welcome")
def index(self):
import time
log.debug("Happy TurboGears Controller Responding For Duty")
flash("Your application is now running")
return dict(now=time.ctime())

@expose(template="bookmarker.templates.list")
def list(self):
from model import Bookmark
b=Bookmark.select()
return dict(bookmarks=b)

@expose(template="bookmarker.templates.add")
def save_bookmark(self, name, link, description):
from model import Bookmark
b=Bookmark(name=name, link=link, description=description)
raise redirect("/list")

@expose(template="bookmarker.templates.form")
def bookmark(self):
return dict()


model.py
from turbogears.database import PackageHub
from sqlobject import *

hub = PackageHub('bookmarker')
__connection__ = hub

# class YourDataClass(SQLObject):
# pass

class Bookmark(SQLObject):
name=UnicodeCol(alternateID=True, length=100)
link=UnicodeCol()
description=UnicodeCol()

Results from nosetests ...
C:\Users\pkraus.PELSUPPLY\Documents\source\turbogears
\4\bookmarker>nosetests
EE.
======================================================================
ERROR: If we add a record to the model, it should show up in the final
page text
----------------------------------------------------------------------
Traceback (most recent call last):
File "C:\Users\pkraus.PELSUPPLY\Documents\source\turbogears
\4\bookmarker\bookmarker\tests\test_controllers.py", line 2
7, in test_list_contents
testutil.createRequest("/list")
File "c:\python25\lib\site-packages\TurboGears-1.0.3.2-py2.5.egg
\turbogears\testutil.py", line 89, in create_request
cherrypy.root.started = True
AttributeError: 'NoneType' object has no attribute 'started'
-------------------- >> begin captured stdout << ---------------------
26/Aug/2007:14:32:11 CONFIG INFO Server parameters:
26/Aug/2007:14:32:11 CONFIG INFO server.environment: development
26/Aug/2007:14:32:11 CONFIG INFO server.log_to_screen: True
26/Aug/2007:14:32:11 CONFIG INFO server.log_file:
26/Aug/2007:14:32:11 CONFIG INFO server.log_tracebacks: True
26/Aug/2007:14:32:11 CONFIG INFO server.log_request_headers: True
26/Aug/2007:14:32:11 CONFIG INFO server.protocol_version: HTTP/1.0
26/Aug/2007:14:32:11 CONFIG INFO server.socket_host:
26/Aug/2007:14:32:11 CONFIG INFO server.socket_port: 8080
26/Aug/2007:14:32:11 CONFIG INFO server.socket_file:
26/Aug/2007:14:32:11 CONFIG INFO server.reverse_dns: False
26/Aug/2007:14:32:11 CONFIG INFO server.socket_queue_size: 5
26/Aug/2007:14:32:11 CONFIG INFO server.thread_pool: 10

--------------------- >> end captured stdout << ----------------------

======================================================================
ERROR: Checks to see that our template is applied
----------------------------------------------------------------------
Traceback (most recent call last):
File "C:\Users\pkraus.PELSUPPLY\Documents\source\turbogears
\4\bookmarker\bookmarker\tests\test_controllers.py", line 1
9, in test_list_template
testutil.createRequest("/list")
File "c:\python25\lib\site-packages\TurboGears-1.0.3.2-py2.5.egg
\turbogears\testutil.py", line 89, in create_request
cherrypy.root.started = True
AttributeError: 'NoneType' object has no attribute 'started'

----------------------------------------------------------------------
Ran 3 tests in 2.147s

FAILED (errors=2)


My code runs but the tests blow up. I have another application I am
developing using TG and would like to use tests and understand whats
wrong with the above.

TIA!!!!
Paul

Reply all
Reply to author
Forward
0 new messages