def test_serialize(self): d = self.get_a_cdr(datetime.now()) data = d.serialize() e = Cdr() e.deserialize(data) self.assertEqual(e.keys(), d.keys())
def test_nested(self): d = Cdr() e = Cdr() e.setString(1, "hello") e.setString(2, "world") d.appendArray(1, e) f = d.getArray(1) self.assertEqual(e.getString(1), f[0].getString(1)) self.assertEqual(e.getString(2), f[0].getString(2))
def test_cdrarray(self): d = Cdr() d[52] = "AAPL" e = Cdr() e[52] = "FB" f = Cdr() f[0] = [d, e] r = Cdr() r[1000] = f
def test_to_python_dict(self): d = Cdr() e = Cdr() f = Cdr() f[21] = 400 e[11] = 300 e[12] = [f] d[1] = 100 d[2] = 200 d[3] = [e] assert (d.toPythonDict()[3][0][12][0][21] == 400)
def get_get_ingoing_calls(): authorized_key = request.headers.get('IDENT-Integration-Key') # if authorized_key != app.config['IDENT_INTEGRATION_KEY']: # abort(404, description="Resource not found") limit = request.args.get('limit', 500) offset = request.args.get('offSet', 0) get_channels = GetChannelsFromRedis(host=app.config.get("REDIS_HOST"), port=app.config.get("REDIS_PORT"), db=app.config.get("REDIS_DB")) list_cdr = list() for tmp_cdr in get_channels.get_list_calls(): start_call_time = datetime.fromtimestamp( int(tmp_cdr.get('start_call_time'))) start_talk_time = 0 if tmp_cdr.get( 'start_talk_time', None) is None else int( tmp_cdr.get('start_talk_time', 0)) if start_talk_time == 0: wait_in_seconds = int(datetime.now().timestamp()) - int( tmp_cdr.get('start_call_time')) talk_in_seconds = 0 else: wait_in_seconds = start_talk_time - int( tmp_cdr.get('start_call_time')) talk_in_seconds = int(datetime.now().timestamp()) - start_talk_time list_cdr.append( Cdr(start_call_time, tmp_cdr.get('direction'), tmp_cdr.get('phone_from'), tmp_cdr.get('phone_to'), wait_in_seconds, talk_in_seconds, None, tmp_cdr.get('line_description')).__dict__) get_channels.close() response = jsonify(list_cdr) response.headers["Content-Type"] = "application/json; charset=utf-8" return response
def get_a_cdr(self, now): d = Cdr() e = Cdr() e[11] = 123 e[12] = "hi" f = Cdr() f[21] = 456 f[22] = "yo" d[1] = 123 d[2] = "Hello" d[3] = "World" d[4] = 1.25 d[5] = now d[6] = [e, f] return d
def get_a_cdr(self): d = Cdr() d.setInteger(field1, 123) d.setString(field2, "Hello") d.setString(field3, "World") return d
def test_from_python_dict(self): x = {1: "AAPL"} d = Cdr() d.fromDict(x) print(d.keys()) self.assertEqual(d.keys(), list(x.keys()))
# # Copyright 2014-2018 Neueda Ltd. # # An example showing the functionality within the python programming language. # Note the class has been renamed in order to be inline with Python standards. from cdr import Cdr d = Cdr() d.setInteger(1, 100) # set an integer value d.setString(2, "hello") # set a string value # retrieve an integer val = d.getInteger(1) print("get integer: {0} ({1})".format(val, type(val))) # retrieve an integer as string val = d.getString(1) print("get integer as string: {0} ({1})".format(val, type(val))) # retrieve a string val = d.getString(2) print("get string: {0}".format(val)) # try to retrieve an integer from a key with value that cannot be converted to # integer try: val = d.getInteger(2) except Exception as e: print('retrieve integer from a non-numeric string: {0}'.format(e)) # attempt to retrieve a value for a non-existant key
def test_str(self): d = Cdr() d.setInteger(field1, 123)
def test_to_string(self): d = Cdr() d.setInteger(field1, 123) self.assertEqual(d.toString(), "1=123")
# # Copyright 2014-2018 Neueda Ltd. # from cdr import Cdr import codec # LSE d = Cdr() d.setString(codec.MessageType, "A") d.setString(codec.UserName, "username") d.setString(codec.Password, "password") d.setString(codec.NewPassword, "password1") d.setInteger(codec.MessageVersion, 0) print(d.toString()) lseCodec = codec.lseCodec.get() logonMessageBuffer = lseCodec.encode(d) bytes = logonMessageBuffer.getByteArray() print(bytes) result = lseCodec.decodeBuffer(logonMessageBuffer) print(result.getCdr().toString())
def test_datetime(self): x = datetime.now() d = Cdr() d[52] = x self.assertEqual(d[52], x)