diff options
| author | Devendra | 2014-04-23 14:03:13 +0530 | 
|---|---|---|
| committer | Devendra | 2014-04-23 14:03:13 +0530 | 
| commit | 09cd0c015ae276aa849297a6a976065b2b3f247b (patch) | |
| tree | f1b253aa856e3a16e36eea9213857a33f6c35df4 /python-twisted/tests/unit-test-full.py | |
| parent | fdb46e56fa6794940f9fbe51a2863d58e927e655 (diff) | |
| download | pubnub-python-09cd0c015ae276aa849297a6a976065b2b3f247b.tar.bz2 | |
modifying code for pep 8 compliance
Diffstat (limited to 'python-twisted/tests/unit-test-full.py')
| -rw-r--r-- | python-twisted/tests/unit-test-full.py | 177 | 
1 files changed, 92 insertions, 85 deletions
| 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() - | 
