diff options
| author | Devendra | 2015-06-25 11:42:00 +0530 |
|---|---|---|
| committer | Devendra | 2015-06-25 11:42:00 +0530 |
| commit | ad89de8312f3f407150c7eb411cbf02765910e53 (patch) | |
| tree | 6f683a1d154a4d4f3bb11ed6f2d56ec813db6ccb /python/tests/test_history.py | |
| parent | 4a44c563ea8af7211197d166596be41ede05c179 (diff) | |
| parent | 232f7389274f0d9ff06835fc5da0970f7918ba25 (diff) | |
| download | pubnub-python-ad89de8312f3f407150c7eb411cbf02765910e53.tar.bz2 | |
Merge branch 'develop'
Diffstat (limited to 'python/tests/test_history.py')
| -rw-r--r-- | python/tests/test_history.py | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/python/tests/test_history.py b/python/tests/test_history.py new file mode 100644 index 0000000..a5feb37 --- /dev/null +++ b/python/tests/test_history.py @@ -0,0 +1,58 @@ +from pubnub import Pubnub +import time +import random +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): + return "rand-" + str(random.random()) + "-" + msg + +channel = rand("channel") +channel_enc = rand("channel_enc") +channel_pam = rand("channel_pam") + +messages = [] + + +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'] + +def test_2(): + time.sleep(3) + hresp = pubnub.history(channel=channel, count=20, include_token=True) + hresp2 = pubnub_enc.history(channel=channel_enc, count=20, include_token=True) + hresp3 = pubnub_pam.history(channel=channel_pam, count=20, include_token=True) + hresp4 = pubnub_pam.history(channel=channel_pam + "no_rw", count=20, include_token=True) + assert len(hresp[0]) == len(messages) + assert hresp[0][0]['timetoken'] + assert len(hresp2[0]) == len(messages) + assert hresp2[0][0]['timetoken'] + assert len(hresp3[0]) == len(messages) + assert hresp3[0][0]['timetoken'] + assert hresp4['message'] == 'Forbidden' + assert channel_pam + "no_rw" in hresp4['payload']['channels'] |
