Skip to content

Commit

Permalink
history fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Devendra committed Jun 18, 2015
1 parent d6455ba commit 276bf54
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
17 changes: 10 additions & 7 deletions pubnub.py
Original file line number Diff line number Diff line change
Expand Up @@ -919,11 +919,14 @@ def history(self, channel, count=100, reverse=False,
"""

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:
Expand All @@ -940,7 +943,7 @@ def _history_callback(resp):
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'

Expand Down Expand Up @@ -2187,7 +2190,7 @@ def _request(self, request, callback=None, error=None, single=False, timeout=5):
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

Expand Down
9 changes: 9 additions & 0 deletions python/tests/test_history.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@

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):
return "rand-" + str(random.random()) + "-" + msg

channel = rand("channel")
channel_enc = rand("channel_enc")
channel_pam = rand("channel_pam")

messages = []

Expand All @@ -21,17 +23,24 @@ 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)
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']



0 comments on commit 276bf54

Please sign in to comment.