

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': 'Success',
            'payload': {
                'auths': {
                    auth_key: {
                        'r': 1,
                        'm': 0,
                        'w': 1,
                    },
                },
                'subscribe_key': subkey,
                'level': 'user',
                'channel': channel,
                'ttl': 10,
            },
        })

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

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

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

                def _err5(resp):
                    assert (resp['message'] == 'Forbidden')
                    assert (resp['payload'] == {
                        '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)

dataset/ETHPy150Open pubnub/python/python-twisted/tests/test_grant_async.py test_9/original