From d8d69b887d0dde622388acae83a3510d08a8eefc Mon Sep 17 00:00:00 2001 From: Nan Jiang Date: Mon, 28 May 2018 13:51:07 -0400 Subject: [PATCH] Extract action field from ping-centre ping --- onyx/api/v3.py | 3 ++- tests/api/test_v3.py | 7 ++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/onyx/api/v3.py b/onyx/api/v3.py index 29294a3..ab56ed2 100644 --- a/onyx/api/v3.py +++ b/onyx/api/v3.py @@ -172,6 +172,7 @@ def handle_ping_centre_ping(ping_type, log_name): client_payload_raw = request.get_data(cache=False) client_payload = ujson.decode(client_payload_raw) assert 'topic' in client_payload # treat it as malformed payload if "topic" is missing + action = client_payload.get("action", "ping_centre") ip_addr = request.headers.get('X-Forwarded-For') if ip_addr is None: @@ -191,7 +192,7 @@ def handle_ping_centre_ping(ping_type, log_name): return Response('', content_type='application/json; charset=utf-8', status=400) - env.log_dict(name=log_name, action="ping_centre", message=client_payload) + env.log_dict(name=log_name, action=action, message=client_payload) env.statsd.incr("{0}".format(ping_type)) return Response('', content_type='application/json; charset=utf-8', diff --git a/tests/api/test_v3.py b/tests/api/test_v3.py index 3c362d8..77ed1fe 100644 --- a/tests/api/test_v3.py +++ b/tests/api/test_v3.py @@ -293,9 +293,14 @@ class TestPingCentrePing(BaseTestCase): assert_equals(response.content_length, 0) def test_payload_meta(self): + payload = { + "data": "test", + "action": "ping_centre_action", + "topic": "activity_stream_mobile_session" + } response = self.client.post(url_for('v3_links.ping_centre'), content_type='application/json', headers=[("User-Agent", "TestClient")], - data=json.dumps({"data": "test", "topic": "activity_stream_mobile_session"})) + data=json.dumps(payload)) assert_equals(response.status_code, 200) assert_equals(response.content_length, 0)