test_conformance_001.py 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. @pytest.mark.asyncio
  18. async def test_conformance_001():
  19. dt = datetime(2020,1,1,12,0,0,tzinfo=timezone(offset=timedelta(hours=4)))
  20. msg = create_message('oadrCreateOpt', **{'opt_id': generate_id(),
  21. 'opt_type': enums.OPT.OPT_IN,
  22. 'opt_reason': enums.OPT_REASON.ECONOMIC,
  23. 'ven_id': generate_id(),
  24. 'created_date_time': dt,
  25. 'request_id': generate_id(),
  26. 'event_id': generate_id(),
  27. 'modification_number': 1,
  28. 'targets': []})
  29. parsed_type, parsed_msg = parse_message(msg)
  30. assert parsed_msg['created_date_time'].tzinfo == timezone.utc
  31. assert parsed_msg['created_date_time'] == dt.astimezone(timezone.utc)