## --------------------------------------------------------------------------- ## Unit Test Function ## --------------------------------------------------------------------------- def test( trial, name ) : if trial : print( 'PASS: '******'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 test(trial, name): if trial: print('PASS: '******'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 ## -----------------------------------------------------------------------
else : print( 'FAIL: ' + name ) ## ----------------------------------------------------------------------- ## Publish Example ## ----------------------------------------------------------------------- publish_success = pubnub.publish({ 'channel' : crazy, 'message' : crazy }) test( publish_success[0] == 1, 'Publish First Message Success' ) ## ----------------------------------------------------------------------- ## History Example ## ----------------------------------------------------------------------- history = pubnub.history({ 'channel' : crazy, 'limit' : 1 }) test( history[0].encode('utf-8') == crazy, 'History Message: ' + history[0] ) test( len(history) == 1, 'History Message Count' ) ## ----------------------------------------------------------------------- ## PubNub Server Time Example ## ----------------------------------------------------------------------- timestamp = pubnub.time() test( timestamp > 0, 'PubNub Server Time: ' + str(timestamp) )
## --------------------------------------------------------------------------- def test(trial, name): if trial: print("PASS: "******"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)