diff options
Diffstat (limited to 'python-twisted/tests')
| -rw-r--r-- | python-twisted/tests/unit-test-full.py | 2 | ||||
| -rw-r--r-- | python-twisted/tests/unit-test.py | 107 | ||||
| -rw-r--r-- | python-twisted/tests/unit-tests.py | 107 |
3 files changed, 109 insertions, 107 deletions
diff --git a/python-twisted/tests/unit-test-full.py b/python-twisted/tests/unit-test-full.py index f593d11..c5940af 100644 --- a/python-twisted/tests/unit-test-full.py +++ b/python-twisted/tests/unit-test-full.py @@ -19,6 +19,8 @@ import sys sys.path.append('../') +sys.path.append('./') +sys.path.append('../common/') from Pubnub import Pubnub publish_key = len(sys.argv) > 1 and sys.argv[1] or 'demo' diff --git a/python-twisted/tests/unit-test.py b/python-twisted/tests/unit-test.py deleted file mode 100644 index 843f939..0000000 --- a/python-twisted/tests/unit-test.py +++ /dev/null @@ -1,107 +0,0 @@ -## www.pubnub.com - PubNub Real-time push service in the cloud. -# coding=utf8 - -## PubNub Real-time Push APIs and Notifications Framework -## Copyright (c) 2010 Stephen Blum -## http://www.pubnub.com/ - -## ----------------------------------- -## PubNub 3.1 Real-time Push Cloud API -## ----------------------------------- - -import sys -sys.path.append('../') -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' -secret_key = len(sys.argv) > 3 and sys.argv[3] or 'demo' -cipher_key = len(sys.argv) > 4 and sys.argv[4] or '' ##(Cipher key is Optional) -ssl_on = len(sys.argv) > 5 and bool(sys.argv[5]) or False - -## ----------------------------------------------------------------------- -## Initiat Class -## ----------------------------------------------------------------------- -pubnub = Pubnub( publish_key, subscribe_key, secret_key, cipher_key, ssl_on ) -crazy = ' ~`!@#$%^&*( 顶顅 Ȓ)+=[]\\{}|;\':",./<>?abcd' - -## --------------------------------------------------------------------------- -## Unit Test Function -## --------------------------------------------------------------------------- -def test( trial, name ) : - if trial : - print( 'PASS: ' + name ) - else : - print( 'FAIL: ' + name ) - -## ----------------------------------------------------------------------- -## Time Example -## ----------------------------------------------------------------------- -def time_complete(timestamp): - print(timestamp) - -pubnub.time({ 'callback' : time_complete }) - -## ----------------------------------------------------------------------- -## History Example -## ----------------------------------------------------------------------- -def history_complete(messages): - print(messages) - -pubnub.history( { - 'channel' : crazy, - 'limit' : 10, - 'callback' : history_complete -}) - -## ----------------------------------------------------------------------- -## Publish Example -## ----------------------------------------------------------------------- -def publish_complete(info): - print(info) - -pubnub.publish({ - 'channel' : crazy, - 'message' : {'one': 'Hello World! --> ɂ顶@#$%^&*()!', 'two': 'hello2'}, - 'callback' : publish_complete -}) - -## ----------------------------------------------------------------------- -## Subscribe Example -## ----------------------------------------------------------------------- -def message_received(message): - print(message) - print('Disconnecting...') - pubnub.unsubscribe({ 'channel' : crazy }) - - def done() : - print('final connection, done :)') - pubnub.unsubscribe({ 'channel' : crazy }) - pubnub.stop() - - def dumpster(message) : - print('never see this') - print(message) - - print('reconnecting...') - pubnub.subscribe({ - 'channel' : crazy, - 'connect' : done, - 'callback' : dumpster - }) - -def connected() : - pubnub.publish({ - 'channel' : crazy, - 'message' : { 'Info' : 'Connected!' } - }) - -pubnub.subscribe({ - 'channel' : crazy, - 'connect' : connected, - 'callback' : message_received -}) -## ----------------------------------------------------------------------- -## IO Event Loop -## ----------------------------------------------------------------------- -pubnub.start() diff --git a/python-twisted/tests/unit-tests.py b/python-twisted/tests/unit-tests.py new file mode 100644 index 0000000..f143a3a --- /dev/null +++ b/python-twisted/tests/unit-tests.py @@ -0,0 +1,107 @@ + +import sys +import time + +sys.path.append('../../common') +sys.path.append('../common') +sys.path.append('..') +sys.path.append('.') + +from PubnubUnitTest import Suite +from Pubnub import Pubnub + +pubnub = Pubnub("demo","demo") + +tests_count = 1 + 2 + 1 +test_suite = Suite(pubnub,tests_count) + +tests = [] + + + +def test_publish(): + channel = "hello" + str(time.time()) + name = "Publish Test" + def success(r): + test_suite.test(r[0] == 1, name) + + def fail(e): + test_suite.test(False, msg , e) + + + pubnub.publish({ + 'channel' : 'hello', + 'message' : 'hi', + 'callback' : success, + 'error' : fail + }) +tests.append(test_publish) + +#""" +def test_subscribe_publish(): + channel = "hello" + str(time.time()) + name = "Subscribe Publish Test" + publish_msg = "This is Pubnub Python-Twisted" + def connect(): + #print 'connect' + def success(r): + test_suite.test(r[0] == 1, name, "publish success") + + def fail(e): + test_suite.test(False, name , "Publish Failed", e) + + pubnub.publish({ + 'channel' : channel, + 'message' : publish_msg, + 'callback' : success, + 'error' : fail + }) + + def callback(r): + test_suite.test(r == publish_msg, name, "message received") + + pubnub.subscribe({ + 'channel' : channel, + 'callback' : callback, + 'connect' : connect + }) +tests.append(test_subscribe_publish) +#""" + +def test_here_now(): + channel = "hello12" #+ str(time.time()) + name = "Here Now Test" + + def connect(): + print 'connect' + def call_here_now(): + print 'call_here_now' + def success(r): + test_suite.test(r['occupancy'] == 1, name, "Here Now success") + + def fail(e): + test_suite.test(False, name , "Here Now Failed", e) + + pubnub.here_now({ + 'channel' : channel, + 'callback' : success, + 'error' : fail + }) + pubnub.timeout(5, call_here_now) + + def callback(r): + pass + print 'Subscribe' + pubnub.subscribe({ + 'channel' : channel, + 'callback' : callback, + 'connect' : connect + }) +tests.append(test_here_now) + + + + +for t in tests: t() + +pubnub.start() |
