diff --git a/manager/subscription/consumers.py b/manager/subscription/consumers.py index 3657f685..2e190088 100644 --- a/manager/subscription/consumers.py +++ b/manager/subscription/consumers.py @@ -169,7 +169,8 @@ async def handle_data_message(self, message): 'category': category, 'csc': csc, 'salindex': salindex, - 'data': {stream: data_csc[stream]} + 'data': {stream: data_csc[stream]}, + 'subscription': group_name } ) streams_data[stream] = data_csc[stream] @@ -180,7 +181,8 @@ async def handle_data_message(self, message): 'category': category, 'csc': csc, 'salindex': salindex, - 'data': {csc: streams_data} + 'data': {csc: streams_data}, + 'subscription': '-'.join([category, csc, str(salindex), 'all']) } ) @@ -254,6 +256,7 @@ async def subscription_data(self, message): category = message['category'] salindex = message['salindex'] csc = message['csc'] + subscription = message['subscription'] # Send data to WebSocket await self.send(text_data=json.dumps({ @@ -261,8 +264,9 @@ async def subscription_data(self, message): 'data': [{ 'csc': csc, 'salindex': salindex, - 'data': data, - }] + 'data': data + }], + 'subscription': subscription })) async def subscription_ack(self, message): @@ -292,7 +296,8 @@ async def subscription_ack(self, message): 'csc': csc, 'salindex': salindex, 'data': data, - }] + }], + 'subscription': 'cmd_acks-all-all-all' })) async def subscription_all_data(self, message): @@ -308,9 +313,11 @@ async def subscription_all_data(self, message): """ data = message['data'] category = message['category'] + # subscription = '{}-all-all-all'.format(category) # Send data to WebSocket await self.send(text_data=json.dumps({ 'category': category, - 'data': data + 'data': data, + 'subscription': '{}-all-all-all'.format(category) })) diff --git a/manager/subscription/tests/test_commands.py b/manager/subscription/tests/test_commands.py index 2b6d9b0d..cd742adb 100644 --- a/manager/subscription/tests/test_commands.py +++ b/manager/subscription/tests/test_commands.py @@ -52,7 +52,8 @@ def build_messages(self, category, csc, salindex, streams): 'csc': csc, 'salindex': salindex, 'data': {stream: {'value': 1.02813957817852497, 'dataType': 'Float'} for stream in streams} - }] + }], + 'subscription': '{}-{}-{}-{}'.format(category, csc, salindex, streams[0]) } return response, response @@ -149,7 +150,8 @@ async def test_authorized_user_gets_ack(self): "cmd_id": 12345 } } - }] + }], + "subscription": "cmd_acks-all-all-all" } ack = { "category": "ack", @@ -163,12 +165,16 @@ async def test_authorized_user_gets_ack(self): "cmd_id": 12345 } } - }] + }], + "subscription": "cmd_acks-all-all-all" } await communicator.send_json_to(msg_send) await communicator.receive_json_from() await communicator.send_json_to(msg_receive) # Assert response = await communicator.receive_json_from() + print(ack) + print('\n\n\n') + print(response) assert ack == response await communicator.disconnect() \ No newline at end of file diff --git a/manager/subscription/tests/test_subscriptions.py b/manager/subscription/tests/test_subscriptions.py index 61e4ad08..60fbafb1 100644 --- a/manager/subscription/tests/test_subscriptions.py +++ b/manager/subscription/tests/test_subscriptions.py @@ -65,7 +65,8 @@ def build_messages(self, category, csc, salindex, streams): 'csc': csc, 'salindex': salindex, 'data': {stream: {'value': 1.02813957817852497, 'dataType': 'Float'} for stream in streams} - }] + }], + 'subscription': '{}-{}-{}-{}'.format(category, csc, salindex, streams[0]) } return response, response @@ -194,8 +195,11 @@ async def test_receive_messages_from_all_subscription(self): self.build_messages(combination['category'], combination['csc'], combination['salindex'], [ combination['stream']]) await communicator.send_json_to(msg) + expected['subscription'] = '{}-all-all-all'.format(combination['category']) response = await communicator.receive_json_from() # Assert + print(response) + print(expected) assert response == expected await communicator.disconnect()