diff options
Diffstat (limited to 'python-twisted/tests')
| -rw-r--r-- | python-twisted/tests/delivery.py | 140 | ||||
| -rwxr-xr-x | python-twisted/tests/subscribe-test.py | 86 | ||||
| -rw-r--r-- | python-twisted/tests/unit-test-full.py | 177 | ||||
| -rw-r--r-- | python-twisted/tests/unit-tests.py | 148 |
4 files changed, 290 insertions, 261 deletions
diff --git a/python-twisted/tests/delivery.py b/python-twisted/tests/delivery.py index dc6b9e2..3ba221b 100644 --- a/python-twisted/tests/delivery.py +++ b/python-twisted/tests/delivery.py @@ -1,4 +1,4 @@ -## www.pubnub.com - PubNub Real-time push service in the cloud. +## www.pubnub.com - PubNub Real-time push service in the cloud. # coding=utf8 ## PubNub Real-time Push APIs and Notifications Framework @@ -20,93 +20,100 @@ from Pubnub import Pubnub ## ----------------------------------------------------------------------- ## Configuration ## ----------------------------------------------------------------------- -publish_key = len(sys.argv) > 1 and sys.argv[1] or 'demo' +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 'demo' -ssl_on = len(sys.argv) > 5 and bool(sys.argv[5]) or False -origin = len(sys.argv) > 6 and sys.argv[6] or 'pubsub.pubnub.com' +secret_key = len(sys.argv) > 3 and sys.argv[3] or 'demo' +cipher_key = len(sys.argv) > 4 and sys.argv[4] or 'demo' +ssl_on = len(sys.argv) > 5 and bool(sys.argv[5]) or False +origin = len(sys.argv) > 6 and sys.argv[6] or 'pubsub.pubnub.com' origin = '184.72.9.220' ## ----------------------------------------------------------------------- ## Analytics ## ----------------------------------------------------------------------- analytics = { - 'publishes' : 0, ## Total Send Requests - 'received' : 0, ## Total Received Messages (Deliveries) - 'queued' : 0, ## Total Unreceived Queue (UnDeliveries) - 'successful_publishes' : 0, ## Confirmed Successful Publish Request - 'failed_publishes' : 0, ## Confirmed UNSuccessful Publish Request - 'failed_deliveries' : 0, ## (successful_publishes - received) - 'deliverability' : 0 ## Percentage Delivery + 'publishes': 0, # Total Send Requests + 'received': 0, # Total Received Messages (Deliveries) + 'queued': 0, # Total Unreceived Queue (UnDeliveries) + 'successful_publishes': 0, # Confirmed Successful Publish Request + 'failed_publishes': 0, # Confirmed UNSuccessful Publish Request + 'failed_deliveries': 0, # (successful_publishes - received) + 'deliverability': 0 # Percentage Delivery } trips = { - 'last' : None, - 'current' : None, - 'max' : 0, - 'avg' : 0 + 'last': None, + 'current': None, + 'max': 0, + 'avg': 0 } ## ----------------------------------------------------------------------- ## Initiat Class ## ----------------------------------------------------------------------- channel = 'deliverability-' + str(time.time()) -pubnub = Pubnub( +pubnub = Pubnub( publish_key, subscribe_key, - secret_key = secret_key, - cipher_key = cipher_key, - ssl_on = ssl_on, - origin = origin + secret_key=secret_key, + cipher_key=cipher_key, + ssl_on=ssl_on, + origin=origin ) ## ----------------------------------------------------------------------- ## BENCHMARK ## ----------------------------------------------------------------------- -def publish_sent(info = None): - if info and info[0]: analytics['successful_publishes'] += 1 - else: analytics['failed_publishes'] += 1 + + +def publish_sent(info=None): + if info and info[0]: + analytics['successful_publishes'] += 1 + else: + analytics['failed_publishes'] += 1 analytics['publishes'] += 1 - analytics['queued'] += 1 + analytics['queued'] += 1 + + pubnub.timeout(send, 0.1) - pubnub.timeout( send, 0.1 ) def send(): if analytics['queued'] > 100: analytics['queued'] -= 10 - return pubnub.timeout( send, 10 ) + return pubnub.timeout(send, 10) pubnub.publish({ - 'channel' : channel, - 'callback' : publish_sent, - 'message' : "1234567890" + 'channel': channel, + 'callback': publish_sent, + 'message': "1234567890" }) + def received(message): - analytics['queued'] -= 1 + analytics['queued'] -= 1 analytics['received'] += 1 current_trip = trips['current'] = str(datetime.datetime.now())[0:19] - last_trip = trips['last'] = str( + last_trip = trips['last'] = str( datetime.datetime.now() - datetime.timedelta(seconds=1) )[0:19] ## New Trip Span (1 Second) - if not trips.has_key(current_trip) : + if current_trip not in trips: trips[current_trip] = 0 ## Average - if trips.has_key(last_trip): + if last_trip in trips: trips['avg'] = (trips['avg'] + trips[last_trip]) / 2 ## Increment Trip Counter trips[current_trip] = trips[current_trip] + 1 ## Update Max - if trips[current_trip] > trips['max'] : + if trips[current_trip] > trips['max']: trips['max'] = trips[current_trip] + def show_status(): ## Update Failed Deliveries analytics['failed_deliveries'] = \ @@ -115,45 +122,46 @@ def show_status(): ## Update Deliverability analytics['deliverability'] = ( - float(analytics['received']) / \ + float(analytics['received']) / float(analytics['successful_publishes'] or 1.0) ) * 100.0 ## Print Display - print( ( - "max:%(max)03d/sec " + \ - "avg:%(avg)03d/sec " + \ - "pubs:%(publishes)05d " + \ - "received:%(received)05d " + \ - "spub:%(successful_publishes)05d " + \ - "fpub:%(failed_publishes)05d " + \ - "failed:%(failed_deliveries)05d " + \ - "queued:%(queued)03d " + \ - "delivery:%(deliverability)03f%% " + \ - "" - ) % { - 'max' : trips['max'], - 'avg' : trips['avg'], - 'publishes' : analytics['publishes'], - 'received' : analytics['received'], - 'successful_publishes' : analytics['successful_publishes'], - 'failed_publishes' : analytics['failed_publishes'], - 'failed_deliveries' : analytics['failed_deliveries'], - 'publishes' : analytics['publishes'], - 'deliverability' : analytics['deliverability'], - 'queued' : analytics['queued'] - } ) - pubnub.timeout( show_status, 1 ) + print(( + "max:%(max)03d/sec " + + "avg:%(avg)03d/sec " + + "pubs:%(publishes)05d " + + "received:%(received)05d " + + "spub:%(successful_publishes)05d " + + "fpub:%(failed_publishes)05d " + + "failed:%(failed_deliveries)05d " + + "queued:%(queued)03d " + + "delivery:%(deliverability)03f%% " + + "" + ) % { + 'max': trips['max'], + 'avg': trips['avg'], + 'publishes': analytics['publishes'], + 'received': analytics['received'], + 'successful_publishes': analytics['successful_publishes'], + 'failed_publishes': analytics['failed_publishes'], + 'failed_deliveries': analytics['failed_deliveries'], + 'publishes': analytics['publishes'], + 'deliverability': analytics['deliverability'], + 'queued': analytics['queued'] + }) + pubnub.timeout(show_status, 1) + def connected(): show_status() - pubnub.timeout( send, 1 ) + pubnub.timeout(send, 1) -print( "Connected: %s\n" % origin ) +print("Connected: %s\n" % origin) pubnub.subscribe({ - 'channel' : channel, - 'connect' : connected, - 'callback' : received + 'channel': channel, + 'connect': connected, + 'callback': received }) ## ----------------------------------------------------------------------- diff --git a/python-twisted/tests/subscribe-test.py b/python-twisted/tests/subscribe-test.py index 0d4c65e..6ff4a35 100755 --- a/python-twisted/tests/subscribe-test.py +++ b/python-twisted/tests/subscribe-test.py @@ -1,4 +1,4 @@ -## www.pubnub.com - PubNub Real-time push service in the cloud. +## www.pubnub.com - PubNub Real-time push service in the cloud. # coding=utf8 ## PubNub Real-time Push APIs and Notifications Framework @@ -16,18 +16,18 @@ from Pubnub import Pubnub from functools import partial from threading import current_thread import threading -publish_key = len(sys.argv) > 1 and sys.argv[1] or 'demo' +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 None -ssl_on = len(sys.argv) > 5 and bool(sys.argv[5]) or False +secret_key = len(sys.argv) > 3 and sys.argv[3] or 'demo' +cipher_key = len(sys.argv) > 4 and sys.argv[4] or None +ssl_on = len(sys.argv) > 5 and bool(sys.argv[5]) or False ## ----------------------------------------------------------------------- ## Initiate Pubnub State ## ----------------------------------------------------------------------- #pubnub = Pubnub( publish_key, subscribe_key, secret_key, cipher_key, ssl_on ) -pubnub = Pubnub( publish_key, subscribe_key, secret_key, ssl_on ) -crazy = 'hello_world' +pubnub = Pubnub(publish_key, subscribe_key, secret_key, ssl_on) +crazy = 'hello_world' current = -1 @@ -37,9 +37,12 @@ received = 0 ## ----------------------------------------------------------------------- ## Subscribe Example ## ----------------------------------------------------------------------- + + def message_received(message): print message + def check_received(message): global current global errors @@ -53,18 +56,19 @@ def check_received(message): else: received += 1 print 'active thread count : ', threading.activeCount() - print 'errors = ' , errors + print 'errors = ', errors print current_thread().getName(), ' , ', 'received = ', received if received != message: - print '********** MISSED **************** ', message - received + print '********** MISSED **************** ', message - received current = message - -def connected_test(ch) : - print 'Connected' , ch -def connected(ch) : +def connected_test(ch): + print 'Connected', ch + + +def connected(ch): pass @@ -75,57 +79,63 @@ pubnub.subscribe({ 'callback' : message_received }) ''' + + def cb1(): - pubnub.subscribe({ - 'channel' : 'efgh1', - 'connect' : connected, - 'callback' : message_received - }) + pubnub.subscribe({ + 'channel': 'efgh1', + 'connect': connected, + 'callback': message_received + }) + def cb2(): - pubnub.subscribe({ - 'channel' : 'dsm-test', - 'connect' : connected_test, - 'callback' : check_received - }) + pubnub.subscribe({ + 'channel': 'dsm-test', + 'connect': connected_test, + 'callback': check_received + }) + def cb3(): - pubnub.unsubscribe({'channel' : 'efgh1'}) + pubnub.unsubscribe({'channel': 'efgh1'}) + def cb4(): - pubnub.unsubscribe({'channel' : 'abcd1'}) + pubnub.unsubscribe({'channel': 'abcd1'}) + def subscribe(channel): - pubnub.subscribe({ - 'channel' : channel, - 'connect' : connected, - 'callback' : message_received - }) + pubnub.subscribe({ + 'channel': channel, + 'connect': connected, + 'callback': message_received + }) print threading.activeCount() -pubnub.timeout(15,cb1) +pubnub.timeout(15, cb1) -pubnub.timeout(30,cb2) +pubnub.timeout(30, cb2) -pubnub.timeout(45,cb3) +pubnub.timeout(45, cb3) -pubnub.timeout(60,cb4) +pubnub.timeout(60, cb4) #''' -for x in range(1,1000): +for x in range(1, 1000): #print x def y(t): subscribe('channel-' + str(t)) def z(t): - pubnub.unsubscribe({'channel' : 'channel-' + str(t)}) + pubnub.unsubscribe({'channel': 'channel-' + str(t)}) - pubnub.timeout(x + 5, partial(y,x)) - pubnub.timeout(x + 25, partial(z, x)) + pubnub.timeout(x + 5, partial(y, x)) + pubnub.timeout(x + 25, partial(z, x)) x += 10 #''' diff --git a/python-twisted/tests/unit-test-full.py b/python-twisted/tests/unit-test-full.py index c5940af..f8be1cc 100644 --- a/python-twisted/tests/unit-test-full.py +++ b/python-twisted/tests/unit-test-full.py @@ -1,4 +1,4 @@ -## www.pubnub.com - PubNub Real-time push service in the cloud. +## www.pubnub.com - PubNub Real-time push service in the cloud. # coding=utf8 ## PubNub Real-time Push APIs and Notifications Framework @@ -8,10 +8,10 @@ ## TODO Tests ## ## - wait 20 minutes, send a message, receive and success. -## - -## - -## -## +## - +## - +## +## ## ----------------------------------- ## PubNub 3.1 Real-time Push Cloud API @@ -23,21 +23,21 @@ sys.path.append('./') sys.path.append('../common/') from Pubnub import Pubnub -publish_key = len(sys.argv) > 1 and sys.argv[1] or 'demo' +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 None -cipher_key = len(sys.argv) > 4 and sys.argv[4] or None -ssl_on = len(sys.argv) > 5 and bool(sys.argv[5]) or False +secret_key = len(sys.argv) > 3 and sys.argv[3] or None +cipher_key = len(sys.argv) > 4 and sys.argv[4] or None +ssl_on = len(sys.argv) > 5 and bool(sys.argv[5]) or False ## ----------------------------------------------------------------------- ## Command Line Options Supplied PubNub ## ----------------------------------------------------------------------- pubnub_user_supplied_options = Pubnub( - publish_key, ## OPTIONAL (supply None to disable) - subscribe_key, ## REQUIRED - secret_key, ## OPTIONAL (supply None to disable) - cipher_key, ## OPTIONAL (supply None to disable) - ssl_on ## OPTIONAL (supply None to disable) + publish_key, # OPTIONAL (supply None to disable) + subscribe_key, # REQUIRED + secret_key, # OPTIONAL (supply None to disable) + cipher_key, # OPTIONAL (supply None to disable) + ssl_on # OPTIONAL (supply None to disable) ) ## ----------------------------------------------------------------------- @@ -54,15 +54,15 @@ pubnub_high_security = Pubnub( 'sec-c-MTliNDE0NTAtYjY4Ni00MDRkLTllYTItNDhiZGE0N2JlYzBl', ## Cipher Key - 'YWxzamRmbVjFaa05HVnGFqZHM3NXRBS73jxmhVMkjiwVVXV1d5UrXR1JLSkZFRr'+ - 'WVd4emFtUm1iR0TFpUZvbiBoYXMgYmVlbxWkhNaF3uUi8kM0YkJTEVlZYVFjBYi'+ - 'jFkWFIxSkxTa1pGUjd874hjklaTFpUwRVuIFNob3VsZCB5UwRkxUR1J6YVhlQWa'+ - 'V1ZkNGVH32mDkdho3pqtRnRVbTFpUjBaeGUgYXNrZWQtZFoKjda40ZWlyYWl1eX'+ - 'U4RkNtdmNub2l1dHE2TTA1jd84jkdJTbFJXYkZwWlZtRnKkWVrSRhhWbFpZVmFz'+ - 'c2RkZmTFpUpGa1dGSXhTa3hUYTFwR1Vpkm9yIGluZm9ybWFNfdsWQdSiiYXNWVX'+ - 'RSblJWYlRGcFVqQmFlRmRyYUU0MFpXbHlZV2wxZVhVNFJrTnR51YjJsMWRIRTJU'+ - 'W91ciBpbmZvcm1hdGliBzdWJtaXR0ZWQb3UZSBhIHJlc3BvbnNlLCB3ZWxsIHJl'+ - 'VEExWdHVybiB0am0aW9uIb24gYXMgd2UgcG9zc2libHkgY2FuLuhcFe24ldWVns'+ + 'YWxzamRmbVjFaa05HVnGFqZHM3NXRBS73jxmhVMkjiwVVXV1d5UrXR1JLSkZFRr' + + 'WVd4emFtUm1iR0TFpUZvbiBoYXMgYmVlbxWkhNaF3uUi8kM0YkJTEVlZYVFjBYi' + + 'jFkWFIxSkxTa1pGUjd874hjklaTFpUwRVuIFNob3VsZCB5UwRkxUR1J6YVhlQWa' + + 'V1ZkNGVH32mDkdho3pqtRnRVbTFpUjBaeGUgYXNrZWQtZFoKjda40ZWlyYWl1eX' + + 'U4RkNtdmNub2l1dHE2TTA1jd84jkdJTbFJXYkZwWlZtRnKkWVrSRhhWbFpZVmFz' + + 'c2RkZmTFpUpGa1dGSXhTa3hUYTFwR1Vpkm9yIGluZm9ybWFNfdsWQdSiiYXNWVX' + + 'RSblJWYlRGcFVqQmFlRmRyYUU0MFpXbHlZV2wxZVhVNFJrTnR51YjJsMWRIRTJU' + + 'W91ciBpbmZvcm1hdGliBzdWJtaXR0ZWQb3UZSBhIHJlc3BvbnNlLCB3ZWxsIHJl' + + 'VEExWdHVybiB0am0aW9uIb24gYXMgd2UgcG9zc2libHkgY2FuLuhcFe24ldWVns' + 'dSaTFpU3hVUjFKNllWaFdhRmxZUWpCaQo34gcmVxdWlGFzIHNveqQl83snBfVl3', ## 2048bit SSL ON - ENABLED TRUE @@ -72,19 +72,24 @@ pubnub_high_security = Pubnub( ## ----------------------------------------------------------------------- ## Channel | Message Test Data (UTF-8) ## ----------------------------------------------------------------------- -crazy = ' ~`â¦â§!@#$%^&*(顶顅Ȓ)+=[]\\{}|;\':",./<>?abcd' -many_channels = [ str(x) + '-many_channel_test' for x in range(10) ] -runthroughs = 0 -planned_tests = 2 +crazy = ' ~`â¦â§!@#$%^&*(顶顅Ȓ)+=[]\\{}|;\':",./<>?abcd' +many_channels = [str(x) + '-many_channel_test' for x in range(10)] +runthroughs = 0 +planned_tests = 2 delivery_retries = 0 -max_retries = 10 +max_retries = 10 ## ----------------------------------------------------------------------- ## Unit Test Function ## ----------------------------------------------------------------------- -def test( trial, name ) : - if trial : print( 'PASS: ' + name ) - else : print( '- FAIL - ' + name ) + + +def test(trial, name): + if trial: + print('PASS: ' + name) + else: + print('- FAIL - ' + name) + def test_pubnub(pubnub): global runthroughs, planned_tests, delivery_retries, max_retries @@ -94,36 +99,38 @@ def test_pubnub(pubnub): ## ----------------------------------------------------------------------- def phase2(): status = { - 'sent' : 0, - 'received' : 0, - 'connections' : 0 + 'sent': 0, + 'received': 0, + 'connections': 0 } - def received( message, chan ): + def received(message, chan): global runthroughs - test( status['received'] <= status['sent'], 'many sends' ) + test(status['received'] <= status['sent'], 'many sends') status['received'] += 1 - pubnub.unsubscribe({ 'channel' : chan }) + pubnub.unsubscribe({'channel': chan}) if status['received'] == len(many_channels): runthroughs += 1 - if runthroughs == planned_tests: pubnub.stop() + if runthroughs == planned_tests: + pubnub.stop() - def publish_complete( info, chan ): + def publish_complete(info, chan): global delivery_retries, max_retries status['sent'] += 1 - test( info, 'publish complete' ) - test( info and len(info) > 2, 'publish response' ) + test(info, 'publish complete') + test(info and len(info) > 2, 'publish response') if not info[0]: delivery_retries += 1 - if max_retries > delivery_retries: sendit(chan) + if max_retries > delivery_retries: + sendit(chan) def sendit(chan): tchan = chan pubnub.publish({ - 'channel' : chan, - 'message' : "Hello World", - 'callback' : (lambda msg:publish_complete( msg, tchan )) + 'channel': chan, + 'message': "Hello World", + 'callback': (lambda msg: publish_complete(msg, tchan)) }) def connected(chan): @@ -131,88 +138,89 @@ def test_pubnub(pubnub): sendit(chan) def delivered(info): - if info and info[0]: status['sent'] += 1 + if info and info[0]: + status['sent'] += 1 def subscribe(chan): pubnub.subscribe({ - 'channel' : chan, - 'connect' : (lambda:connected(chan+'')), - 'callback' : (lambda msg:received( msg, chan )) + 'channel': chan, + 'connect': (lambda: connected(chan + '')), + 'callback': (lambda msg: received(msg, chan)) }) ## Subscribe All Channels - for chan in many_channels: subscribe(chan) - + for chan in many_channels: + subscribe(chan) + ## ----------------------------------------------------------------------- ## Time Example ## ----------------------------------------------------------------------- def time_complete(timetoken): - test( timetoken, 'timetoken fetch' ) - test( isinstance( timetoken, int ), 'timetoken int type' ) + test(timetoken, 'timetoken fetch') + test(isinstance(timetoken, int), 'timetoken int type') - pubnub.time({ 'callback' : time_complete }) + pubnub.time({'callback': time_complete}) ## ----------------------------------------------------------------------- ## Publish Example ## ----------------------------------------------------------------------- def publish_complete(info): - test( info, 'publish complete' ) - test( info and len(info) > 2, 'publish response' ) + test(info, 'publish complete') + test(info and len(info) > 2, 'publish response') - pubnub.history( { - 'channel' : crazy, - 'limit' : 10, - 'callback' : history_complete + pubnub.history({ + 'channel': crazy, + 'limit': 10, + 'callback': history_complete }) ## ----------------------------------------------------------------------- ## History Example ## ----------------------------------------------------------------------- def history_complete(messages): - test( messages and len(messages) > 0, 'history' ) - test( messages, 'history' ) - + test(messages and len(messages) > 0, 'history') + test(messages, 'history') pubnub.publish({ - 'channel' : crazy, - 'message' : "Hello World", - 'callback' : publish_complete + 'channel': crazy, + 'message': "Hello World", + 'callback': publish_complete }) ## ----------------------------------------------------------------------- ## Subscribe Example ## ----------------------------------------------------------------------- def message_received(message): - test( message, 'message received' ) - pubnub.unsubscribe({ 'channel' : crazy }) + test(message, 'message received') + pubnub.unsubscribe({'channel': crazy}) - def done() : - pubnub.unsubscribe({ 'channel' : crazy }) + def done(): + pubnub.unsubscribe({'channel': crazy}) pubnub.publish({ - 'channel' : crazy, - 'message' : "Hello World", - 'callback' : (lambda x:x) + 'channel': crazy, + 'message': "Hello World", + 'callback': (lambda x: x) }) - def dumpster(message) : - test( 0, 'never see this' ) + def dumpster(message): + test(0, 'never see this') pubnub.subscribe({ - 'channel' : crazy, - 'connect' : done, - 'callback' : dumpster + 'channel': crazy, + 'connect': done, + 'callback': dumpster }) - def connected() : + def connected(): pubnub.publish({ - 'channel' : crazy, - 'message' : { 'Info' : 'Connected!' } + 'channel': crazy, + 'message': {'Info': 'Connected!'} }) pubnub.subscribe({ - 'channel' : crazy, - 'connect' : connected, - 'callback' : message_received + 'channel': crazy, + 'connect': connected, + 'callback': message_received }) phase2() @@ -223,4 +231,3 @@ def test_pubnub(pubnub): test_pubnub(pubnub_user_supplied_options) test_pubnub(pubnub_high_security) pubnub_high_security.start() - diff --git a/python-twisted/tests/unit-tests.py b/python-twisted/tests/unit-tests.py index f143a3a..d0e5722 100644 --- a/python-twisted/tests/unit-tests.py +++ b/python-twisted/tests/unit-tests.py @@ -10,98 +10,102 @@ sys.path.append('.') from PubnubUnitTest import Suite from Pubnub import Pubnub -pubnub = Pubnub("demo","demo") +pubnub = Pubnub("demo", "demo") tests_count = 1 + 2 + 1 -test_suite = Suite(pubnub,tests_count) +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) + channel = "hello" + str(time.time()) + name = "Publish Test" - def fail(e): - test_suite.test(False, msg , e) + 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 - }) + 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 - }) + 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 - }) + 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() +for t in tests: + t() pubnub.start() |
