Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable asserting that a signal was called several times in a specific order #7

Closed
jpic opened this issue Oct 6, 2012 · 1 comment
Closed

Comments

@jpic
Copy link

jpic commented Oct 6, 2012

I could test that a signal was called once with the right arguments:

def test_001_simple_app(self):  
    app = App.objects.create(name='artists',  
        category=AppCategory.objects.create(name='art'))  
    appversion = AppVersion.objects.create(app=app, version=0)  
    env = Environment.objects.create(name='default')  

    with mock_signal_receiver(post_app_install) as install_receiver:  
        env.install(appversion)  

    self.assertEqual(install_receiver.call_count, 1)  
    install_receiver.assert_called_with(signal=post_app_install, sender=env, appversion=appversion)  

    self.assertEqual(list(env.appversions.all()), [appversion])  
    self.assertIn(app, env.installed_apps)  

    with mock_signal_receiver(post_app_uninstall) as uninstall_receiver:  
        env.uninstall(appversion)  

    self.assertEqual(uninstall_receiver.call_count, 1)  
    uninstall_receiver.assert_called_with(signal=post_app_uninstall, sender=env, appversion=appversion)        

    self.assertEqual(list(env.appversions.all()), [])  
    self.assertEqual(0, len(env.installed_apps))  

But in this case, I'd like to assert that post_app_install was called twice, first with 'artists' and then with 'artworks' - since 'artists' is a dependency of 'artworks':

def test_002_simple_dependency(self):  
    artists_app = App.objects.create(name='artists',  
        category=AppCategory.objects.create(name='art'))  
    artists_appversion = AppVersion.objects.create(app=artists_app, version=0)  

    artworks_app = App.objects.create(name='artworks',  
        category=AppCategory.objects.get(name='art'))  
    artworks_appversion = AppVersion.objects.create(app=artworks_app, version=0)  
    artworks_appversion.dependencies.add(artists_appversion)  

    env = Environment.objects.create(name='default')  

    with mock_signal_receiver(post_app_install) as install_receiver:  
        import ipdb; ipdb.set_trace()  
        env.install(artworks_appversion)  

    self.assertEqual(install_receiver.call_count, 2)  

Fiddling with ipdb, I couldn't find a way .... Is this even possible ?

You may want to fiddle with it too, just pip install -e the app and cd to test_project and run manage.py test appstore: app is open source

Thanks in advance !

Regards

@jpic
Copy link
Author

jpic commented Oct 6, 2012

Nevermind, I'm dumb sorry ... All i have to do is assert on call_args_list (I found out in an ultimate try).

Thanks a lot for this fantastic app.

@jpic jpic closed this as completed Oct 6, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant