I've been upgrading my unit testing to use the django TestCase
framework [1]. I wrote a single function that inspects my
permissions:
setup_auth()
g1,g2, g3 create_groups()
perms1 = [permission_finder('app1.perm1'), permission_finder('app2.perm1]
perms2 = perms + [permission_finder('app3.perm1'),]
add_perms(g1,perms)
add_perms(g2,perms2)
add_users_to_groups()
I then add those permissions to groups as a basis for all my cross-app
'role' testing within django. I can call that from setUp across all
my derived unit tests (or inherit from my own testCase). I think
signals would be a more elegant solution but I've run into 'fire
ordering' issue.
contrib.auth.management registers:
dispatcher.connect(create_permissions, signal=signals.post_syncdb)
If I then add setup_auth to the same signal, my setup_auth code
triggers prior to create_permissions, making my code fail. If I
switch to fixdumpdata on the auth app, I end up with pretty hairy
maintenance as I change what permissions groups have and whittling the
fixture down to the smallest unit.
My current solution is to include a custom TestCase involving
_pre_setup(). While that works for me, I think that the "after
everything syncs with the database but before we do anything else" is
a good place to handle cross-app issues and I think it's where several
people are looking [2][3]. The patch is fairly simple
(syncdb_finished -> models/signals.py and a syncdb_finished signal ->
emit_syncdb_signals after the for model ... loop).
References:
[1] My discussion with Russ Magee explaining using signals to address
the account authorization problem:
http://groups.google.com/group/django-users/msg/e8b936529a4fbe97
[2] Someone else running into similar issue (looked like a support
request so it got marked as invalid):
http://code.djangoproject.com/ticket/6040
[3] Someone having the same idea and redirected towards fixtures
http://groups.google.com/group/django-users/browse_thread/thread/cb0e199820b1ff7d
--
Chris Green <[EMAIL PROTECTED]>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" 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/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---