From 80edcffbfe140a6d19c65deca24e1ba1c0f49b99 Mon Sep 17 00:00:00 2001 From: Devendra Date: Mon, 24 Mar 2014 19:17:48 +0530 Subject: support for python3 --- python/tests/detailed-history-unit-test.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'python/tests/detailed-history-unit-test.py') diff --git a/python/tests/detailed-history-unit-test.py b/python/tests/detailed-history-unit-test.py index 31bdef8..b1500b4 100755 --- a/python/tests/detailed-history-unit-test.py +++ b/python/tests/detailed-history-unit-test.py @@ -14,7 +14,7 @@ sys.path.append('.') sys.path.append('..') sys.path.append('../common') from Pubnub import Pubnub -import unittest2 as unittest +import unittest as unittest publish_key = len(sys.argv) > 1 and sys.argv[1] or 'demo' @@ -37,7 +37,7 @@ class TestDetailedHistory(unittest.TestCase): @classmethod def publish_msg(cls, start, end, offset): - print 'Publishing messages' + print('Publishing messages') inputs = [] for i in range(start + offset, end + offset): message = str(i) + " " + crazy @@ -47,19 +47,19 @@ class TestDetailedHistory(unittest.TestCase): }) t = pubnub.time() inputs.append({'timestamp': t, 'message': message}) - print 'Message # ', i, ' published' + 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 setUpClass(c): + print('Setting up context for Detailed History tests. Please wait ...') + c.starttime = pubnub.time() + c.inputs = c.inputs + c.publish_msg(0, c.total_msg / 2, 0) + c.midtime = pubnub.time() + c.inputs = c.inputs + c.publish_msg( + 0, c.total_msg / 2, c.total_msg / 2) + c.endtime = pubnub.time() + print('Context setup for Detailed History tests. Now running tests') def test_begin_to_end_count(self): count = 5 -- cgit v1.2.3 From 93379625e26c98a8cfab72c106ae40819843f956 Mon Sep 17 00:00:00 2001 From: Devendra Date: Thu, 24 Apr 2014 00:35:10 +0530 Subject: remove relative imports --- python/tests/detailed-history-unit-test.py | 3 --- 1 file changed, 3 deletions(-) (limited to 'python/tests/detailed-history-unit-test.py') diff --git a/python/tests/detailed-history-unit-test.py b/python/tests/detailed-history-unit-test.py index b1500b4..9663de9 100755 --- a/python/tests/detailed-history-unit-test.py +++ b/python/tests/detailed-history-unit-test.py @@ -10,9 +10,6 @@ ## ----------------------------------- import sys -sys.path.append('.') -sys.path.append('..') -sys.path.append('../common') from Pubnub import Pubnub import unittest as unittest -- cgit v1.2.3 From c98286f500b77dcf426367df0b688f536b77ea9b Mon Sep 17 00:00:00 2001 From: Devendra Date: Thu, 24 Apr 2014 01:33:45 +0530 Subject: fixing imports --- python/tests/detailed-history-unit-test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'python/tests/detailed-history-unit-test.py') diff --git a/python/tests/detailed-history-unit-test.py b/python/tests/detailed-history-unit-test.py index 9663de9..fd2c81a 100755 --- a/python/tests/detailed-history-unit-test.py +++ b/python/tests/detailed-history-unit-test.py @@ -10,7 +10,7 @@ ## ----------------------------------- import sys -from Pubnub import Pubnub +from Pubnub import PubnubAsync as Pubnub import unittest as unittest -- cgit v1.2.3 From 32492b68b66a46bdbf6736e1ddd16a34dca12b9b Mon Sep 17 00:00:00 2001 From: Devendra Date: Thu, 15 May 2014 19:48:06 +0530 Subject: adding more unit tests --- python/tests/detailed-history-unit-test.py | 134 ----------------------------- 1 file changed, 134 deletions(-) delete mode 100755 python/tests/detailed-history-unit-test.py (limited to 'python/tests/detailed-history-unit-test.py') diff --git a/python/tests/detailed-history-unit-test.py b/python/tests/detailed-history-unit-test.py deleted file mode 100755 index fd2c81a..0000000 --- a/python/tests/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 -## ----------------------------------- - -import sys -from Pubnub import PubnubAsync as Pubnub -import unittest 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(c): - print('Setting up context for Detailed History tests. Please wait ...') - c.starttime = pubnub.time() - c.inputs = c.inputs + c.publish_msg(0, c.total_msg / 2, 0) - c.midtime = pubnub.time() - c.inputs = c.inputs + c.publish_msg( - 0, c.total_msg / 2, c.total_msg / 2) - c.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() -- cgit v1.2.3