diff options
| -rw-r--r-- | Pubnub.py | 59 | ||||
| -rw-r--r-- | python/examples/console.py | 2 | ||||
| -rw-r--r-- | python/examples/here-now.py | 2 | ||||
| -rw-r--r-- | python/examples/history.py | 2 | ||||
| -rw-r--r-- | python/examples/publish.py | 2 | ||||
| -rw-r--r-- | python/examples/pubnub-console/pubnub-console | 2 | ||||
| -rw-r--r-- | python/examples/subscribe.py | 2 | ||||
| -rw-r--r-- | python/tests/test_grant.py | 199 | ||||
| -rw-r--r-- | python/tests/test_grant_async.py | 369 | 
9 files changed, 586 insertions, 53 deletions
| @@ -283,10 +283,15 @@ class PubnubBase(object):              self._return_wrapped_callback(error))      def get_origin(self): -          return self.origin -    def grant(self, channel, auth_key=False, read=True, +    def set_auth_key(self, auth_key): +        self.auth_key = auth_key + +    def get_auth_key(self): +        return auth_key + +    def grant(self, channel=None, auth_key=False, read=True,                write=True, ttl=5, callback=None, error=None):          """Method for granting permissions. @@ -367,7 +372,7 @@ class PubnubBase(object):              "ttl": ttl          }, callback=callback, error=error) -    def revoke(self, channel, auth_key=False, ttl=1, callback=None, error=None): +    def revoke(self, channel=None, auth_key=None, ttl=1, callback=None, error=None):          """Method for revoking permissions.          Args: @@ -430,7 +435,7 @@ class PubnubBase(object):              "ttl": ttl          }, callback=callback, error=error) -    def audit(self, channel=False, auth_key=False, callback=None, error=None): +    def audit(self, channel=None, auth_key=None, callback=None, error=None):          """Method for fetching permissions from pubnub servers.          This method provides a mechanism to reveal existing PubNub Access Manager attributes @@ -790,6 +795,7 @@ class PubnubBase(object):          if ("urlparams" in request):              url = url + '?' + "&".join([x + "=" + str(y) for x, y in request[                  "urlparams"].items() if y is not None]) +        print url          return url @@ -824,15 +830,6 @@ class PubnubCoreAsync(PubnubBase):          _tt_lock=empty_lock,          _channel_list_lock=empty_lock      ): -        """Summary of class here. - -        Longer class information.... -        Longer class information.... - -        Attributes: -            likes_spam: A boolean indicating if we like SPAM or not. -            eggs: An integer count of the eggs we have laid. -        """          super(PubnubCoreAsync, self).__init__(              publish_key=publish_key, @@ -1250,12 +1247,6 @@ class HTTPClient:          if self._urllib_func is None:              return -        ''' -        try: -            resp = urllib2.urlopen(self.url, timeout=320) -        except urllib2.HTTPError as http_error: -            resp = http_error -        '''          resp = self._urllib_func(self.url, timeout=320)          data = resp[0]          code = resp[1] @@ -1335,7 +1326,7 @@ _urllib_request = None  #  PubnubAsync -class PubnubAsync(PubnubCoreAsync): +class Pubnub(PubnubCoreAsync):      def __init__(          self,          publish_key, @@ -1348,7 +1339,7 @@ class PubnubAsync(PubnubCoreAsync):          pres_uuid=None,          pooling=True      ): -        super(PubnubAsync, self).__init__( +        super(Pubnub, self).__init__(              publish_key=publish_key,              subscribe_key=subscribe_key,              secret_key=secret_key, @@ -1422,31 +1413,6 @@ class PubnubAsync(PubnubCoreAsync):          else:              self._request_async(request, callback, error, single=single) -''' - -    def _request3_sync( self, request) : -        ## Build URL -        url = self.getUrl(request) -        ## Send Request Expecting JSONP Response -        try: -            response = urllib.request.urlopen(url,timeout=310) -            resp_json = json.loads(response.read().decode("utf-8")) -        except Exception as e: -            return None - -        return resp_json - -    def _request3_async( self, request, callback, single=False ) : -        pass - -    def _request3(self, request, callback=None, single=False): -        if callback is None: -            return self._request3_sync(request,single=single) -        else: -            self._request3_async(request, callback, single=single) -            ''' - -  # Pubnub Twisted  class PubnubTwisted(PubnubCoreAsync): @@ -1481,7 +1447,6 @@ class PubnubTwisted(PubnubCoreAsync):          )          self.headers = {}          self.headers['User-Agent'] = ['Python-Twisted'] -        #self.headers['Accept-Encoding'] = [self.accept_encoding]          self.headers['V'] = [self.version]      def _request(self, request, callback=None, error=None, single=False): diff --git a/python/examples/console.py b/python/examples/console.py index 7798340..5d74517 100644 --- a/python/examples/console.py +++ b/python/examples/console.py @@ -7,7 +7,7 @@  import sys -from Pubnub import PubnubAsync as Pubnub +from Pubnub import Pubnub  import threading  from datetime import datetime diff --git a/python/examples/here-now.py b/python/examples/here-now.py index d03a110..9640cc5 100644 --- a/python/examples/here-now.py +++ b/python/examples/here-now.py @@ -7,7 +7,7 @@  import sys -from Pubnub import PubnubAsync as Pubnub +from Pubnub import Pubnub  publish_key = len(sys.argv) > 1 and sys.argv[1] or 'demo'  subscribe_key = len(sys.argv) > 2 and sys.argv[2] or 'demo' diff --git a/python/examples/history.py b/python/examples/history.py index 7f7466b..603a0f8 100644 --- a/python/examples/history.py +++ b/python/examples/history.py @@ -7,7 +7,7 @@  import sys -from Pubnub import PubnubAsync as Pubnub +from Pubnub import Pubnub  publish_key = len(sys.argv) > 1 and sys.argv[1] or 'demo'  subscribe_key = len(sys.argv) > 2 and sys.argv[2] or 'demo' diff --git a/python/examples/publish.py b/python/examples/publish.py index a1b913b..594e7c4 100644 --- a/python/examples/publish.py +++ b/python/examples/publish.py @@ -7,7 +7,7 @@  import sys -from Pubnub import PubnubAsync as Pubnub +from Pubnub import Pubnub  publish_key = len(sys.argv) > 1 and sys.argv[1] or 'demo'  subscribe_key = len(sys.argv) > 2 and sys.argv[2] or 'demo' diff --git a/python/examples/pubnub-console/pubnub-console b/python/examples/pubnub-console/pubnub-console index a12c77f..7276fb9 100644 --- a/python/examples/pubnub-console/pubnub-console +++ b/python/examples/pubnub-console/pubnub-console @@ -9,7 +9,7 @@  import sys -from Pubnub import PubnubAsync as Pubnub +from Pubnub import Pubnub  import threading  from datetime import datetime diff --git a/python/examples/subscribe.py b/python/examples/subscribe.py index 6cf93b1..9b8b223 100644 --- a/python/examples/subscribe.py +++ b/python/examples/subscribe.py @@ -7,7 +7,7 @@  import sys -from Pubnub import PubnubAsync as Pubnub +from Pubnub import Pubnub  publish_key = len(sys.argv) > 1 and sys.argv[1] or 'demo'  subscribe_key = len(sys.argv) > 2 and sys.argv[2] or 'demo' diff --git a/python/tests/test_grant.py b/python/tests/test_grant.py new file mode 100644 index 0000000..6826335 --- /dev/null +++ b/python/tests/test_grant.py @@ -0,0 +1,199 @@ + + +from Pubnub import Pubnub +import time + +pubnub = Pubnub("demo","demo") +pubnub_pam = Pubnub("pub-c-c077418d-f83c-4860-b213-2f6c77bde29a",  +	"sub-c-e8839098-f568-11e2-a11a-02ee2ddab7fe", "sec-c-OGU3Y2Q4ZWUtNDQwMC00NTI1LThjNWYtNWJmY2M4OGIwNjEy") + + +# Grant permission read true, write true, on channel ( Sync Mode ) +def test_1(): +	resp = pubnub_pam.grant(channel="abcd", auth_key="abcd", read=True, write=True, ttl=1) +	assert resp['message'] == 'Success' +	assert resp['payload'] == { +								'auths': {'abcd': {'r': 1, 'w': 1}}, +								'subscribe_key': 'sub-c-e8839098-f568-11e2-a11a-02ee2ddab7fe', +								'level': 'user', 'channel': 'abcd', 'ttl': 1 +							  } +							 + +# Grant permission read false, write false, on channel ( Sync Mode ) +def test_2(): +	resp = pubnub_pam.grant(channel="abcd", auth_key="abcd", read=False, write=False, ttl=1) +	assert resp['message'] == 'Success' +	assert resp['payload'] == { +								'auths': {'abcd': {'r': 0, 'w': 0}}, +								'subscribe_key': 'sub-c-e8839098-f568-11e2-a11a-02ee2ddab7fe', +								'level': 'user', 'channel': 'abcd', 'ttl': 1 +							  } + +# Grant permission read True, write false, on channel ( Sync Mode ) +def test_3(): +	resp = pubnub_pam.grant(channel="abcd", auth_key="abcd", read=True, write=False, ttl=1) +	assert resp['message'] == 'Success' +	assert resp['payload'] == { +								'auths': {'abcd': {'r': 1, 'w': 0}}, +								'subscribe_key': 'sub-c-e8839098-f568-11e2-a11a-02ee2ddab7fe', +								'level': 'user', 'channel': 'abcd', 'ttl': 1 +							  } + +# Grant permission read False, write True, on channel ( Sync Mode ) +def test_4(): +	resp = pubnub_pam.grant(channel="abcd", auth_key="abcd", read=True, write=False, ttl=1) +	assert resp['message'] == 'Success' +	assert resp['payload'] == { +								'auths': {'abcd': {'r': 1, 'w': 0}}, +								'subscribe_key': 'sub-c-e8839098-f568-11e2-a11a-02ee2ddab7fe', +								'level': 'user', 'channel': 'abcd', 'ttl': 1 +							  } + +# Grant permission read False, write True, on channel ( Sync Mode ), TTL 10 +def test_5(): +	resp = pubnub_pam.grant(channel="abcd", auth_key="abcd", read=True, write=False, ttl=10) +	assert resp['message'] == 'Success' +	assert resp['payload'] == { +								'auths': {'abcd': {'r': 1, 'w': 0}}, +								'subscribe_key': 'sub-c-e8839098-f568-11e2-a11a-02ee2ddab7fe', +								'level': 'user', 'channel': 'abcd', 'ttl': 10 +							  } + +# Grant permission read False, write True, without channel ( Sync Mode ), TTL 10 +def test_6(): +	resp = pubnub_pam.grant(auth_key="abcd", read=True, write=False, ttl=10) +	assert resp['message'] == 'Success' +	assert resp['payload'] == { +								'subscribe_key': 'sub-c-e8839098-f568-11e2-a11a-02ee2ddab7fe', +								'level': 'subkey' , u'r': 1, u'w': 0, 'ttl': 10 +							  } + + +# Grant permission read False, write False, without channel ( Sync Mode ) +def test_7(): +	resp = pubnub_pam.grant(auth_key="abcd", read=False, write=False) +	assert resp['message'] == 'Success' +	assert resp['payload'] == { +								'subscribe_key': 'sub-c-e8839098-f568-11e2-a11a-02ee2ddab7fe', +								'level': 'subkey' , u'r': 0, u'w': 0, 'ttl': 1 +							  } + + +# Complete flow , try publish on forbidden channel, grant permission to auth key and try again. ( Sync Mode) + +def test_8(): +	channel = "test_8-" + str(time.time()) +	message = "Hello World" +	auth_key = "auth-" + channel +	pubnub_pam.set_auth_key(auth_key) +	resp = pubnub_pam.publish(channel=channel,message=message) +	assert resp['message'] == 'Forbidden' +	assert resp['payload'] == {u'channels': [channel]} +	resp = pubnub_pam.grant(channel=channel, read=True, write=True, auth_key=auth_key, ttl=10) +	assert resp == 			{ +								'message': u'Success', +								'payload': {u'auths': {auth_key : {u'r': 1, u'w': 1}}, +								u'subscribe_key': u'sub-c-e8839098-f568-11e2-a11a-02ee2ddab7fe', +								u'level': u'user', u'channel': channel, u'ttl': 10} +							} +	resp = pubnub_pam.publish(channel=channel,message=message) +	assert resp[0] == 1 + + +# Complete flow , try publish on forbidden channel, grant permission to authkey and try again. ( Sync Mode) +# then revoke and try again +def test_9(): +	channel = "test_9-" + str(time.time()) +	message = "Hello World" +	auth_key = "auth-" + channel +	pubnub_pam.set_auth_key(auth_key) +	resp = pubnub_pam.publish(channel=channel,message=message) +	assert resp['message'] == 'Forbidden' +	assert resp['payload'] == {u'channels': [channel]} +	resp = pubnub_pam.grant(channel=channel, read=True, write=True, auth_key=auth_key, ttl=10) +	print resp +	assert resp == 			{ +								'message': u'Success', +								'payload': {u'auths': {auth_key : {u'r': 1, u'w': 1}}, +								u'subscribe_key': u'sub-c-e8839098-f568-11e2-a11a-02ee2ddab7fe', +								u'level': u'user', u'channel': channel, u'ttl': 10} +							} +	resp = pubnub_pam.publish(channel=channel,message=message) +	assert resp[0] == 1 +	resp = pubnub_pam.revoke(channel=channel, auth_key=auth_key) +	print resp +	assert resp == 			{ +								'message': u'Success', +								'payload': {u'auths': {auth_key : {u'r': 0, u'w': 0}}, +								u'subscribe_key': u'sub-c-e8839098-f568-11e2-a11a-02ee2ddab7fe', +								u'level': u'user', u'channel': channel, u'ttl': 1} +							} +	resp = pubnub_pam.publish(channel=channel,message=message) +	assert resp['message'] == 'Forbidden' +	assert resp['payload'] == {u'channels': [channel]} + +# Complete flow , try publish on forbidden channel, grant permission channel level for subkey and try again. ( Sync Mode) +# then revoke and try again +def test_10(): +	channel = "test_10-" + str(time.time()) +	message = "Hello World" +	auth_key = "auth-" + channel +	pubnub_pam.set_auth_key(auth_key) +	resp = pubnub_pam.publish(channel=channel,message=message) +	assert resp['message'] == 'Forbidden' +	assert resp['payload'] == {u'channels': [channel]} +	resp = pubnub_pam.grant(channel=channel, read=True, write=True, ttl=10) +	print resp +	assert resp == 			{ +									'message': u'Success', +									'payload': { u'channels': {channel: {u'r': 1, u'w': 1}}, +									u'subscribe_key': u'sub-c-e8839098-f568-11e2-a11a-02ee2ddab7fe', +									u'level': u'channel', u'ttl': 10} +								} +	resp = pubnub_pam.publish(channel=channel,message=message) +	assert resp[0] == 1 +	resp = pubnub_pam.revoke(channel=channel) +	print resp +	assert resp == 			{ +									'message': u'Success', +									'payload': { u'channels': {channel : {u'r': 0, u'w': 0}}, +									u'subscribe_key': u'sub-c-e8839098-f568-11e2-a11a-02ee2ddab7fe', +									u'level': u'channel', u'ttl': 1} +								} +	resp = pubnub_pam.publish(channel=channel,message=message) +	assert resp['message'] == 'Forbidden' +	assert resp['payload'] == {u'channels': [channel]} + +# Complete flow , try publish on forbidden channel, grant permission subkey level for subkey and try again. ( Sync Mode) +# then revoke and try again +def test_11(): +	channel = "test_11-" + str(time.time()) +	message = "Hello World" +	auth_key = "auth-" + channel +	pubnub_pam.set_auth_key(auth_key) +	resp = pubnub_pam.publish(channel=channel,message=message) +	assert resp['message'] == 'Forbidden' +	assert resp['payload'] == {u'channels': [channel]} +	resp = pubnub_pam.grant(read=True, write=True, ttl=10) +	print resp +	assert resp == 			{ +									'message': u'Success', +									'payload': { u'r': 1, u'w': 1, +									u'subscribe_key': u'sub-c-e8839098-f568-11e2-a11a-02ee2ddab7fe', +									u'level': u'subkey', u'ttl': 10} +								} +	resp = pubnub_pam.publish(channel=channel,message=message) +	assert resp[0] == 1 +	resp = pubnub_pam.revoke() +	print resp +	assert resp == 			{ +									'message': u'Success', +									'payload': {u'r': 0, u'w': 0, +									u'subscribe_key': u'sub-c-e8839098-f568-11e2-a11a-02ee2ddab7fe', +									u'level': u'subkey', u'ttl': 1} +								} +	resp = pubnub_pam.publish(channel=channel,message=message) +	assert resp['message'] == 'Forbidden' +	assert resp['payload'] == {u'channels': [channel]} + + diff --git a/python/tests/test_grant_async.py b/python/tests/test_grant_async.py new file mode 100644 index 0000000..4d38a0a --- /dev/null +++ b/python/tests/test_grant_async.py @@ -0,0 +1,369 @@ + + +from Pubnub import Pubnub +import time + +pubnub = Pubnub("demo","demo") +pubnub_pam = Pubnub("pub-c-c077418d-f83c-4860-b213-2f6c77bde29a",  +	"sub-c-e8839098-f568-11e2-a11a-02ee2ddab7fe", "sec-c-OGU3Y2Q4ZWUtNDQwMC00NTI1LThjNWYtNWJmY2M4OGIwNjEy") + + + +# Grant permission read true, write true, on channel ( Async Mode ) +def test_1(): +	resp = {'response' : None} +	def _callback(response): +		resp['response'] = response + +	def _error(response): +		resp['response'] = response + +	pubnub_pam.grant(channel="abcd", auth_key="abcd", read=True, write=True, ttl=1, callback=_callback, error=_error) +	time.sleep(2) +	assert resp['response'] == { +									'message': u'Success', +									'payload': {u'auths': {u'abcd': {u'r': 1, u'w': 1}}, +									u'subscribe_key': u'sub-c-e8839098-f568-11e2-a11a-02ee2ddab7fe', +									u'level': u'user', u'channel': u'abcd', u'ttl': 1} +								} +							 + +# Grant permission read false, write false, on channel ( Async Mode ) +def test_2(): +	resp = {'response' : None} +	def _callback(response): +		resp['response'] = response + +	def _error(response): +		resp['response'] = response + +	pubnub_pam.grant(channel="abcd", auth_key="abcd", read=False, write=False, ttl=1, callback=_callback, error=_error) +	time.sleep(2) +	assert resp['response'] == { +									'message': u'Success', +									'payload': {u'auths': {u'abcd': {u'r': 0, u'w': 0}}, +									u'subscribe_key': u'sub-c-e8839098-f568-11e2-a11a-02ee2ddab7fe', +									u'level': u'user', u'channel': u'abcd', u'ttl': 1} +								} + + +# Grant permission read True, write false, on channel ( Async Mode ) +def test_3(): +	resp = {'response' : None} +	def _callback(response): +		resp['response'] = response + +	def _error(response): +		resp['response'] = response + +	pubnub_pam.grant(channel="abcd", auth_key="abcd", read=True, write=False, ttl=1, callback=_callback, error=_error) +	time.sleep(2) +	assert resp['response'] == { +									'message': u'Success', +									'payload': {u'auths': {u'abcd': {u'r': 1, u'w': 0}}, +									u'subscribe_key': u'sub-c-e8839098-f568-11e2-a11a-02ee2ddab7fe', +									u'level': u'user', u'channel': u'abcd', u'ttl': 1} +								} + +# Grant permission read False, write True, on channel ( Async Mode ) +def test_4(): +	resp = {'response' : None} +	def _callback(response): +		resp['response'] = response + +	def _error(response): +		resp['response'] = response + +	pubnub_pam.grant(channel="abcd", auth_key="abcd", read=False, write=True, ttl=1, callback=_callback, error=_error) +	time.sleep(2) +	assert resp['response'] == { +									'message': u'Success', +									'payload': {u'auths': {u'abcd': {u'r': 0, u'w': 1}}, +									u'subscribe_key': u'sub-c-e8839098-f568-11e2-a11a-02ee2ddab7fe', +									u'level': u'user', u'channel': u'abcd', u'ttl': 1} +								} + + +# Grant permission read False, write True, on channel ( Async Mode ), TTL 10 +def test_5(): +	resp = {'response' : None} +	def _callback(response): +		resp['response'] = response + +	def _error(response): +		resp['response'] = response + +	pubnub_pam.grant(channel="abcd", auth_key="abcd", read=False, write=True, ttl=10, callback=_callback, error=_error) +	time.sleep(2) +	assert resp['response'] == { +									'message': u'Success', +									'payload': {u'auths': {u'abcd': {u'r': 0, u'w': 1}}, +									u'subscribe_key': u'sub-c-e8839098-f568-11e2-a11a-02ee2ddab7fe', +									u'level': u'user', u'channel': u'abcd', u'ttl': 10} +								} + + +# Grant permission read False, write True, without channel ( Async Mode ), TTL 10 +def test_6(): +	resp = {'response' : None} +	def _callback(response): +		resp['response'] = response + +	def _error(response): +		resp['response'] = response + +	pubnub_pam.grant(auth_key="abcd", read=False, write=True, ttl=10, callback=_callback, error=_error) +	time.sleep(2) +	assert resp['response'] == { +									'message': u'Success', +									'payload': { u'r': 0, u'w': 1, +									u'subscribe_key': u'sub-c-e8839098-f568-11e2-a11a-02ee2ddab7fe', +									u'level': u'subkey', u'ttl': 10} +								} + + +# Grant permission read False, write False, without channel ( Async Mode ) +def test_7(): +	resp = {'response' : None} +	def _callback(response): +		resp['response'] = response + +	def _error(response): +		resp['response'] = response + +	pubnub_pam.grant(auth_key="abcd", read=False, write=False, callback=_callback, error=_error) +	time.sleep(2) +	assert resp['response'] == { +									'message': u'Success', +									'payload': { u'r': 0, u'w': 0, +									u'subscribe_key': u'sub-c-e8839098-f568-11e2-a11a-02ee2ddab7fe', +									u'level': u'subkey', u'ttl': 1} +								} + + +# Complete flow , try publish on forbidden channel, grant permission to subkey and try again. ( Sync Mode) + +def test_8(): +	channel = "test_8-" + str(time.time()) +	message = "Hello World" +	auth_key = "auth-" + channel +	pubnub_pam.set_auth_key(auth_key) + + + +	def _cb1(resp, ch=None): +		assert False +	def _err1(resp): +		assert resp['message'] == 'Forbidden' +		assert resp['payload'] == {u'channels': [channel]} +	pubnub_pam.publish(channel=channel,message=message, callback=_cb1, error=_err1) +	time.sleep(2) + + +	def _cb2(resp, ch=None): +		assert resp == 		{ +								'message': u'Success', +								'payload': {u'auths': {auth_key : {u'r': 1, u'w': 1}}, +								u'subscribe_key': u'sub-c-e8839098-f568-11e2-a11a-02ee2ddab7fe', +								u'level': u'user', u'channel': channel, u'ttl': 10} +							} +	def _err2(resp): +		assert False + + +	resp = pubnub_pam.grant(channel=channel, read=True, write=True, auth_key=auth_key, ttl=10, callback=_cb2, error=_err2) +	time.sleep(2) + +	def _cb3(resp, ch=None): +		assert resp[0] == 1 +	def _err3(resp): +		assert False + +	pubnub_pam.publish(channel=channel,message=message, callback=_cb3, error=_err3) +	time.sleep(2) + + + + + +# Complete flow , try publish on forbidden channel, grant permission to authkey and try again.  +# then revoke and try again +def test_9(): +	channel = "test_9-" + str(time.time()) +	message = "Hello World" +	auth_key = "auth-" + channel +	pubnub_pam.set_auth_key(auth_key) + +	def _cb1(resp, ch=None): +		assert False +	def _err1(resp): +		assert resp['message'] == 'Forbidden' +		assert resp['payload'] == {u'channels': [channel]} +	pubnub_pam.publish(channel=channel,message=message, callback=_cb1, error=_err1) +	time.sleep(2) + + +	def _cb2(resp, ch=None): +		assert resp == 		{ +								'message': u'Success', +								'payload': {u'auths': {auth_key : {u'r': 1, u'w': 1}}, +								u'subscribe_key': u'sub-c-e8839098-f568-11e2-a11a-02ee2ddab7fe', +								u'level': u'user', u'channel': channel, u'ttl': 10} +							} +	def _err2(resp): +		assert False + + +	pubnub_pam.grant(channel=channel, read=True, write=True, auth_key=auth_key, ttl=10, callback=_cb2, error=_err2) +	time.sleep(2) + +	def _cb3(resp, ch=None): +		assert resp[0] == 1 +	def _err3(resp): +		assert False + +	pubnub_pam.publish(channel=channel,message=message, callback=_cb3, error=_err3) +	time.sleep(2) + +	def _cb4(resp, ch=None): +		assert resp == 		{ +								'message': u'Success', +								'payload': {u'auths': {auth_key : {u'r': 0, u'w': 0}}, +								u'subscribe_key': u'sub-c-e8839098-f568-11e2-a11a-02ee2ddab7fe', +								u'level': u'user', u'channel': channel, u'ttl': 1} +							} +	def _err4(resp): +		assert False +	pubnub_pam.revoke(channel=channel, auth_key=auth_key, callback=_cb4, error=_err4) +	time.sleep(2) + +	def _cb5(resp, ch=None): +		assert False +	def _err5(resp): +		assert resp['message'] == 'Forbidden' +		assert resp['payload'] == {u'channels': [channel]} +	pubnub_pam.publish(channel=channel,message=message, callback=_cb5, error=_err5) +	time.sleep(2) + + + + +# Complete flow , try publish on forbidden channel, grant permission channel level for subkey and try again. +# then revoke and try again +def test_10(): +	channel = "test_10-" + str(time.time()) +	message = "Hello World" +	auth_key = "auth-" + channel +	pubnub_pam.set_auth_key(auth_key) + +	def _cb1(resp, ch=None): +		assert False +	def _err1(resp): +		assert resp['message'] == 'Forbidden' +		assert resp['payload'] == {u'channels': [channel]} +	pubnub_pam.publish(channel=channel,message=message, callback=_cb1, error=_err1) +	time.sleep(2) + + +	def _cb2(resp, ch=None): +		assert resp == 		{ +									'message': u'Success', +									'payload': { u'channels': {channel: {u'r': 1, u'w': 1}}, +									u'subscribe_key': u'sub-c-e8839098-f568-11e2-a11a-02ee2ddab7fe', +									u'level': u'channel', u'ttl': 10} +								} +	def _err2(resp): +		assert False + + +	pubnub_pam.grant(channel=channel, read=True, write=True, ttl=10, callback=_cb2, error=_err2) +	time.sleep(2) + +	def _cb3(resp, ch=None): +		assert resp[0] == 1 +	def _err3(resp): +		assert False + +	pubnub_pam.publish(channel=channel,message=message, callback=_cb3, error=_err3) +	time.sleep(2) + +	def _cb4(resp, ch=None): +		assert resp == 		{ +									'message': u'Success', +									'payload': { u'channels': {channel : {u'r': 0, u'w': 0}}, +									u'subscribe_key': u'sub-c-e8839098-f568-11e2-a11a-02ee2ddab7fe', +									u'level': u'channel', u'ttl': 1} +								} +	def _err4(resp): +		assert False +	pubnub_pam.revoke(channel=channel, callback=_cb4, error=_err4) +	time.sleep(2) + +	def _cb5(resp, ch=None): +		assert False +	def _err5(resp): +		assert resp['message'] == 'Forbidden' +		assert resp['payload'] == {u'channels': [channel]} +	pubnub_pam.publish(channel=channel,message=message, callback=_cb5, error=_err5) +	time.sleep(2) + + + +# Complete flow , try publish on forbidden channel, grant permission subkey level for subkey and try again. +# then revoke and try again +def test_11(): +	channel = "test_11-" + str(time.time()) +	message = "Hello World" +	auth_key = "auth-" + channel +	pubnub_pam.set_auth_key(auth_key) + +	def _cb1(resp, ch=None): +		assert False +	def _err1(resp): +		assert resp['message'] == 'Forbidden' +		assert resp['payload'] == {u'channels': [channel]} +	pubnub_pam.publish(channel=channel,message=message, callback=_cb1, error=_err1) +	time.sleep(2) + + +	def _cb2(resp, ch=None): +		assert resp == 		{ +									'message': u'Success', +									'payload': { u'r': 1, u'w': 1, +									u'subscribe_key': u'sub-c-e8839098-f568-11e2-a11a-02ee2ddab7fe', +									u'level': u'subkey', u'ttl': 10} +								} +	def _err2(resp): +		assert False + + +	pubnub_pam.grant(read=True, write=True, ttl=10, callback=_cb2, error=_err2) +	time.sleep(2) + +	def _cb3(resp, ch=None): +		assert resp[0] == 1 +	def _err3(resp): +		assert False + +	pubnub_pam.publish(channel=channel,message=message, callback=_cb3, error=_err3) +	time.sleep(2) + +	def _cb4(resp, ch=None): +		assert resp == 		{ +									'message': u'Success', +									'payload': {u'r': 0, u'w': 0, +									u'subscribe_key': u'sub-c-e8839098-f568-11e2-a11a-02ee2ddab7fe', +									u'level': u'subkey', u'ttl': 1} +								} +	def _err4(resp): +		assert False +	pubnub_pam.revoke(callback=_cb4, error=_err4) +	time.sleep(2) + +	def _cb5(resp, ch=None): +		assert False +	def _err5(resp): +		assert resp['message'] == 'Forbidden' +		assert resp['payload'] == {u'channels': [channel]} +	pubnub_pam.publish(channel=channel,message=message, callback=_cb5, error=_err5) +	time.sleep(2) | 
