test_conformance_009.py 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. 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. }
  51. # Create a message with this event
  52. msg = create_message('oadrDistributeEvent',
  53. response={'response_code': 200,
  54. 'response_description': 'OK',
  55. 'request_id': generate_id()},
  56. request_id=generate_id(),
  57. vtn_id=generate_id(),
  58. events=[event])
  59. @pytest.mark.asyncio
  60. async def test_conformance_009_raise():
  61. """
  62. oadrDistributeEvent eiEventSignal’s with a signalName of “SIMPLE” MUST
  63. use signalPayload values of 0=normal; 1=moderate; 2=high; 3=special.
  64. """
  65. event_id = generate_id()
  66. event = {'event_descriptor':
  67. {'event_id': event_id,
  68. 'modification_number': 0,
  69. 'modification_date': datetime.now(),
  70. 'priority': 0,
  71. 'market_context': 'MarketContext001',
  72. 'created_date_time': datetime.now(),
  73. 'event_status': enums.EVENT_STATUS.FAR,
  74. 'test_event': False,
  75. 'vtn_comment': 'No Comment'},
  76. 'active_period':
  77. {'dtstart': datetime.now(),
  78. 'duration': timedelta(minutes=30)},
  79. 'event_signals':
  80. [{'intervals': [{'duration': timedelta(minutes=10),
  81. 'signal_payload': 10},
  82. {'duration': timedelta(minutes=10),
  83. 'signal_payload': 20},
  84. {'duration': timedelta(minutes=10),
  85. 'signal_payload': 30}],
  86. 'signal_name': enums.SIGNAL_NAME.SIMPLE,
  87. 'signal_type': enums.SIGNAL_TYPE.DELTA,
  88. 'signal_id': generate_id()
  89. }]
  90. }
  91. with pytest.raises(ValueError):
  92. msg = create_message('oadrDistributeEvent',
  93. response={'response_code': 200,
  94. 'response_description': 'OK',
  95. 'request_id': generate_id()},
  96. request_id=generate_id(),
  97. vtn_id=generate_id(),
  98. events=[event])