test_conformance_002.py 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. # SPDX-License-Identifier: Apache-2.0
  2. # Copyright 2020 Contributors to OpenLEADR
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. # http://www.apache.org/licenses/LICENSE-2.0
  7. # Unless required by applicable law or agreed to in writing, software
  8. # distributed under the License is distributed on an "AS IS" BASIS,
  9. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. # See the License for the specific language governing permissions and
  11. # limitations under the License.
  12. import pytest
  13. from openleadr import OpenADRClient, OpenADRServer, enums
  14. from openleadr.utils import generate_id
  15. from openleadr.messaging import create_message, parse_message
  16. from datetime import datetime, timezone, timedelta
  17. from pprint import pprint
  18. @pytest.mark.asyncio
  19. async def test_conformance_002():
  20. """
  21. The uid element is REQUIRED for each eiEventSignal interval. Within a sin-
  22. gle oadrDistributeEvent eiEventSignal, uid MUST be expressed as an inter-
  23. val number with a base of 0 and an increment of 1 for each subsequent in-
  24. terval.
  25. """
  26. event_id = generate_id()
  27. event = {'event_descriptor':
  28. {'event_id': event_id,
  29. 'modification_number': 0,
  30. 'modification_date': datetime.now(),
  31. 'priority': 0,
  32. 'market_context': 'MarketContext001',
  33. 'created_date_time': datetime.now(),
  34. 'event_status': enums.EVENT_STATUS.FAR,
  35. 'test_event': False,
  36. 'vtn_comment': 'No Comment'},
  37. 'active_period':
  38. {'dtstart': datetime.now(),
  39. 'duration': timedelta(minutes=30)},
  40. 'event_signals':
  41. [{'intervals': [{'duration': timedelta(minutes=10),
  42. 'signal_payload': 1},
  43. {'duration': timedelta(minutes=10),
  44. 'signal_payload': 2},
  45. {'duration': timedelta(minutes=10),
  46. 'signal_payload': 3}],
  47. 'signal_name': enums.SIGNAL_NAME.SIMPLE,
  48. 'signal_type': enums.SIGNAL_TYPE.DELTA,
  49. 'signal_id': generate_id()
  50. }],
  51. 'targets': [{'ven_id': '123'}]
  52. }
  53. # Create a message with this event
  54. msg = create_message('oadrDistributeEvent',
  55. response={'response_code': 200,
  56. 'response_description': 'OK',
  57. 'request_id': generate_id()},
  58. request_id=generate_id(),
  59. vtn_id=generate_id(),
  60. events=[event])
  61. # Parse the message
  62. parsed_type, parsed_msg = parse_message(msg)
  63. assert parsed_type == 'oadrDistributeEvent'
  64. intervals = parsed_msg['events'][0]['event_signals'][0]['intervals']
  65. # Verify that the interval uid's are numbered consecutively and starting at 0
  66. assert intervals[0]['uid'] == 0
  67. assert intervals[0]['signal_payload'] == 1
  68. assert intervals[1]['uid'] == 1
  69. assert intervals[1]['signal_payload'] == 2
  70. assert intervals[2]['uid'] == 2
  71. assert intervals[2]['signal_payload'] == 3