Skip to content

Commit

Permalink
pre-e2e-refactor
Browse files Browse the repository at this point in the history
rref #5367
rref #5366

ref #66
ref #65
  • Loading branch information
evrenesat committed Jul 21, 2016
1 parent 6928e29 commit 4b9e238
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 14 deletions.
3 changes: 1 addition & 2 deletions tests/async_amqp/messaging_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ def test_channel_list(self):
self.post('ulakbus', {"view": "_zops_list_channels"})

def test_search_user(self):
self.post('ulakbus', {"view": "_zops_search_user",
"query": "x"})
self.post('ulakbus', {"view": "_zops_search_user", "query": "x"})

def test_show_channel(self):
self.post('ulakbus',
Expand Down
15 changes: 8 additions & 7 deletions zengine/lib/concurrent_amqp_test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
from zengine.views.auth import Login

sys.sessid_to_userid = {}
sys.test_method_names = {}
UserModel = get_object_from_path(settings.USER_MODEL)


Expand Down Expand Up @@ -97,6 +96,8 @@ def backend_to_client(self, 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,))

Expand All @@ -107,10 +108,11 @@ def client_to_backend(self, message, callback, caller_fn_name):
cbid = uuid.uuid4().hex
message = json_encode({"callbackID": cbid, "data": message})
def cb(res):
print("Testing: %s :: " % caller_fn_name, end='')
callback(res, message)
result = callback(res, message)
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 All @@ -128,7 +130,6 @@ def __init__(self, queue_manager):
self.queue_manager = queue_manager
self.clients = {}
self.make_client('ulakbus')
self.test_fn_name = ''
self.run_tests()

def make_client(self, username):
Expand All @@ -147,12 +148,12 @@ def post(self, username, data, callback=None):
if username not in self.clients:
self.make_client(username)
callback = callback or self.stc
self.clients[username].client_to_backend(data, callback, self.test_fn_name)
view_name = data['view'] if 'view' in data else sys._getframe(1).f_code.co_name
self.clients[username].client_to_backend(data, callback, view_name)

def run_tests(self):
for name in sorted(self.__class__.__dict__):
if name.startswith("test_"):
self.test_fn_name = name[5:]
getattr(self, name)()

def process_error_reponse(self, resp):
Expand All @@ -174,7 +175,7 @@ def stc(self, response, request=None):
print("\nRESP:\n%s")
print("\nREQ:\n %s" % (response, request))
else:
print("PASS!\n")
return True

def pstc(self, response, request=None):
"""
Expand Down
8 changes: 5 additions & 3 deletions zengine/messaging/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,9 @@ def bind_to_channel(self):
Binds (subscribes) users private exchange to channel exchange
Automatically called at creation of subscription record.
"""
channel = self._connect_mq()
channel.exchange_bind(source=self.channel.code_name, destination=self.user.prv_exchange)
if self.channel.code_name != self.user.prv_exchange:
channel = self._connect_mq()
channel.exchange_bind(source=self.channel.code_name, destination=self.user.prv_exchange)

def post_creation(self):
self.create_exchange()
Expand Down Expand Up @@ -303,13 +304,14 @@ def serialize(self, user=None):
return {
'content': self.body,
'type': self.typ,
'updated_at': self.updated_at.strftime(DATE_TIME_FORMAT) if self.updated_at else None,
'updated_at': self.updated_at,
'timestamp': self.timestamp.strftime(DATE_TIME_FORMAT),
'is_update': self.exist,
'attachments': [attachment.serialize() for attachment in self.attachment_set],
'title': self.msg_title,
'sender_name': self.sender.full_name,
'sender_key': self.sender.key,
'cmd': 'message',
'avatar_url': self.sender.avatar,
'key': self.key,
'actions': self.get_actions_for(user),
Expand Down
6 changes: 6 additions & 0 deletions zengine/messaging/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
'type': int,
'avatar_url': string,
'key': key,
'cmd': 'message',
'actions':[('action name', 'view name'),
('Add to Favorite', '_zops_add_to_favorites'), # applicable to everyone
Expand Down Expand Up @@ -112,6 +113,11 @@ def create_message(current):
msg = current.input['message']
msg_obj = Channel.add_message(msg['channel'], body=msg['body'], typ=msg['type'], sender=current.user,
title=msg['title'], receiver=msg['receiver'] or None)
current.output = {
'msg_key': msg_obj.key,
'status': 'OK',
'code': 201
}
if 'attachment' in msg:
for atch in msg['attachments']:
typ = current._dedect_file_type(atch['name'], atch['content'])
Expand Down
4 changes: 2 additions & 2 deletions zengine/tornado_server/ws_to_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,13 +268,13 @@ def on_message(self, channel, method, header, body):
if user_id in self.websockets:
log.info("write msg to client")
self.websockets[user_id].write_message(body)
channel.basic_ack(delivery_tag=method.delivery_tag)
# channel.basic_ack(delivery_tag=method.delivery_tag)
elif 'sessid_to_userid' in body:
reply = json_decode(body)
sys.sessid_to_userid[reply['sess_id']] = reply['user_id']
self.websockets[reply['user_id']] = self.websockets[reply['sess_id']]
del self.websockets[reply['sess_id']]
channel.basic_ack(delivery_tag=method.delivery_tag)
channel.basic_ack(delivery_tag=method.delivery_tag)

# else:
# channel.basic_reject(delivery_tag=method.delivery_tag)

0 comments on commit 4b9e238

Please sign in to comment.