test_conformance_002.py 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import pytest
  2. from pyopenadr import OpenADRClient, OpenADRServer, enums
  3. from pyopenadr.utils import generate_id
  4. from pyopenadr.messaging import create_message, parse_message
  5. from datetime import datetime, timezone, timedelta
  6. from pyopenadr.signature import validate_message
  7. from pprint import pprint
  8. @pytest.mark.asyncio
  9. async def test_conformance_002():
  10. """
  11. The uid element is REQUIRED for each eiEventSignal interval. Within a sin-
  12. gle oadrDistributeEvent eiEventSignal, uid MUST be expressed as an inter-
  13. val number with a base of 0 and an increment of 1 for each subsequent in-
  14. terval.
  15. """
  16. event_id = generate_id()
  17. event = {'event_descriptor':
  18. {'event_id': event_id,
  19. 'modification_number': 0,
  20. 'modification_date': datetime.now(),
  21. 'priority': 0,
  22. 'market_context': 'MarketContext001',
  23. 'created_date_time': datetime.now(),
  24. 'event_status': enums.EVENT_STATUS.FAR,
  25. 'test_event': False,
  26. 'vtn_comment': 'No Comment'},
  27. 'active_period':
  28. {'dtstart': datetime.now(),
  29. 'duration': timedelta(minutes=30)},
  30. 'event_signals':
  31. [{'intervals': [{'duration': timedelta(minutes=10),
  32. 'signal_payload': 1},
  33. {'duration': timedelta(minutes=10),
  34. 'signal_payload': 2},
  35. {'duration': timedelta(minutes=10),
  36. 'signal_payload': 3}],
  37. 'signal_name': enums.SIGNAL_NAME.SIMPLE,
  38. 'signal_type': enums.SIGNAL_TYPE.DELTA,
  39. 'signal_id': generate_id()
  40. }]
  41. }
  42. # Create a message with this event
  43. msg = create_message('oadrDistributeEvent',
  44. response={'response_code': 200,
  45. 'response_description': 'OK',
  46. 'request_id': generate_id()},
  47. request_id=generate_id(),
  48. vtn_id=generate_id(),
  49. events=[event])
  50. validate_message(msg)
  51. # Parse the message
  52. parsed_type, parsed_msg = parse_message(msg)
  53. assert parsed_type == 'oadrDistributeEvent'
  54. intervals = parsed_msg['events'][0]['event_signals'][0]['intervals']
  55. # Verify that the interval uid's are numbered consecutively and starting at 0
  56. assert intervals[0]['uid'] == 0
  57. assert intervals[0]['signal_payload'] == 1
  58. assert intervals[1]['uid'] == 1
  59. assert intervals[1]['signal_payload'] == 2
  60. assert intervals[2]['uid'] == 2
  61. assert intervals[2]['signal_payload'] == 3