Skip to content

Commit

Permalink
Merge pull request #165 from praekelt/feature/MOMZA-836-create-messag…
Browse files Browse the repository at this point in the history
…e-endpoints

Fix destination message events location
  • Loading branch information
erikh360 committed Jan 18, 2018
2 parents 3dd6c26 + 906b369 commit 3cfff00
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 24 deletions.
16 changes: 7 additions & 9 deletions junebug/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ def send_message(self, request, body, channel_id):
@inlineCallbacks
def get_message_status(self, request, channel_id, message_id):
'''Retrieve the status of a message'''
data = yield self.get_channel_message_events(
data = yield self.get_message_events(
request, channel_id, message_id)
returnValue(response(request, 'message status', data))

Expand Down Expand Up @@ -584,7 +584,7 @@ def send_destination_message(
router = yield Router.from_id(self, router_id)
router.get_destination(destination_id)
channel_id = yield router.router_worker.get_destination_channel(
destination_id, message_body=body)
destination_id, body)

msg = yield self.send_messsage_on_channel(channel_id, body)

Expand All @@ -600,19 +600,17 @@ def get_destination_message_status(

router = yield Router.from_id(self, router_id)
router.get_destination(destination_id)
channel_id = yield router.router_worker.get_destination_channel(
destination_id, message_id=message_id)

data = yield self.get_channel_message_events(
request, channel_id, message_id)
data = yield self.get_message_events(
request, destination_id, message_id)

returnValue(response(request, 'message status', data))

@inlineCallbacks
def get_channel_message_events(self, request, channel_id, message_id):
events = yield self.outbounds.load_all_events(channel_id, message_id)
def get_message_events(self, request, location_id, message_id):
events = yield self.outbounds.load_all_events(location_id, message_id)
events = sorted(
(api_from_event(channel_id, e) for e in events),
(api_from_event(location_id, e) for e in events),
key=lambda e: e['timestamp'])

last_event = events[-1] if events else None
Expand Down
9 changes: 4 additions & 5 deletions junebug/router/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,12 +356,11 @@ def teardown_router(self):
done here. May return a deferred.
"""

def get_destination_channel(
self, destination_id, message_body=None, message_id=None):
def get_destination_channel(self, destination_id, message_body):
"""
Gets the channel associated with the specified destination. Either
message_body or message_id will be supplied. Should be implemented by
router implementation.
Gets the channel associated with the specified destination. The
message_body will always be supplied. Should be implemented by router
implementation.
"""

def setup_connectors(self):
Expand Down
3 changes: 1 addition & 2 deletions junebug/router/from_address.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,7 @@ def setup_router(self):
self.consume_destination(
destination['id'], self.handle_outbound_message)

def get_destination_channel(
self, destination_id, message_body=None, message_id=None):
def get_destination_channel(self, destination_id, message_body):
config = self.get_static_config()
return succeed(str(config.channel))

Expand Down
3 changes: 1 addition & 2 deletions junebug/tests/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,7 @@ def teardown_router(self):
def test_log(self, message='Test log'):
self.log.msg(message, source=self)

def get_destination_channel(
self, destination_id, message_body=None, message_id=None):
def get_destination_channel(self, destination_id, message_body):
config = self.get_static_config()

for dest in config.destinations:
Expand Down
9 changes: 5 additions & 4 deletions junebug/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2118,11 +2118,11 @@ def test_get_destination_message_status_one_event(self):
event = TransportEvent(
user_message_id='message-id', sent_message_id='message-id',
event_type='nack', nack_reason='error error')
yield self.outbounds.store_event('channel-id', 'message-id', event)
yield self.outbounds.store_event(destination_id, 'message-id', event)
resp = yield self.get(
'/routers/{}/destinations/{}/messages/message-id'.format(
router_id, destination_id))
event_dict = api_from_event('channel-id', event)
event_dict = api_from_event(destination_id, event)
event_dict['timestamp'] = str(event_dict['timestamp'])
yield self.assert_response(
resp, http.OK, 'message status', {
Expand Down Expand Up @@ -2152,9 +2152,10 @@ def test_get_destination_message_status_multiple_events(self):
event = TransportEvent(
user_message_id='message-id', sent_message_id='message-id',
event_type='nack', nack_reason='error error')
yield self.outbounds.store_event('channel-id', 'message-id', event)
yield self.outbounds.store_event(
destination_id, 'message-id', event)
events.append(event)
event_dict = api_from_event('channel-id', event)
event_dict = api_from_event(destination_id, event)
event_dict['timestamp'] = str(event_dict['timestamp'])
event_dicts.append(event_dict)

Expand Down
6 changes: 4 additions & 2 deletions junebug/tests/test_from_address_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,12 @@ def test_get_destination_channel(self):
'channel': '41e58f4a-2acc-442f-b3e5-3cf2b2f1cf14',
})

channel_id = yield router.get_destination_channel("test-destination1")
channel_id = yield router.get_destination_channel(
"test-destination1", {})
self.assertEqual(channel_id, '41e58f4a-2acc-442f-b3e5-3cf2b2f1cf14')

channel_id = yield router.get_destination_channel("test-destination2")
channel_id = yield router.get_destination_channel(
"test-destination2", {})
self.assertEqual(channel_id, '41e58f4a-2acc-442f-b3e5-3cf2b2f1cf14')

@inlineCallbacks
Expand Down

0 comments on commit 3cfff00

Please sign in to comment.