test_conformance_014.py 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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_014_warn():
  21. """
  22. If currentValue is included in the payload, it MUST be set to 0 (normal)
  23. when the event status is not “active” for the SIMPLE signalName.
  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() + timedelta(minutes=30),
  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. 'current_value': 123
  50. }]
  51. }
  52. # Create a message with this event
  53. with pytest.warns(UserWarning):
  54. msg = create_message('oadrDistributeEvent',
  55. response={'response_code': 200,
  56. 'response_description': 'OK',
  57. 'request_id': generate_id()},
  58. request_id=generate_id(),
  59. vtn_id=generate_id(),
  60. events=[event])