Skip to content

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

jpic opened this Issue Oct 6, 2012 · 1 comment

1 participant

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',  
    appversion = AppVersion.objects.create(app=app, version=0)  
    env = Environment.objects.create(name='default')  

    with mock_signal_receiver(post_app_install) as install_receiver:  

    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:  

    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',  
    artists_appversion = AppVersion.objects.create(app=artists_app, version=0)  

    artworks_app = App.objects.create(name='artworks',  
    artworks_appversion = AppVersion.objects.create(app=artworks_app, version=0)  

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

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

    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 test appstore: app is open source

Thanks in advance !


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 Oct 6, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.