test_conformance_009.py 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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 pprint import pprint
  7. import warnings
  8. @pytest.mark.asyncio
  9. async def test_conformance_009_pass():
  10. """
  11. oadrDistributeEvent eiEventSignal’s with a signalName of “SIMPLE” MUST
  12. use signalPayload values of 0=normal; 1=moderate; 2=high; 3=special.
  13. """
  14. event_id = generate_id()
  15. event = {'event_descriptor':
  16. {'event_id': event_id,
  17. 'modification_number': 0,
  18. 'modification_date': datetime.now(),
  19. 'priority': 0,
  20. 'market_context': 'MarketContext001',
  21. 'created_date_time': datetime.now(),
  22. 'event_status': enums.EVENT_STATUS.FAR,
  23. 'test_event': False,
  24. 'vtn_comment': 'No Comment'},
  25. 'active_period':
  26. {'dtstart': datetime.now(),
  27. 'duration': timedelta(minutes=30)},
  28. 'event_signals':
  29. [{'intervals': [{'duration': timedelta(minutes=10),
  30. 'signal_payload': 1},
  31. {'duration': timedelta(minutes=10),
  32. 'signal_payload': 2},
  33. {'duration': timedelta(minutes=10),
  34. 'signal_payload': 3}],
  35. 'signal_name': enums.SIGNAL_NAME.SIMPLE,
  36. 'signal_type': enums.SIGNAL_TYPE.DELTA,
  37. 'signal_id': generate_id()
  38. }]
  39. }
  40. # Create a message with this event
  41. msg = create_message('oadrDistributeEvent',
  42. response={'response_code': 200,
  43. 'response_description': 'OK',
  44. 'request_id': generate_id()},
  45. request_id=generate_id(),
  46. vtn_id=generate_id(),
  47. events=[event])
  48. @pytest.mark.asyncio
  49. async def test_conformance_009_raise():
  50. """
  51. oadrDistributeEvent eiEventSignal’s with a signalName of “SIMPLE” MUST
  52. use signalPayload values of 0=normal; 1=moderate; 2=high; 3=special.
  53. """
  54. event_id = generate_id()
  55. event = {'event_descriptor':
  56. {'event_id': event_id,
  57. 'modification_number': 0,
  58. 'modification_date': datetime.now(),
  59. 'priority': 0,
  60. 'market_context': 'MarketContext001',
  61. 'created_date_time': datetime.now(),
  62. 'event_status': enums.EVENT_STATUS.FAR,
  63. 'test_event': False,
  64. 'vtn_comment': 'No Comment'},
  65. 'active_period':
  66. {'dtstart': datetime.now(),
  67. 'duration': timedelta(minutes=30)},
  68. 'event_signals':
  69. [{'intervals': [{'duration': timedelta(minutes=10),
  70. 'signal_payload': 10},
  71. {'duration': timedelta(minutes=10),
  72. 'signal_payload': 20},
  73. {'duration': timedelta(minutes=10),
  74. 'signal_payload': 30}],
  75. 'signal_name': enums.SIGNAL_NAME.SIMPLE,
  76. 'signal_type': enums.SIGNAL_TYPE.DELTA,
  77. 'signal_id': generate_id()
  78. }]
  79. }
  80. with pytest.raises(ValueError):
  81. msg = create_message('oadrDistributeEvent',
  82. response={'response_code': 200,
  83. 'response_description': 'OK',
  84. 'request_id': generate_id()},
  85. request_id=generate_id(),
  86. vtn_id=generate_id(),
  87. events=[event])