in my tests/__init__.py, i changed the setup_db() function do to this:

def setup_db():
    """Method used to build a database"""
    engine = config['pylons.app_globals'].sa_engine

    contact = model.Contact()
    contact.full_name = u"Alice Neville"
    contact.given_name = u"Alice"
    contact.family_name = u"Neville"
    contact.birthday = datetime.date(1984, 4, 29)
    model.DBSession.add(contact)

i've also added the call for setup_db() in the setUp() function in the
same file.  (i added the call too make sure it gets called b/c
sometimes it runs but not others depending how you trigger the tests.)

since i could query it right before self.app.get, i was assuming that
it was set up properly.

ideally, i would like to get it to work without modifying zope's
transaction stuff b/c i m worried that if i don't do it properly, it
would cause even more problems.  (this is my first tg project).
conversely, this zope stuff is driving me nuts b/c i am not sure when
it decides to commit and i couldn't get farmdev's fixture module to
work.  so if u have some advice or resource on this subject, please
let me know too.

really appreciate the help.


On Dec 1, 5:39 am, "Diez B. Roggisch" <[email protected]> wrote:
> On Tuesday 01 December 2009 04:58:20 steve wrote:
>
> > the controllers and template is pretty straight forward.  when i visit
> > it on a browser via paster serve, it displays properly when given a
> > valid id in the db.  as for the exception during nosetests, it is the
> > same one u would get when you provide an invalid id at GET /contacts/
> > [invalid_id].  this confuses me b/c the print statement in my test
> > case validates that the row is in the test database.  however, when
> > you hit self.app.get(' /contacts/[contact_id]'), the exception it
> > throws indicate that the id is invalid, hence contact is None, and
> > hence 'None has no member named "full_name"'.
>
> You don't show how you actually create the user. What gives us troubles in
> these cases is that you have to create data inside a test within it's own
> transaction. Otherwise, it's of course not visible to the *next* transaction
> which is openend via self.app.get
>
> Because of various issues with the transaction-handling in TG2, we ripped this
> out (the whole zope.transaction-stuff), and rolled our own middleware which
> simply applies a
>
>   @transactional
>
> decorator around a call. This same decorator we use in tests:
>
> class MyTest(...):
>
>    def test_something(self):
>         �...@transactional
>          def create_testuser():
>                return User(name='test').id
>
>          user_id = create_testuser()
>          self.app.get("/test/%i" % user_id)
>
> HTH,
>
> Diez

--

You received this message because you are subscribed to the Google Groups 
"TurboGears" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/turbogears?hl=en.


Reply via email to