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 pyopenadr import OpenADRClient, OpenADRServer, enums
  14. from pyopenadr.utils import generate_id
  15. from pyopenadr.messaging import create_message, parse_message
  16. from datetime import datetime, timezone, timedelta
  17. from pyopenadr.signature import validate_message
  18. from pprint import pprint
  19. @pytest.mark.asyncio
  20. async def test_conformance_002():
  21. """
  22. The uid element is REQUIRED for each eiEventSignal interval. Within a sin-
  23. gle oadrDistributeEvent eiEventSignal, uid MUST be expressed as an inter-
  24. val number with a base of 0 and an increment of 1 for each subsequent in-
  25. terval.
  26. """
  27. event_id = generate_id()
  28. event = {'event_descriptor':
  29. {'event_id': event_id,
  30. 'modification_number': 0,
  31. 'modification_date': datetime.now(),
  32. 'priority': 0,
  33. 'market_context': 'MarketContext001',
  34. 'created_date_time': datetime.now(),
  35. 'event_status': enums.EVENT_STATUS.FAR,
  36. 'test_event': False,
  37. 'vtn_comment': 'No Comment'},
  38. 'active_period':
  39. {'dtstart': datetime.now(),
  40. 'duration': timedelta(minutes=30)},
  41. 'event_signals':
  42. [{'intervals': [{'duration': timedelta(minutes=10),
  43. 'signal_payload': 1},
  44. {'duration': timedelta(minutes=10),
  45. 'signal_payload': 2},
  46. {'duration': timedelta(minutes=10),
  47. 'signal_payload': 3}],
  48. 'signal_name': enums.SIGNAL_NAME.SIMPLE,
  49. 'signal_type': enums.SIGNAL_TYPE.DELTA,
  50. 'signal_id': generate_id()
  51. }]
  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