def test_get_friends(self): uid_1 = "uid_user_1" uid_2 = "uid_user_2" usecret_1 = "usecret_1" usecret_2 = "usecret_2" # log in/ register user 1 resp, code = self.test_login(uid=uid_1, usecret=usecret_1, result=True) assert code == 200, resp # log in/ register user 2 resp, code = self.test_login(uid=uid_2, usecret=usecret_2, result=True) assert code == 200, resp # prepare auth token as headers resp_dict = json.loads(resp) headers = dict() headers['token'] = resp_dict['token'] # add user 2 as friend of user 1 resp, code = api.on_add_friend(headers=headers, friend_uid=uid_2) assert code == 200, str(code) + resp resp, code = api.on_get_friends(headers=headers) assert code == 200, str(code) + resp assert len(resp) > 5, resp print "test[test_get_friends] finished"
def test_add_friend(self): uid_1 = "uid_user_1" uid_2 = "uid_user_2" usecret_1 = "usecret_1" usecret_2 = "usecret_2" resp, code = self.test_login(uid=uid_1, usecret=usecret_1, result=True) assert code == 200, resp resp_dict = json.loads(resp) headers = dict() headers['token'] = resp_dict['token'] resp, code = api.on_add_friend(headers=headers, friend_uid=None) assert code == 400, str(code) + resp resp, code = api.on_add_friend(headers=headers, friend_uid="--") assert code == 400, str(code) + resp resp, code = self.test_login(uid=uid_2, usecret=usecret_2, result=True) assert code == 200, resp resp, code = api.on_add_friend(headers=headers, friend_uid=uid_2) assert code == 200, str(code) + resp print "test[test_add_friend] finished"
def test_add_user(self, uid="*****@*****.**", usecret="1234", result=False): uname = "user-" + uid params_invalid_0 = None params_invalid_1 = dict() params_invalid_1['uid'] = uid params_invalid_1['secret'] = usecret params_valid = dict(params_invalid_1) params_valid['name'] = uname invalid_response_0, inv_resp_code_0 = api.on_add_user(params=params_invalid_0) invalid_response_1, inv_resp_code_1 = api.on_add_user(params=params_invalid_1) valid_response, v_resp_code = api.on_add_user(params=params_valid) if result: if v_resp_code == 201: return elif v_resp_code == 400 and "already exists" in valid_response: return else: assert inv_resp_code_0 == 400, str(inv_resp_code_0) + invalid_response_0 assert inv_resp_code_1 == 400, str(inv_resp_code_1) + invalid_response_1 if not v_resp_code == 201 or v_resp_code == 400 and "already exists" in valid_response: pass else: assert v_resp_code == 201, str(v_resp_code) + valid_response print "test[test_add_user] finished"
def test_update(self): uid_1 = "uid_user_1" uid_2 = "uid_user_2" usecret_1 = "usecret_1" usecret_2 = "usecret_2" self.test_add_friend() resp, code = self.test_login(uid=uid_1, usecret=usecret_1, result=True) assert code == 200, resp resp_dict = json.loads(resp) headers = dict() headers['token'] = resp_dict['token'] success, dialog_id = Dialog.did_from_users_list([uid_1, uid_2]) assert success, dialog_id msg1 = Message(dialog_id=dialog_id, text="test text", from_id=uid_1, time_stamp=-1) msg2 = Message(dialog_id=dialog_id, text="text test", from_id=uid_2, time_stamp=-2) valid_params = msg1.to_dict() resp, code = api.on_new_msg(headers=headers, params=valid_params) assert code == 200, str(code) + resp resp, code = api.on_new_msg(headers=headers, params=valid_params) assert code == 200, str(code) + resp resp, code = api.on_update_request(headers=headers) assert code == 200, str(code) + resp print "test[test_update] finished"
def route_user_add_friend(friend_uid): if request.method == 'GET': # headers headers = request.headers return api.on_add_friend(headers=headers, friend_uid=friend_uid) elif request.method == 'DELETE': # headers headers = request.headers return api.on_remove_friend(headers=headers, friend_uid=friend_uid)
def get_currencies(): from core import API dic = {} for currency in API()._up(): iid = currency.get('id') symbol = currency.get('symbol') dic[symbol] = iid return dic
def route_update(): if request.method == 'GET': # headers headers = request.headers return api.on_update_request(headers=headers) elif request.method == 'POST': # headers headers = request.headers # params params = params_from_request(request) if params is None: response = json.dumps({'error': "unsupported content-type -> " + str(request.content_type)}) return response, 400 else: return api.on_new_msg(params=params, headers=headers)
def route_user_add(): # params params = params_from_request(request) if params is None: response = json.dumps({'error': "unsupported content-type -> " + str(request.content_type)}) return response, 400 else: return api.on_add_user(params=params)
def test_login(self, uid="*****@*****.**", usecret="1234", result=False): self.test_add_user(uid=uid, usecret=usecret, result=result) params_invalid_0 = None params_invalid_1 = dict() params_invalid_1['uid'] = uid params_valid = dict(params_invalid_1) params_valid['secret'] = usecret invalid_response_0, inv_resp_code_0 = api.login(params=params_invalid_0) invalid_response_1, inv_resp_code_1 = api.login(params=params_invalid_1) valid_response, v_resp_code = api.login(params=params_valid) assert inv_resp_code_0 == 400, str(inv_resp_code_0) + invalid_response_0 assert inv_resp_code_1 == 400, str(inv_resp_code_1) + invalid_response_1 assert v_resp_code == 200, str(v_resp_code) + valid_response if result: return valid_response, v_resp_code else: print "test[test_auth] finished"
def test_get_me(self): uid_1 = "uid_user_1" usecret_1 = "usecret_1" resp, code = self.test_login(uid=uid_1, usecret=usecret_1, result=True) assert code == 200, resp resp_dict = json.loads(resp) headers = dict() headers['token'] = resp_dict['token'] resp, code = api.on_get_me(headers=headers) assert code == 200, str(code) + resp print "test[test_get_me] finished"
def route_user_friends(): # headers headers = request.headers return api.on_get_friends(headers=headers)
def route_user_me(): # headers headers = request.headers return api.on_get_me(headers=headers)
def get(self): s = str(self.get_argument("symbol")) t = str(self.get_argument("time")) result = API.single(s,t) self.set_header("Content-Type", "application/json; charset=UTF-8") self.write(json.dumps(result))
def get(self): s = str(self.get_argument("symbol")) or "Tutti" result = API.latest(s) self.set_header("Content-Type", "application/json; charset=UTF-8") self.write(json.dumps(result))