From f384d1ccc37271df37380cf6b95c35266eb9da8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Evren=20Esat=20=C3=96zkan?= Date: Thu, 21 Jul 2016 20:51:42 +0300 Subject: [PATCH] rref #5367 rref #5366 ref zetaops/zengine#66 ref zetaops/zengine#65 --- tests/async_amqp/messaging_tests.py | 28 +++++++++---------- zengine/lib/concurrent_amqp_test_client.py | 31 +++++++++++----------- zengine/messaging/views.py | 26 ++++++++++-------- 3 files changed, 44 insertions(+), 41 deletions(-) diff --git a/tests/async_amqp/messaging_tests.py b/tests/async_amqp/messaging_tests.py index 254b4ad4..21a65a42 100644 --- a/tests/async_amqp/messaging_tests.py +++ b/tests/async_amqp/messaging_tests.py @@ -16,20 +16,20 @@ def test_channel_list(self): def test_search_user(self): self.post('ulakbus', {"view": "_zops_search_user", "query": "x"}) - def test_show_channel(self): - self.post('ulakbus', - {"view": "_zops_show_channel", - 'channel_key': 'iG4mvjQrfkvTDvM6Jk56X5ILoJ_CoqwpemOHnknn3hYu1BlAghb3dm'}) - - def test_create_message(self): - self.post('ulakbus', - {"view": "_zops_create_message", - "message": dict( - body='test_body', title='testtitle', - channel='iG4mvjQrfkvTDvM6Jk56X5ILoJ_CoqwpemOHnknn3hYu1BlAghb3dm', - receiver='', - type=2 - )}) + # def test_show_channel(self): + # self.post('ulakbus', + # {"view": "_zops_show_channel", + # 'channel_key': 'iG4mvjQrfkvTDvM6Jk56X5ILoJ_CoqwpemOHnknn3hYu1BlAghb3dm'}) + # + # def test_create_message(self): + # self.post('ulakbus', + # {"view": "_zops_create_message", + # "message": dict( + # body='test_body', title='testtitle', + # channel='iG4mvjQrfkvTDvM6Jk56X5ILoJ_CoqwpemOHnknn3hYu1BlAghb3dm', + # receiver='', + # type=2 + # )}) def main(): diff --git a/zengine/lib/concurrent_amqp_test_client.py b/zengine/lib/concurrent_amqp_test_client.py index ffb7fdda..3f8d4bd0 100644 --- a/zengine/lib/concurrent_amqp_test_client.py +++ b/zengine/lib/concurrent_amqp_test_client.py @@ -17,7 +17,7 @@ import inspect import uuid -from pprint import pprint +from pprint import pprint, pformat import pika from tornado.escape import json_encode, json_decode @@ -93,13 +93,9 @@ def backend_to_client(self, body): from backend to client """ body = json_decode(body) - try: - self.message_callbacks[body['callbackID']](body) - except KeyError: - print("No cb for %s" % body['callbackID']) - print("CB HELL %s" % self.message_callbacks) - self.message_stack[body['callbackID']] = body - log.info("WRITE MESSAGE TO CLIENT:\n%s" % (body,)) + self.message_stack[body['callbackID']] = body + self.message_callbacks[body['callbackID']](body) + log.info("WRITE MESSAGE TO CLIENT:\n%s" % (pformat(body),)) def client_to_backend(self, message, callback, caller_fn_name): """ @@ -112,7 +108,6 @@ def cb(res): print("API Request: %s :: %s\n" % (caller_fn_name, 'PASS' if result else 'FAIL!')) # self.message_callbacks[cbid] = lambda res: callable(res, message) self.message_callbacks[cbid] = cb - print(caller_fn_name, self.message_callbacks) log.info("GOT MESSAGE FOR BACKEND %s: %s" % (self.sess_id, message)) self.queue_manager.redirect_incoming_message(self.sess_id, message, self.request) @@ -169,13 +164,17 @@ def stc(self, response, request=None): response: request: """ - if not response['code'] in (200, 201): - print("FAILED: Response not successful: \n") - if not self.process_error_reponse(response): - print("\nRESP:\n%s") - print("\nREQ:\n %s" % (response, request)) - else: - return True + try: + if not response['code'] in (200, 201): + print("FAILED: Response not successful: \n") + if not self.process_error_reponse(response): + print("\nRESP:\n%s") + print("\nREQ:\n %s" % (response, request)) + else: + return True + except Exception as e: + log.exception("\n===========>\nFAILED API REQUEST\n<===========\n%s\n" % e) + log.info("Response: \n%s\n\n" % response) def pstc(self, response, request=None): """ diff --git a/zengine/messaging/views.py b/zengine/messaging/views.py index cc3947ce..ce560425 100644 --- a/zengine/messaging/views.py +++ b/zengine/messaging/views.py @@ -117,7 +117,7 @@ def create_message(current): title=msg['title'], receiver=msg['receiver'] or None) current.output = { 'msg_key': msg_obj.key, - 'status': 'OK', + 'status': 'Created', 'code': 201 } if 'attachment' in msg: @@ -170,7 +170,9 @@ def show_channel(current, waited=False): 'avatar_url': sb.user.get_avatar_url() } for sb in ch.subscriber_set.objects.filter()], 'last_messages': [msg.serialize(current.user) - for msg in ch.get_last_messages()] + for msg in ch.get_last_messages()], + 'status': 'OK', + 'code': 200 } @@ -265,15 +267,17 @@ def list_channels(current): },] } """ - current.output['channels'] = [ - {'name': sbs.name, - 'key': sbs.channel.key, - 'type': sbs.channel.typ, - 'read_only': sbs.read_only, - 'is_online': sbs.is_online(), - 'actions': sbs.get_actions(), - 'unread': sbs.unread_count()} for sbs in - current.user.subscriptions.objects.filter(is_visible=True)] + current.output = { + 'status': 'OK', + 'code': 200, + 'channels': [{'name': sbs.name, + 'key': sbs.channel.key, + 'type': sbs.channel.typ, + 'read_only': sbs.read_only, + 'is_online': sbs.is_online(), + 'actions': sbs.get_actions(), + 'unread': sbs.unread_count()} for sbs in + current.user.subscriptions.objects.filter(is_visible=True)]} def create_channel(current):