Closed mauricioabreu closed 10 years ago
Hey, @mauricioabreu! Thank you for the report. Could you shoot me a whole testcase?
Of course:
I am using:
Here is an example:
class TestListUserSearch(TestCase):
def setUp(self):
self.user = mommy_recipes.make_user('brand')
self.brand = CustomUserAccount.objects.get(user=self.user).account
self.client.login(username=self.user.email,
password='aaa123')
def test_list_users_with_filter_by_email(self):
user = mommy.make(CustomUserAccount, account=self.brand).user
user.save()
url = reverse('user:user_list',
args=[self.brand.id]) + '?q={0}'.format(user.email)
response = self.client.get(url)
self.assertTemplateUsed(response, 'user/user_list.html')
self.assertEqual(len(response.context['objects']), 1)
Every test I write setUp outputs errors:
AttributeError: 'HttpRequest' object has no attribute 'user'
Couldn't reproduce it. I think you may have a special case with settings of test project or something like that.
It would be better if you sent me a pull request including a test to reproduce the problem. Otherwise, i cannot help you, because without a code i will not find anything.
Attached #2 Can you check my test? This way you can reproduce what I am talking about. Thanks!
When running the application itself those errors don't happen.
Thank you for the pull request.
After diving into the problem i found that django.test.client.login()
is not processing midlewares, where request.user
is set.
I've found a commit https://github.com/django/django/commit/4fdd51b73240bf9c8d9472fcc45df699f0714755, that solve that problem, but it's fixed in django 1.7.
I'll try to find some solution.
I amo willing to provide a fix plus some tests. Tell me if you need some help. Thanks.
It seems everything is ok!
I am facing a problem running my tests. All tests that rely on logged in users fail and output the following traceback:
My tests have setUp function (TestCase) that login the user.