nsigustavo / ludibrio

Platform for test doubles in Python (mocks, stubs, Spy, and dummies)
113 stars 15 forks source link

Error using ludibrio with nose and Django for testing #6

Open supercodepoet opened 13 years ago

supercodepoet commented 13 years ago

There is an odd recursion happening between Ludibrio and Django.

Traceback File "./bin/test", line 31, in File "/Users/robmadole/Development/src/social-lead-x/eggs/nose-0.11.4-py2.7.egg/nose/core.py", line 117, in init _extra_args) File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/unittest/main.py", line 95, in init self.runTests() File "/Users/robmadole/Development/src/social-lead-x/eggs/nose-0.11.4-py2.7.egg/nose/core.py", line 196, in runTests result = self.testRunner.run(self.test) File "/Users/robmadole/Development/src/social-lead-x/eggs/nose-0.11.4-py2.7.egg/nose/core.py", line 61, in run test(result) File "/Users/robmadole/Development/src/social-lead-x/eggs/nose-0.11.4-py2.7.egg/nose/suite.py", line 176, in call return self.run(_arg, _kw) File "/Users/robmadole/Development/src/social-lead-x/eggs/nose-0.11.4-py2.7.egg/nose/suite.py", line 223, in run test(orig) File "/Users/robmadole/Development/src/social-lead-x/eggs/nose-0.11.4-py2.7.egg/nose/suite.py", line 176, in call return self.run(_arg, _kw) File "/Users/robmadole/Development/src/social-lead-x/eggs/nose-0.11.4-py2.7.egg/nose/suite.py", line 223, in run test(orig) File "/Users/robmadole/Development/src/social-lead-x/eggs/nose-0.11.4-py2.7.egg/nose/suite.py", line 176, in call return self.run(_arg, _kw) File "/Users/robmadole/Development/src/social-lead-x/eggs/nose-0.11.4-py2.7.egg/nose/suite.py", line 223, in run test(orig) File "/Users/robmadole/Development/src/social-lead-x/eggs/nose-0.11.4-py2.7.egg/nose/case.py", line 44, in call return self.run(_arg, *_kwarg) File "/Users/robmadole/Development/src/social-lead-x/eggs/nose-0.11.4-py2.7.egg/nose/case.py", line 132, in run self.runTest(result) File "/Users/robmadole/Development/src/social-lead-x/eggs/nose-0.11.4-py2.7.egg/nose/case.py", line 150, in runTest test(result) File "/Users/robmadole/Development/src/social-lead-x/parts/django/django/test/testcases.py", line 263, in call super(TransactionTestCase, self).call(result) File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/unittest/case.py", line 376, in call return self.run(_args, **kwds) File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/unittest/case.py", line 318, in run testMethod() File "/Users/robmadole/Development/src/social-lead-x/src/socialleadx/facebook/tests/test_utils.py", line 27, in test_populate_friends from facebook import get_user_from_cookie File "/Users/robmadole/Development/src/social-lead-x/eggs/ludibrio-3.0.3-py2.7.egg/ludibrio/dependencyinjection.py", line 43, in import_double self.inject() File "/Users/robmadole/Development/src/social-lead-x/eggs/ludibrio-3.0.3-py2.7.egg/ludibrio/dependencyinjection.py", line 48, in inject self._original_to_double() File "/Users/robmadole/Development/src/social-lead-x/eggs/ludibrio-3.0.3-py2.7.egg/ludibrio/dependencyinjection.py", line 54, in _original_to_double self._replace_all(self.original, self.double) File "/Users/robmadole/Development/src/social-lead-x/eggs/ludibrio-3.0.3-py2.7.egg/ludibrio/dependencyinjection.py", line 65, in _replace_all for module in self._all_modules(): File "/Users/robmadole/Development/src/social-lead-x/eggs/ludibrio-3.0.3-py2.7.egg/ludibrio/dependencyinjection.py", line 75, in _all_modules if isinstance(obj, ModuleType): File "/Users/robmadole/Development/src/social-lead-x/parts/django/django/utils/functional.py", line 354, in get_class if self._wrapped is None: self._setup() File "/Users/robmadole/Development/src/social-lead-x/parts/django/django/utils/functional.py", line 367, in _setup self._wrapped = self._setupfunc() File "/Users/robmadole/Development/src/social-lead-x/parts/django/django/contrib/auth/context_processors.py", line 23, in get_user if hasattr(request, 'user'): File "/Users/robmadole/Development/src/social-lead-x/parts/django/django/contrib/auth/middleware.py", line 8, in get from django.contrib.auth import get_user File "/Users/robmadole/Development/src/social-lead-x/eggs/ludibrio-3.0.3-py2.7.egg/ludibrio/dependencyinjection.py", line 43, in import_double self.inject() File "/Users/robmadole/Development/src/social-lead-x/eggs/ludibrio-3.0.3-py2.7.egg/ludibrio/dependencyinjection.py", line 48, in inject self._original_to_double() File "/Users/robmadole/Development/src/social-lead-x/eggs/ludibrio-3.0.3-py2.7.egg/ludibrio/dependencyinjection.py", line 54, in _original_to_double self._replace_all(self.original, self.double) File "/Users/robmadole/Development/src/social-lead-x/eggs/ludibrio-3.0.3-py2.7.egg/ludibrio/dependencyinjection.py", line 65, in _replace_all for module in self._all_modules(): File "/Users/robmadole/Development/src/social-lead-x/eggs/ludibrio-3.0.3-py2.7.egg/ludibrio/dependencyinjection.py", line 75, in _all_modules if isinstance(obj, ModuleType): File "/Users/robmadole/Development/src/social-lead-x/parts/django/django/utils/functional.py", line 354, in get_class if self._wrapped is None: self._setup() File "/Users/robmadole/Development/src/social-lead-x/parts/django/django/utils/functional.py", line 367, in _setup self._wrapped = self._setupfunc() File "/Users/robmadole/Development/src/social-lead-x/parts/django/django/contrib/auth/context_processors.py", line 23, in get_user if hasattr(request, 'user'): File "/Users/robmadole/Development/src/social-lead-x/parts/django/django/contrib/auth/middleware.py", line 8, in get from django.contrib.auth import get_user File "/Users/robmadole/Development/src/social-lead-x/eggs/ludibrio-3.0.3-py2.7.egg/ludibrio/dependencyinjection.py", line 43, in import_double self.inject() File "/Users/robmadole/Development/src/social-lead-x/eggs/ludibrio-3.0.3-py2.7.egg/ludibrio/dependencyinjection.py", line 48, in inject self._original_to_double() File "/Users/robmadole/Development/src/social-lead-x/eggs/ludibrio-3.0.3-py2.7.egg/ludibrio/dependencyinjection.py", line 54, in _original_to_double self._replace_all(self.original, self.double) File "/Users/robmadole/Development/src/social-lead-x/eggs/ludibrio-3.0.3-py2.7.egg/ludibrio/dependencyinjection.py", line 65, in _replace_all for module in self._all_modules(): File "/Users/robmadole/Development/src/social-lead-x/eggs/ludibrio-3.0.3-py2.7.egg/ludibrio/dependencyinjection.py", line 75, in _all_modules if isinstance(obj, ModuleType): File "/Users/robmadole/Development/src/social-lead-x/parts/django/django/utils/functional.py", line 354, in get_class if self._wrapped is None: self._setup() File "/Users/robmadole/Development/src/social-lead-x/parts/django/django/utils/functional.py", line 367, in _setup self._wrapped = self._setupfunc() File "/Users/robmadole/Development/src/social-lead-x/parts/django/django/contrib/auth/context_processors.py", line 23, in get_user if hasattr(request, 'user'): File "/Users/robmadole/Development/src/social-lead-x/parts/django/django/contrib/auth/middleware.py", line 8, in get from django.contrib.auth import get_user File "/Users/robmadole/Development/src/social-lead-x/eggs/ludibrio-3.0.3-py2.7.egg/ludibrio/dependencyinjection.py", line 43, in import_double self.inject() File "/Users/robmadole/Development/src/social-lead-x/eggs/ludibrio-3.0.3-py2.7.egg/ludibrio/dependencyinjection.py", line 48, in inject self._original_to_double() File "/Users/robmadole/Development/src/social-lead-x/eggs/ludibrio-3.0.3-py2.7.egg/ludibrio/dependencyinjection.py", line 54, in _original_to_double self._replace_all(self.original, self.double) File "/Users/robmadole/Development/src/social-lead-x/eggs/ludibrio-3.0.3-py2.7.egg/ludibrio/dependencyinjection.py", line 65, in _replace_all for module in self._all_modules(): File "/Users/robmadole/Development/src/social-lead-x/eggs/ludibrio-3.0.3-py2.7.egg/ludibrio/dependencyinjection.py", line 75, in _all_modules if isinstance(obj, ModuleType): File "/Users/robmadole/Development/src/social-lead-x/parts/django/django/utils/functional.py", line 354, in get_class if self._wrapped is None: self._setup() File "/Users/robmadole/Development/src/social-lead-x/parts/django/django/utils/functional.py", line 367, in _setup self._wrapped = self._setupfunc() File "/Users/robmadole/Development/src/social-lead-x/parts/django/django/contrib/auth/context_processors.py", line 23, in get_user if hasattr(request, 'user'): File "/Users/robmadole/Development/src/social-lead-x/parts/django/django/contrib/auth/middleware.py", line 8, in get from django.contrib.auth import get_user File "/Users/robmadole/Development/src/social-lead-x/eggs/ludibrio-3.0.3-py2.7.egg/ludibrio/dependencyinjection.py", line 43, in import_double self.inject() File "/Users/robmadole/Development/src/social-lead-x/eggs/ludibrio-3.0.3-py2.7.egg/ludibrio/dependencyinjection.py", line 48, in inject self._original_to_double() File "/Users/robmadole/Development/src/social-lead-x/eggs/ludibrio-3.0.3-py2.7.egg/ludibrio/dependencyinjection.py", line 54, in _original_to_double self._replace_all(self.original, self.double) File "/Users/robmadole/Development/src/social-lead-x/eggs/ludibrio-3.0.3-py2.7.egg/ludibrio/dependencyinjection.py", line 65, in _replace_all for module in self._all_modules(): File "/Users/robmadole/Development/src/social-lead-x/eggs/ludibrio-3.0.3-py2.7.egg/ludibrio/dependencyinjection.py", line 75, in _all_modules if isinstance(obj, ModuleType): File "/Users/robmadole/Development/src/social-lead-x/parts/django/django/utils/functional.py", line 354, in get_class if self._wrapped is None: self._setup() File "/Users/robmadole/Development/src/social-lead-x/parts/django/django/utils/functional.py", line 367, in _setup self._wrapped = self._setupfunc() File "/Users/robmadole/Development/src/social-lead-x/parts/django/django/contrib/auth/context_processors.py", line 23, in get_user if hasattr(request, 'user'): File "/Users/robmadole/Development/src/social-lead-x/parts/django/django/contrib/auth/middleware.py", line 8, in get from django.contrib.auth import get_user File "/Users/robmadole/Development/src/social-lead-x/eggs/ludibrio-3.0.3-py2.7.egg/ludibrio/dependencyinjection.py", line 43, in import_double self.inject() File "/Users/robmadole/Development/src/social-lead-x/eggs/ludibrio-3.0.3-py2.7.egg/ludibrio/dependencyinjection.py", line 48, in inject self._original_to_double() File "/Users/robmadole/Development/src/social-lead-x/eggs/ludibrio-3.0.3-py2.7.egg/ludibrio/dependencyinjection.py", line 54, in _original_to_double self._replace_all(self.original, self.double) File "/Users/robmadole/Development/src/social-lead-x/eggs/ludibrio-3.0.3-py2.7.egg/ludibrio/dependencyinjection.py", line 65, in _replace_all for module in self._all_modules(): File "/Users/robmadole/Development/src/social-lead-x/eggs/ludibrio-3.0.3-py2.7.egg/ludibrio/dependencyinjection.py", line 75, in _all_modules if isinstance(obj, ModuleType): File "/Users/robmadole/Development/src/social-lead-x/parts/django/django/utils/functional.py", line 354, in get_class if self._wrapped is None: self._setup() File "/Users/robmadole/Development/src/social-lead-x/parts/django/django/utils/functional.py", line 367, in _setup self._wrapped = self._setupfunc() File "/Users/robmadole/Development/src/social-lead-x/parts/django/django/contrib/auth/context_processors.py", line 23, in get_user if hasattr(request, 'user'): File "/Users/robmadole/Development/src/social-lead-x/parts/django/django/contrib/auth/middleware.py", line 8, in get from django.contrib.auth import get_user File "/Users/robmadole/Development/src/social-lead-x/eggs/ludibrio-3.0.3-py2.7.egg/ludibrio/dependencyinjection.py", line 43, in import_double self.inject() File "/Users/robmadole/Development/src/social-lead-x/eggs/ludibrio-3.0.3-py2.7.egg/ludibrio/dependencyinjection.py", line 48, in inject self._original_to_double() File "/Users/robmadole/Development/src/social-lead-x/eggs/ludibrio-3.0.3-py2.7.egg/ludibrio/dependencyinjection.py", line 54, in _original_to_double self._replace_all(self.original, self.double) File "/Users/robmadole/Development/src/social-lead-x/eggs/ludibrio-3.0.3-py2.7.egg/ludibrio/dependencyinjection.py", line 65, in _replace_all for module in self._all_modules(): File "/Users/robmadole/Development/src/social-lead-x/eggs/ludibrio-3.0.3-py2.7.egg/ludibrio/dependencyinjection.py", line 75, in _all_modules if isinstance(obj, ModuleType): File "/Users/robmadole/Development/src/social-lead-x/parts/django/django/utils/functional.py", line 354, in get_class if self._wrapped is None: self._setup() File "/Users/robmadole/Development/src/social-lead-x/parts/django/django/utils/functional.py", line 367, in _setup self._wrapped = self._setupfunc() File "/Users/robmadole/Development/src/social-lead-x/parts/django/django/contrib/auth/context_processors.py", line 23, in get_user if hasattr(request, 'user'): File "/Users/robmadole/Development/src/social-lead-x/parts/django/django/contrib/auth/middleware.py", line 8, in get__ from django.contrib.auth import get_user File "/Users/robmadole/Development/src/social-lead-x/eggs/ludibrio-3.0.3-py2.7.egg/ludibrio/dependencyinjection.py", line 39, in import_double print traceback.print_stack()

nsigustavo commented 13 years ago

can show this code?

/Users/robmadole/Development/src/social-lead-x/src/socialleadx/facebook/tests/test_utils.py?!?!?!?!

supercodepoet commented 13 years ago

import unittest

from nose.plugins.attrib import attr from django.contrib.auth.models import User from django.core.urlresolvers import reverse from django.test import TestCase from ludibrio import *

from socialleadx.account.models import from socialleadx.facebook.models import

class FacebookIntegrationTest(TestCase): fixtures = ('persona',)

def setUp(self):
    self.login_url = reverse('facebook-login')
    self.connect_url = reverse('facebook-connect')
    self.dashboard_url = reverse('dashboard-default')

    self.homer = User.objects.get(username='homersimpson')

@attr('facebook')
def test_facebook_login_with_account_with_fbconnect(self):
    '''
    Testing logging in with Facebook when the user has already created
    a Localbase account and has already connected with Facebook
    '''
    homer_account = Individual.objects.get(user=self.homer)
    homer_facebook = FacebookUser.objects.create(
        id='10000001',
        name='Homer Simpson',
        first_name='Homer',
        last_name='Simpson',
        email='homer.simpson@gmail.com',
        link='http://www.facebook.com/homer')

    homer_account.facebook = homer_facebook
    homer_account.save()

    try:
        from facebook import get_user_from_cookie

        with Stub() as get_user_from_cookie:
            from facebook import get_user_from_cookie

            get_user_from_cookie(any(), any(), any()) >> {
                'uid': '10000001',
                'access_token': 'notrealtoken'}

        response = self.client.post(self.login_url, follow=True)

        self.assertEquals(response.status_code, 200)
        self.assertEquals(response.redirect_chain[0],
            ('http://testserver%s' % self.dashboard_url, 302))

    finally:
        get_user_from_cookie.restore_import()

    self.client.logout()
supercodepoet commented 13 years ago

I see this issue was closed. Is it fixed in a new version?

nsigustavo commented 13 years ago

can reproduce this error on a test?

supercodepoet commented 13 years ago

yes, I sent you the test code in this message thread. Here is the test that is running:

https://github.com/nsigustavo/ludibrio/issues#issue/6/comment/597149

The setup is Django 1.2.3, nose and ludibrio 3.0.3