test_conformance_009.py 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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 openleadr import OpenADRClient, OpenADRServer, enums
  14. from openleadr.utils import generate_id
  15. from openleadr.messaging import create_message, parse_message
  16. from datetime import datetime, timezone, timedelta
  17. from pprint import pprint
  18. import warnings
  19. @pytest.mark.asyncio
  20. async def test_conformance_009_pass():
  21. """
  22. oadrDistributeEvent eiEventSignal’s with a signalName of “SIMPLE” MUST
  23. use signalPayload values of 0=normal; 1=moderate; 2=high; 3=special.
  24. """
  25. event_id = generate_id()
  26. event = {'event_descriptor':
  27. {'event_id': event_id,
  28. 'modification_number': 0,
  29. 'modification_date': datetime.now(),
  30. 'priority': 0,
  31. 'market_context': 'MarketContext001',
  32. 'created_date_time': datetime.now(),
  33. 'event_status': enums.EVENT_STATUS.FAR,
  34. 'test_event': False,
  35. 'vtn_comment': 'No Comment'},
  36. 'active_period':
  37. {'dtstart': datetime.now(),
  38. 'duration': timedelta(minutes=30)},
  39. 'event_signals':
  40. [{'intervals': [{'duration': timedelta(minutes=10),
  41. 'signal_payload': 1},
  42. {'duration': timedelta(minutes=10),
  43. 'signal_payload': 2},
  44. {'duration': timedelta(minutes=10),
  45. 'signal_payload': 3}],
  46. 'signal_name': enums.SIGNAL_NAME.SIMPLE,
  47. 'signal_type': enums.SIGNAL_TYPE.DELTA,
  48. 'signal_id': generate_id()
  49. }],
  50. 'targets': [{'ven_id': '123'}]
  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. @pytest.mark.asyncio
  61. async def test_conformance_009_raise():
  62. """
  63. oadrDistributeEvent eiEventSignal’s with a signalName of “SIMPLE” MUST
  64. use signalPayload values of 0=normal; 1=moderate; 2=high; 3=special.
  65. """
  66. event_id = generate_id()
  67. event = {'event_descriptor':
  68. {'event_id': event_id,
  69. 'modification_number': 0,
  70. 'modification_date': datetime.now(),
  71. 'priority': 0,
  72. 'market_context': 'MarketContext001',
  73. 'created_date_time': datetime.now(),
  74. 'event_status': enums.EVENT_STATUS.FAR,
  75. 'test_event': False,
  76. 'vtn_comment': 'No Comment'},
  77. 'active_period':
  78. {'dtstart': datetime.now(),
  79. 'duration': timedelta(minutes=30)},
  80. 'event_signals':
  81. [{'intervals': [{'duration': timedelta(minutes=10),
  82. 'signal_payload': 10},
  83. {'duration': timedelta(minutes=10),
  84. 'signal_payload': 20},
  85. {'duration': timedelta(minutes=10),
  86. 'signal_payload': 30}],
  87. 'signal_name': enums.SIGNAL_NAME.SIMPLE,
  88. 'signal_type': enums.SIGNAL_TYPE.DELTA,
  89. 'signal_id': generate_id()
  90. }]
  91. }
  92. with pytest.raises(ValueError):
  93. msg = create_message('oadrDistributeEvent',
  94. response={'response_code': 200,
  95. 'response_description': 'OK',
  96. 'request_id': generate_id()},
  97. request_id=generate_id(),
  98. vtn_id=generate_id(),
  99. events=[event])