test_conformance_021.py 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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 pyopenadr.objects import Event, EventDescriptor, ActivePeriod, EventSignal, Interval
  17. from datetime import datetime, timezone, timedelta
  18. from pprint import pprint
  19. import warnings
  20. from test.fixtures.simple_server import start_server, add_event
  21. @pytest.mark.asyncio
  22. async def test_conformance_021(start_server):
  23. """
  24. If venID, vtnID, or eventID value is included in the payload, the receiving
  25. entity MUST validate that the ID value is as expected and generate an error
  26. if an unexpected value is received.
  27. Exception: A VEN MUST NOT generate an error upon receipt of a canceled
  28. event whose eventID is not previously known.
  29. """
  30. client = OpenADRClient(ven_name="TestVEN",
  31. vtn_url="http://localhost:8001/OpenADR2/Simple/2.0b")
  32. await client.create_party_registration()
  33. event = {'event_descriptor':
  34. {'event_id': generate_id(),
  35. 'modification_number': 0,
  36. 'modification_date': datetime.now(),
  37. 'priority': 0,
  38. 'market_context': 'MarketContext001',
  39. 'created_date_time': datetime.now(),
  40. 'event_status': enums.EVENT_STATUS.FAR,
  41. 'test_event': False,
  42. 'vtn_comment': 'No Comment'},
  43. 'active_period':
  44. {'dtstart': datetime.now() + timedelta(minutes=30),
  45. 'duration': timedelta(minutes=30)},
  46. 'event_signals':
  47. [{'intervals': [{'duration': timedelta(minutes=10),
  48. 'signal_payload': 1},
  49. {'duration': timedelta(minutes=10),
  50. 'signal_payload': 2},
  51. {'duration': timedelta(minutes=10),
  52. 'signal_payload': 3}],
  53. 'signal_name': enums.SIGNAL_NAME.SIMPLE,
  54. 'signal_type': enums.SIGNAL_TYPE.DELTA,
  55. 'signal_id': generate_id(),
  56. 'current_value': 123
  57. }]
  58. }
  59. add_event(ven_id=client.ven_id,
  60. event_id = event['event_descriptor']['event_id'],
  61. event=event)
  62. message_type, message_payload = await client.poll()
  63. assert message_type == 'oadrDistributeEvent'