예제 #1
0
class PushTestCase(unittest.TestCase):
    """ General API tests """
    config = ConfigParser.ConfigParser()
    config.read('../config.ini')
    url = config.get('server', 'url')
    debug = str2bool(config.get('debug', 'trace'))
    verbose = str2bool(config.get('debug', 'verbose'))

    # data types
    uuid = [
        'f7067d44-5893-407c-8d4c-fc8f7ed97041',
        '1c57e340-df59-44648105-b91f1a39608b',
        '0cb8a613-8e2b-4b47-b370-51098daa8401',
        '14a84c48-2b8c-4669-8976--541368ccf4d3'
    ]
    big_uuid = uuid * 100

    chan_150 = str_gen(150)
    strings = [
        '', 'valid_uaid', ' fooey barrey ', '!@#$%^&*()-+', '0', '1', '-66000',
        uuid[0], 'True', 'False', 'true', 'false', '\"foo bar\"',
        str_gen(64000)
    ]
    data_types = [
        'messageType', 'HeLLO', '!@#$%^&*()-+', '0', '1', '-66000', '', 1, 0,
        -1, True, False, None, ' fooey barrey ',
        str_gen(64000),
        chr(0), '\x01\x00\x12\x59'
    ]

    def __init__(self, *args, **kwargs):
        unittest.TestCase.__init__(self, *args, **kwargs)

    def log(self, prefix, msg=""):
        if self.verbose:
            print_log(prefix, msg)

    def msg(self, ws, msg, cb='cb'):
        """ Util that sends and returns dict"""
        self.log("SEND:", msg)
        try:
            ws.send(json.dumps(msg))
        except Exception as e:
            print 'Unable to send data', e
            return None
        if cb:
            try:
                ret = ws.recv()
                if ret is None or len(ret) == 0:
                    return None
                return json.loads(ret)
            except Exception, e:
                print '#### Unable to parse json:', e
                raise AssertionError(e)
예제 #2
0
 def opened(self):
     super(WsClient, self).opened()
     self.sleep = get_rand(self.max_sleep, self.sleep)
     self.chan = get_uaid()
     self.uaid = get_uaid()
     self.version = int(str_gen(8))
     self.start_time = time.time()
     self.hello()
예제 #3
0
 def opened(self):
     super(WsClient, self).opened()
     self.sleep = get_rand(self.max_sleep, self.sleep)
     self.chan = get_uaid()
     self.uaid = get_uaid()
     self.version = int(str_gen(8))
     self.start_time = time.time()
     self.hello()
예제 #4
0
 def new_chan(self):
     self.chan = get_uaid()
     self.version = int(str_gen(8))
     self.hello()
예제 #5
0
 def new_chan(self):
     self.chan = get_uaid()
     self.version = int(str_gen(8))
     self.hello()