From e65cc45e333cc33d19b97b5f93e69121ca2beffa Mon Sep 17 00:00:00 2001 From: Devendra Date: Wed, 10 Jul 2013 10:39:58 +0530 Subject: adding makefiles for version updates --- Makefile | 19 ++++ Makefile.inc | 3 + VERSION | 2 +- common/Makefile | 16 +++ common/PubnubBase.py | 20 ++-- common/PubnubCoreAsync.py | 9 ++ python-tornado/Makefile | 17 ++++ python-tornado/Pubnub.py | 1 - python-tornado/tests/benchmark.py | 2 + python-tornado/tests/unit-test.py | 2 + python-twisted/Makefile | 18 ++++ python-twisted/Pubnub.py | 1 - python-twisted/tests/unit-test-full.py | 2 + python-twisted/tests/unit-test.py | 15 ++- python/Makefile | 19 ++++ python/Pubnub.py | 2 +- python/examples/detailed-history-unit-test.py | 134 ------------------------- python/tests/detailed-history-unit-test.py | 137 ++++++++++++++++++++++++++ python/tests/unit-test.py | 25 ++--- 19 files changed, 275 insertions(+), 169 deletions(-) create mode 100644 Makefile create mode 100644 Makefile.inc create mode 100644 common/Makefile create mode 100644 python-tornado/Makefile create mode 100644 python-twisted/Makefile create mode 100644 python/Makefile delete mode 100755 python/examples/detailed-history-unit-test.py create mode 100755 python/tests/detailed-history-unit-test.py diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..dbe0d95 --- /dev/null +++ b/Makefile @@ -0,0 +1,19 @@ +SUBDIRS = common python python-twisted python-tornado + +.PHONY: all +all: + for dir in $(SUBDIRS); do \ + $(MAKE) -C $$dir; \ + done + +.PHONY: clean +clean: + for dir in $(SUBDIRS); do \ + $(MAKE) clean -C $$dir; \ + done + +.PHONY: test +test: + for dir in $(SUBDIRS); do \ + $(MAKE) test -C $$dir; \ + done diff --git a/Makefile.inc b/Makefile.inc new file mode 100644 index 0000000..68a78c6 --- /dev/null +++ b/Makefile.inc @@ -0,0 +1,3 @@ +REPOS_DIR=.. +VERSION=$(shell cat $(REPOS_DIR)/VERSION) +ECHO=/bin/echo diff --git a/VERSION b/VERSION index 4772543..a0891f5 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -3.3.2 +3.3.4 diff --git a/common/Makefile b/common/Makefile new file mode 100644 index 0000000..1be6f8c --- /dev/null +++ b/common/Makefile @@ -0,0 +1,16 @@ +include ../Makefile.inc + + +.PHONY: all +all: build + +.PHONY: build +build: + find -name "Pubnub*py" | xargs sed -i "s/PubNub\ [0-9]\.[0-9]\.[0-9]/PubNub\ $(VERSION)/g" + + +.PHONY: clean +clean: + +.PHONY: test +test: diff --git a/common/PubnubBase.py b/common/PubnubBase.py index 0691a87..b5da9fa 100644 --- a/common/PubnubBase.py +++ b/common/PubnubBase.py @@ -319,22 +319,22 @@ class PubnubBase(object): ## Capture User Input channel = str(args['channel']) - params = [] + params = dict() count = 100 if args.has_key('count'): count = int(args['count']) - params.append('count' + '=' + str(count)) + params['count'] = str(count) if args.has_key('reverse'): - params.append('reverse' + '=' + str(args['reverse']).lower()) + params['reverse'] = str(args['reverse']).lower() if args.has_key('start'): - params.append('start' + '=' + str(args['start'])) + params['start'] = str(args['start']) if args.has_key('end'): - params.append('end' + '=' + str(args['end'])) + params['end'] = str(args['end']) ## Fail if bad input. if not channel : @@ -348,14 +348,14 @@ class PubnubBase(object): callback = None ## Get History - return self._request([ + return self._request({ 'urlcomponents' : [ 'v2', 'history', 'sub-key', self.subscribe_key, 'channel', channel, - ],params=params , callback=callback); + ],'urlparams' : params }, callback=callback); def time(self, args = None) : """ @@ -377,10 +377,10 @@ class PubnubBase(object): callback = args['callback'] else : callback = None - time = self._request([ + time = self._request({'urlcomponents' : [ 'time', '0' - ], callback) + ]}, callback) if time != None: return time[0] @@ -400,5 +400,5 @@ class PubnubBase(object): ch for ch in list(bit) ]) for bit in request["urlcomponents"]]) if (request.has_key("urlparams")): - url = url + '?' + "&".join([ x + "=" + y for x,y in request["urlparams"].items()]) + url = url + '?' + "&".join([ x + "=" + y for x,y in request["urlparams"].iteritems()]) return url diff --git a/common/PubnubCoreAsync.py b/common/PubnubCoreAsync.py index 9dcad4b..5b8d130 100644 --- a/common/PubnubCoreAsync.py +++ b/common/PubnubCoreAsync.py @@ -188,3 +188,12 @@ class PubnubCoreAsync(PubnubBase): ## BEGIN SUBSCRIPTION (LISTEN FOR MESSAGES) _subscribe() + def unsubscribe( self, args ): + channel = str(args['channel']) + if not (channel in self.subscriptions): + return False + + ## DISCONNECT + self.subscriptions[channel]['connected'] = 0 + self.subscriptions[channel]['timetoken'] = 0 + self.subscriptions[channel]['first'] = False diff --git a/python-tornado/Makefile b/python-tornado/Makefile new file mode 100644 index 0000000..2c33cf3 --- /dev/null +++ b/python-tornado/Makefile @@ -0,0 +1,17 @@ +include ../Makefile.inc + + +.PHONY: all +all: build + +.PHONY: build +build: + find -name "Pubnub*py" | xargs sed -i "s/PubNub\ [0-9]\.[0-9]\.[0-9]/PubNub\ $(VERSION)/g" + + +.PHONY: clean +clean: + +.PHONY: test +test: + diff --git a/python-tornado/Pubnub.py b/python-tornado/Pubnub.py index 0d78a86..55ca7ca 100644 --- a/python-tornado/Pubnub.py +++ b/python-tornado/Pubnub.py @@ -63,7 +63,6 @@ class Pubnub(PubnubCoreAsync): def _request( self, request, callback ) : url = self.getUrl(request) - print url ## Send Request Expecting JSON Response #print self.headers request = tornado.httpclient.HTTPRequest( url, 'GET', self.headers, connect_timeout=310, request_timeout=310 ) diff --git a/python-tornado/tests/benchmark.py b/python-tornado/tests/benchmark.py index 5f9b5e3..9d1840e 100644 --- a/python-tornado/tests/benchmark.py +++ b/python-tornado/tests/benchmark.py @@ -12,7 +12,9 @@ import sys import datetime import tornado +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-tornado/tests/unit-test.py b/python-tornado/tests/unit-test.py index f593d11..c5940af 100644 --- a/python-tornado/tests/unit-test.py +++ b/python-tornado/tests/unit-test.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/Makefile b/python-twisted/Makefile new file mode 100644 index 0000000..4cd9305 --- /dev/null +++ b/python-twisted/Makefile @@ -0,0 +1,18 @@ +include ../Makefile.inc + + +.PHONY: all +all: build + +.PHONY: build +build: + find -name "Pubnub*py" | xargs sed -i "s/PubNub\ [0-9]\.[0-9]\.[0-9]/PubNub\ $(VERSION)/g" + + +.PHONY: clean +clean: + +.PHONY: test +test: + python tests/unit-test.py + diff --git a/python-twisted/Pubnub.py b/python-twisted/Pubnub.py index 247c4ff..e317a9c 100644 --- a/python-twisted/Pubnub.py +++ b/python-twisted/Pubnub.py @@ -81,7 +81,6 @@ class Pubnub(PubnubCoreAsync): contextFactory = WebClientContextFactory(), pool = self.ssl and None or pnconn_pool )), [('gzip', GzipDecoder)]) - print url request = agent.request( 'GET', url, Headers(self.headers), None ) def received(response): 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 index 843f939..ed7fcd5 100644 --- a/python-twisted/tests/unit-test.py +++ b/python-twisted/tests/unit-test.py @@ -11,6 +11,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' @@ -23,7 +25,7 @@ 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' +crazy = 'python-twisted-test-channel' ## --------------------------------------------------------------------------- ## Unit Test Function @@ -90,10 +92,17 @@ def message_received(message): 'callback' : dumpster }) + def connected() : + ch = crazy + def dump_message( msg): + print ch, msg + pubnub.unsubscribe({'channel':ch}) + pubnub.stop() pubnub.publish({ - 'channel' : crazy, - 'message' : { 'Info' : 'Connected!' } + 'channel' : ch, + 'message' : { 'Info' : 'Connected!' }, + 'callback' : dump_message }) pubnub.subscribe({ diff --git a/python/Makefile b/python/Makefile new file mode 100644 index 0000000..9551bb7 --- /dev/null +++ b/python/Makefile @@ -0,0 +1,19 @@ +include ../Makefile.inc + + +.PHONY: all +all: build + +.PHONY: build +build: + find -name "Pubnub*py" | xargs sed -i "s/PubNub\ [0-9]\.[0-9]\.[0-9]/PubNub\ $(VERSION)/g" + + +.PHONY: clean +clean: + +.PHONY: test +test: + python tests/detailed-history-unit-test.py + python tests/unit-test.py + diff --git a/python/Pubnub.py b/python/Pubnub.py index 6143b0b..0a6d877 100644 --- a/python/Pubnub.py +++ b/python/Pubnub.py @@ -6,7 +6,7 @@ ## http://www.pubnub.com/ ## ----------------------------------- -## PubNub 3.3.2 Real-time Push Cloud API +## PubNub 3.3.4 Real-time Push Cloud API ## ----------------------------------- try: import json diff --git a/python/examples/detailed-history-unit-test.py b/python/examples/detailed-history-unit-test.py deleted file mode 100755 index 2169e52..0000000 --- a/python/examples/detailed-history-unit-test.py +++ /dev/null @@ -1,134 +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.0 Real-time Push Cloud API -## ----------------------------------- - -from Pubnub import Pubnub -import unittest2 as unittest -import sys - - -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 -ssl_on = len(sys.argv) > 4 and bool(sys.argv[4]) or False -pubnub = Pubnub(publish_key, subscribe_key, secret_key, ssl_on) -crazy = ' ~`!@#$%^&*(顶顅Ȓ)+=[]\\{}|;\':",./<>?abcd' - - -class TestDetailedHistory(unittest.TestCase): - total_msg = 10 - channel = pubnub.time() - starttime = None - inputs = [] - endtime = None - slice_a = 8 - slice_b = 2 - slice_size = slice_a - slice_b - - @classmethod - def publish_msg(cls, start, end, offset): - print 'Publishing messages' - inputs = [] - for i in range(start + offset, end + offset): - message = str(i) + " " + crazy - success = pubnub.publish({ - 'channel': cls.channel, - 'message': message, - }) - t = pubnub.time() - inputs.append({'timestamp': t, 'message': message}) - print 'Message # ', i, ' published' - return inputs - - @classmethod - def setUpClass(cls): - print 'Setting up context for Detailed History tests. Please wait ...' - cls.starttime = pubnub.time() - cls.inputs = cls.inputs + cls.publish_msg(0, cls.total_msg / 2, 0) - cls.midtime = pubnub.time() - cls.inputs = cls.inputs + cls.publish_msg( - 0, cls.total_msg / 2, cls.total_msg / 2) - cls.endtime = pubnub.time() - print 'Context setup for Detailed History tests. Now running tests' - - def test_begin_to_end_count(self): - count = 5 - history = pubnub.detailedHistory({ - 'channel': self.__class__.channel, - 'start': self.__class__.starttime, - 'end': self.__class__.endtime, - 'count': count - })[0] - self.assertTrue(len(history) == count and history[-1].encode( - 'utf-8') == self.__class__.inputs[count - 1]['message']) - - def test_end_to_begin_count(self): - count = 5 - history = pubnub.detailedHistory({ - 'channel': self.__class__.channel, - 'start': self.__class__.endtime, - 'end': self.__class__.starttime, - 'count': count - })[0] - self.assertTrue(len(history) == count and history[-1] - .encode('utf-8') == self.__class__.inputs[-1]['message']) - - def test_start_reverse_true(self): - history = pubnub.detailedHistory({ - 'channel': self.__class__.channel, - 'start': self.__class__.midtime, - 'reverse': True - })[0] - self.assertTrue(len(history) == self.__class__.total_msg / 2) - expected_msg = self.__class__.inputs[-1]['message'] - self.assertTrue(history[-1].encode('utf-8') == expected_msg) - - def test_start_reverse_false(self): - history = pubnub.detailedHistory({ - 'channel': self.__class__.channel, - 'start': self.__class__.midtime, - })[0] - self.assertTrue(history[0].encode('utf-8') - == self.__class__.inputs[0]['message']) - - def test_end_reverse_true(self): - history = pubnub.detailedHistory({ - 'channel': self.__class__.channel, - 'end': self.__class__.midtime, - 'reverse': True - })[0] - self.assertTrue(history[0].encode('utf-8') - == self.__class__.inputs[0]['message']) - - def test_end_reverse_false(self): - history = pubnub.detailedHistory({ - 'channel': self.__class__.channel, - 'end': self.__class__.midtime, - })[0] - self.assertTrue(len(history) == self.__class__.total_msg / 2) - self.assertTrue(history[-1].encode('utf-8') - == self.__class__.inputs[-1]['message']) - - def test_count(self): - history = pubnub.detailedHistory({ - 'channel': self.__class__.channel, - 'count': 5 - })[0] - self.assertTrue(len(history) == 5) - - def test_count_zero(self): - history = pubnub.detailedHistory({ - 'channel': self.__class__.channel, - 'count': 0 - })[0] - self.assertTrue(len(history) == 0) - -if __name__ == '__main__': - unittest.main() diff --git a/python/tests/detailed-history-unit-test.py b/python/tests/detailed-history-unit-test.py new file mode 100755 index 0000000..31bdef8 --- /dev/null +++ b/python/tests/detailed-history-unit-test.py @@ -0,0 +1,137 @@ +## 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.0 Real-time Push Cloud API +## ----------------------------------- + +import sys +sys.path.append('.') +sys.path.append('..') +sys.path.append('../common') +from Pubnub import Pubnub +import unittest2 as unittest + + +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 +ssl_on = len(sys.argv) > 4 and bool(sys.argv[4]) or False +pubnub = Pubnub(publish_key, subscribe_key, secret_key, ssl_on) +crazy = ' ~`!@#$%^&*(顶顅Ȓ)+=[]\\{}|;\':",./<>?abcd' + + +class TestDetailedHistory(unittest.TestCase): + total_msg = 10 + channel = pubnub.time() + starttime = None + inputs = [] + endtime = None + slice_a = 8 + slice_b = 2 + slice_size = slice_a - slice_b + + @classmethod + def publish_msg(cls, start, end, offset): + print 'Publishing messages' + inputs = [] + for i in range(start + offset, end + offset): + message = str(i) + " " + crazy + success = pubnub.publish({ + 'channel': cls.channel, + 'message': message, + }) + t = pubnub.time() + inputs.append({'timestamp': t, 'message': message}) + print 'Message # ', i, ' published' + return inputs + + @classmethod + def setUpClass(cls): + print 'Setting up context for Detailed History tests. Please wait ...' + cls.starttime = pubnub.time() + cls.inputs = cls.inputs + cls.publish_msg(0, cls.total_msg / 2, 0) + cls.midtime = pubnub.time() + cls.inputs = cls.inputs + cls.publish_msg( + 0, cls.total_msg / 2, cls.total_msg / 2) + cls.endtime = pubnub.time() + print 'Context setup for Detailed History tests. Now running tests' + + def test_begin_to_end_count(self): + count = 5 + history = pubnub.detailedHistory({ + 'channel': self.__class__.channel, + 'start': self.__class__.starttime, + 'end': self.__class__.endtime, + 'count': count + })[0] + self.assertTrue(len(history) == count and history[-1].encode( + 'utf-8') == self.__class__.inputs[count - 1]['message']) + + def test_end_to_begin_count(self): + count = 5 + history = pubnub.detailedHistory({ + 'channel': self.__class__.channel, + 'start': self.__class__.endtime, + 'end': self.__class__.starttime, + 'count': count + })[0] + self.assertTrue(len(history) == count and history[-1] + .encode('utf-8') == self.__class__.inputs[-1]['message']) + + def test_start_reverse_true(self): + history = pubnub.detailedHistory({ + 'channel': self.__class__.channel, + 'start': self.__class__.midtime, + 'reverse': True + })[0] + self.assertTrue(len(history) == self.__class__.total_msg / 2) + expected_msg = self.__class__.inputs[-1]['message'] + self.assertTrue(history[-1].encode('utf-8') == expected_msg) + + def test_start_reverse_false(self): + history = pubnub.detailedHistory({ + 'channel': self.__class__.channel, + 'start': self.__class__.midtime, + })[0] + self.assertTrue(history[0].encode('utf-8') + == self.__class__.inputs[0]['message']) + + def test_end_reverse_true(self): + history = pubnub.detailedHistory({ + 'channel': self.__class__.channel, + 'end': self.__class__.midtime, + 'reverse': True + })[0] + self.assertTrue(history[0].encode('utf-8') + == self.__class__.inputs[0]['message']) + + def test_end_reverse_false(self): + history = pubnub.detailedHistory({ + 'channel': self.__class__.channel, + 'end': self.__class__.midtime, + })[0] + self.assertTrue(len(history) == self.__class__.total_msg / 2) + self.assertTrue(history[-1].encode('utf-8') + == self.__class__.inputs[-1]['message']) + + def test_count(self): + history = pubnub.detailedHistory({ + 'channel': self.__class__.channel, + 'count': 5 + })[0] + self.assertTrue(len(history) == 5) + + def test_count_zero(self): + history = pubnub.detailedHistory({ + 'channel': self.__class__.channel, + 'count': 0 + })[0] + self.assertTrue(len(history) == 0) + +if __name__ == '__main__': + unittest.main() diff --git a/python/tests/unit-test.py b/python/tests/unit-test.py index 88391a0..1737ace 100755 --- a/python/tests/unit-test.py +++ b/python/tests/unit-test.py @@ -9,8 +9,11 @@ ## PubNub 3.0 Real-time Push Cloud API ## ----------------------------------- -from Pubnub import Pubnub 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' subscribe_key = len(sys.argv) > 2 and sys.argv[2] or 'demo' @@ -23,7 +26,7 @@ ssl_on = len(sys.argv) > 4 and bool(sys.argv[4]) or False ## ----------------------------------------------------------------------- pubnub = Pubnub( publish_key, subscribe_key, secret_key, ssl_on ) -crazy = ' ~`!@#$%^&*(顶顅Ȓ)+=[]\\{}|;\':",./<>?abcd' +crazy = 'demo' ## --------------------------------------------------------------------------- ## Unit Test Function @@ -37,11 +40,11 @@ def test( trial, name ) : ## ----------------------------------------------------------------------- ## Publish Example ## ----------------------------------------------------------------------- -pubish_success = pubnub.publish({ +publish_success = pubnub.publish({ 'channel' : crazy, 'message' : crazy }) -test( pubish_success[0] == 1, 'Publish First Message Success' ) +test( publish_success[0] == 1, 'Publish First Message Success' ) ## ----------------------------------------------------------------------- ## History Example @@ -61,17 +64,3 @@ test( len(history) == 1, 'History Message Count' ) ## ----------------------------------------------------------------------- timestamp = pubnub.time() test( timestamp > 0, 'PubNub Server Time: ' + str(timestamp) ) - -## ----------------------------------------------------------------------- -## Subscribe Example -## ----------------------------------------------------------------------- -def receive(message) : - print(message) - return True - -pubnub.subscribe({ - 'channel' : crazy, - 'callback' : receive -}) - - -- cgit v1.2.3