unit testing many to one relationship

46 views
Skip to first unread message

jeetu

unread,
Nov 5, 2012, 3:55:22 AM11/5/12
to turbo...@googlegroups.com
nosetest example in turbogears http://www.turbogears.org/2.2/docs/main/Testing/index.html suggests use of klass and attrs for testing a single table. What if i have multiple tables like in many to one relationships. I want to initiate two tables in single setup of nosetest. How to do it. I am expecting something like

class TestUser(ModelTest):
    """Unit test case for the ``User`` model."""
    klass1 = model.User
    attrs1 = dict(
        user_name = u"ignucius",
        email_address = u"ignu...@example.org"
group = u"test" )

klass2 = model.Group attrs2 = dict( group_name = u"test", )

def test_something(self):
pass

Is something like this possible? An example would help a lot.

jeetu

unread,
Nov 7, 2012, 3:21:39 AM11/7/12
to turbo...@googlegroups.com
@all
Or may be I have to modify __init__.py in tests/model dir so that klass accepts list of tables and attrs accept some sort of list of list of dicts. Is that a good approach?

Craig Small

unread,
Nov 7, 2012, 4:34:41 AM11/7/12
to turbo...@googlegroups.com
On Mon, Nov 05, 2012 at 12:55:22AM -0800, jeetu wrote:
> klass and attrs for testing a single table. What if i have multiple tables
> like in many to one relationships. I want to initiate two tables in single
> setup of nosetest. How to do it. I am expecting something like
I'm not sure myself. I've got the following.

class TestParent(ModelTest):
klass = model.Parent
attrs = dict(
child = model.Child(u'Test Child Name')
)

or, just to be confusing:

class TestParent(ModelTest):
klass = model.Parent

def do_get_dependencies(self):
test_child = model.Child(u'Test Child Name')
return {'child': test_child }

I think the second one is more correct but not sure.

--
Craig Small VK2XLZ http://enc.com.au/ csmall at : enc.com.au
Debian GNU/Linux http://www.debian.org/ csmall at : debian.org
GPG fingerprint: 5D2F B320 B825 D939 04D2 0519 3938 F96B DF50 FEA5

Michael Pedersen

unread,
Jan 1, 2013, 11:49:16 PM1/1/13
to tg-trunk
Another valid option is to consider using bootalchemy. I was able to use it to load up a complete database model, and then run tests against that model. I modeled even many-to-many relations using it, and it was pretty straightforward. I'm actually planning on using it at work in the very near future again for a significant rewrite that I've got coming up.



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




--
Michael J. Pedersen
My Online Resume: http://www.icelus.org/ -- Google+ http://plus.ly/pedersen
Google Talk: m.ped...@icelus.org -- Twitter: pedersentg
Reply all
Reply to author
Forward
0 new messages