TestCase, urlresolvers.reverse and DB

8 views
Skip to first unread message

Liviu Chiributa

unread,
May 11, 2010, 11:23:07 AM5/11/10
to Django developers
Hello,

I encountered a problem while writing some django tests on the svn
version. Whenever I call reverse(urlname), the db is emptied.

Here is the code:

1 from django.contrib.auth.models import User
2 from django.test import TestCase
3 from django.core.urlresolvers import reverse
4
5 class UsersTests(TestCase):
6 def setUp(self):
7 self.john = User.objects.create_user('john',
'jo...@example.com', '123456')
8 self.jack = User.objects.create_user('jack',
'ja...@example.com', '7891011')
9
10 def test_reverse(self):
11 print __file__, 1, User.objects.all()
12 link = reverse('homepage')
13 print __file__, 2, User.objects.all()

And the output is:

userprofile/tests.py 1 [<User: john>, <User: jack>]
userprofile/tests.py 2 []
.
----------------------------------------------------------------------
Ran 1 test in 0.261s

Is this the expect output with the updates to django test framework? I
dont understand why this happens...

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

Jacob Kaplan-Moss

unread,
May 11, 2010, 12:14:24 PM5/11/10
to django-d...@googlegroups.com
On Tue, May 11, 2010 at 10:23 AM, Liviu Chiributa <chl...@gmail.com> wrote:
> I encountered a problem while writing some django tests on the svn
> version. Whenever I call reverse(urlname), the db is emptied.
>
> Here is the code:

I just tried out this exact same code, and it works fine for me with
both the RC and latest trunk (r13237). I get, as expected::

/Users/jacob/Projects/jacobian.org/jacobian/blog/tests.pyc 1 [<User:
john>, <User: jack>]
/Users/jacob/Projects/jacobian.org/jacobian/blog/tests.pyc 2 [<User:
john>, <User: jack>]

So there's probably something strange going on that's specific to your
setup. You should probably take this to django-users -- someone there
can probably help you track down what's wrong with your code. If
you're able to prove that it's a problem with Django, bring it on back
here and we'll take another look.

Thanks!

Jacob
Reply all
Reply to author
Forward
0 new messages