Skip to content

Commit

Permalink
rref #5367
Browse files Browse the repository at this point in the history
rref #5366

ref #66
ref #65
  • Loading branch information
evrenesat committed Jul 21, 2016
1 parent 62faa27 commit f384d1c
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 41 deletions.
28 changes: 14 additions & 14 deletions tests/async_amqp/messaging_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
31 changes: 15 additions & 16 deletions zengine/lib/concurrent_amqp_test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
"""
Expand All @@ -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)

Expand Down Expand Up @@ -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):
"""
Expand Down
26 changes: 15 additions & 11 deletions zengine/messaging/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
}


Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit f384d1c

Please sign in to comment.