def test_9():
    channel = "test_9-" + str(time.time())
    message = "Hello World"
    auth_key = "auth-" + channel
    pubnub.set_auth_key(auth_key)

    def _cb2(resp, ch=None):
        assert resp == {
            'message': u'Success',
            'payload': {u'auths': {auth_key: {u'r': 1, u'm': 0, u'w': 1}},
                        u'subscribe_key': subkey,
                        u'level': u'user', u'channel': channel, u'ttl': 10}
        }

        def _cb3(resp, ch=None):
            assert resp[0] == 1

            def _cb4(resp, ch=None):
                assert resp == {
                    'message': u'Success',
                    'payload': {u'auths': {auth_key: {u'r': 0, u'm': 0, u'w': 0}},
                                u'subscribe_key': subkey,
                                u'level': u'user', u'channel': channel, u'ttl': 1}
                }

                def _cb5(resp, ch=None):
                    print(resp)
                    assert False

                def _err5(resp):
                    assert resp['message'] == 'Forbidden'
                    assert resp['payload'] == {u'channels': [channel]}

                time.sleep(5)
                pubnub.publish(channel=channel, message=message, callback=_cb5, error=_err5)

            def _err4(resp):
                assert False

            pubnub_pam.revoke(channel=channel, auth_key=auth_key, callback=_cb4, error=_err4)

        def _err3(resp):
            assert False

        time.sleep(7)
        pubnub.publish(channel=channel, message=message, callback=_cb3, error=_err3)

    def _err2(resp):
        assert False

    pubnub_pam.grant(channel=channel, read=True, write=True, auth_key=auth_key, ttl=10, callback=_cb2, error=_err2)


# Complete flow , try publish on forbidden channel, grant permission channel level for subkey and try again.
# then revoke and try again
dataset/ETHPy150Open pubnub/python/python-twisted/tests/test_grant_async.py/test_9/original