diff options
| -rw-r--r-- | pubnub.py | 17 | ||||
| -rw-r--r-- | python/tests/test_history.py | 9 | 
2 files changed, 19 insertions, 7 deletions
| @@ -919,11 +919,14 @@ class PubnubBase(object):          """          def _get_decrypted_history(resp): -            if resp and resp[1] is not None and self.cipher_key: -                msgs  = resp[0] -                for i in range(0,len(msgs)): -                    msgs[i] = self.decrypt(msgs[i]) -            return resp +           try: +               if resp and resp[1] is not None and self.cipher_key: +                   msgs  = resp[0] +                   for i in range(0,len(msgs)): +                       msgs[i] = self.decrypt(msgs[i]) +           except KeyError: +                pass  +           return resp          def _history_callback(resp):              if callback is not None: @@ -940,7 +943,7 @@ class PubnubBase(object):          params['reverse'] = reverse          params['start'] = start          params['end'] = end -        params['auth_key'] = self.auth_key +        params['auth'] = self.auth_key          params['pnsdk'] = self.pnsdk          params['include_token'] = 'true' if include_token else 'false' @@ -2187,7 +2190,7 @@ class Pubnub(PubnubCore):          if callback is None:              return get_data_for_user(self._request_sync(request, timeout=timeout))          else: -            self._request_async(request, callback, error, single=single, timeout=timeout) +            return self._request_async(request, callback, error, single=single, timeout=timeout)  # Pubnub Twisted diff --git a/python/tests/test_history.py b/python/tests/test_history.py index 3cf8e03..1592e11 100644 --- a/python/tests/test_history.py +++ b/python/tests/test_history.py @@ -6,6 +6,7 @@ from nose.tools import with_setup  pubnub = Pubnub("ds","ds")  pubnub_enc = Pubnub(publish_key="ds",subscribe_key="ds",cipher_key="enigma") +pubnub_pam = Pubnub(publish_key="pam", subscribe_key="pam", secret_key="pam")  def rand(msg): @@ -13,6 +14,7 @@ def rand(msg):  channel = rand("channel")  channel_enc = rand("channel_enc") +channel_pam = rand("channel_pam")  messages = [] @@ -21,8 +23,10 @@ def setup_func():       for i in range(0,20):       	msg = rand("message-" + str(i))       	messages.append(msg) +     	pubnub_pam.grant(channel=channel_pam, read=True, write=True, ttl=144000)       	pubnub.publish(channel=channel, message=msg)       	pubnub_enc.publish(channel=channel_enc, message=msg) +     	pubnub_pam.publish(channel=channel_pam, message=msg)  @with_setup(setup_func) @@ -30,8 +34,13 @@ def test_1():  	time.sleep(3)  	hresp = pubnub.history(channel=channel, count=20)  	hresp2 = pubnub_enc.history(channel=channel_enc, count=20) +	hresp3 = pubnub_pam.history(channel=channel_pam, count=20) +	hresp4 = pubnub_pam.history(channel=channel_pam + "no_rw", count=20)  	assert hresp[0] == messages  	assert hresp2[0] == messages +	assert hresp3[0] == messages +	assert hresp4['message'] == 'Forbidden' +	assert channel_pam + "no_rw" in hresp4['payload']['channels'] | 
