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