test_conformance_002.py 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 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. }
  52. # Create a message with this event
  53. msg = create_message('oadrDistributeEvent',
  54. response={'response_code': 200,
  55. 'response_description': 'OK',
  56. 'request_id': generate_id()},
  57. request_id=generate_id(),
  58. vtn_id=generate_id(),
  59. events=[event])
  60. # Parse the message
  61. parsed_type, parsed_msg = parse_message(msg)
  62. assert parsed_type == 'oadrDistributeEvent'
  63. intervals = parsed_msg['events'][0]['event_signals'][0]['intervals']
  64. # Verify that the interval uid's are numbered consecutively and starting at 0
  65. assert intervals[0]['uid'] == 0
  66. assert intervals[0]['signal_payload'] == 1
  67. assert intervals[1]['uid'] == 1
  68. assert intervals[1]['signal_payload'] == 2
  69. assert intervals[2]['uid'] == 2
  70. assert intervals[2]['signal_payload'] == 3