<filename>test/TestRedis.py
import unittest
from datetime import datetime
import redis
import time

class Testredis(unittest.TestCase):

    redis_conn = None
    pubsub = None

    def setUp(self):
        self.redis_conn = redis.Redis()
        self.pubsub = self.redis_conn.pubsub()

    def item_decode(self, item):
        result = {}
        result['type'] = item['type']
        result['channel'] = item['channel'].decode('utf-8')
        if isinstance(item['data'], bytes):
            result['data'] = item['data'].decode('utf-8')
        else:
            result['data'] = item['data']
        return result

    def test_send_dummy_report_schedule(self):
        n = datetime.now()
        self.pubsub.subscribe(['colin'])
        done = False
        print('Hello :)')
        while not done:
            for i in self.pubsub.listen():
                item = self.item_decode(i)
                if item['type'] == 'message':
                    print('message>>> %s:%s' % (item['channel'], item['data']))
                    if item['data'] == 'bye':
                        print('Goodbye :(')
                        self.pubsub.unsubscribe()
                        done = True
            if not done:
                time.sleep(5)

if __name__ == '__main__':
    unittest.main()

<filename>test/TestRedis.py
import unittest
from datetime import datetime
import redis
import time

class Testredis(unittest.TestCase):

    redis_conn = None
    pubsub = None

    def setUp(self):
        self.redis_conn = redis.Redis()
        self.pubsub = self.redis_conn.pubsub()

    def item_decode(self, item):
        result = {}
        result['type'] = item['type']
        result['channel'] = item['channel'].decode('utf-8')
        if isinstance(item['data'], bytes):
            result['data'] = item['data'].decode('utf-8')
        else:
            result['data'] = item['data']
        return result

    def test_send_dummy_report_schedule(self):
        n = datetime.now()
        self.pubsub.subscribe(['colin'])
        done = False
        print('Hello :)')
        while not done:
            for i in self.pubsub.listen():
                item = self.item_decode(i)
                if item['type'] == 'message':
                    print('message>>> %s:%s' % (item['channel'], item['data']))
                    if item['data'] == 'bye':
                        print('Goodbye :(')
                        self.pubsub.unsubscribe()
                        done = True
            if not done:
                time.sleep(5)

if __name__ == '__main__':
    unittest.main()
