Sfoglia il codice sorgente

Added conformance test 001, force datetimes to be UTC

Stan Janssen 4 anni fa
parent
commit
d6f73049e6
2 ha cambiato i file con 25 aggiunte e 1 eliminazioni
  1. 1 1
      pyopenadr/utils.py
  2. 24 0
      test/conformance/test_conformance_001.py

+ 1 - 1
pyopenadr/utils.py

@@ -274,7 +274,7 @@ def peek(iterable):
 def datetimeformat(value, format=DATETIME_FORMAT):
     if not isinstance(value, datetime):
         return value
-    return value.strftime(format)
+    return value.astimezone(timezone.utc).strftime(format)
 
 def timedeltaformat(value):
     """

+ 24 - 0
test/conformance/test_conformance_001.py

@@ -0,0 +1,24 @@
+import pytest
+
+from pyopenadr import OpenADRClient, OpenADRServer, enums
+from pyopenadr.utils import generate_id, create_message, parse_message
+from datetime import datetime, timezone, timedelta
+
+
+
+@pytest.mark.asyncio
+async def test_conformance_001():
+    dt = datetime(2020,1,1,12,0,0,tzinfo=timezone(offset=timedelta(hours=4)))
+    msg = create_message('oadrCreateOpt', **{'opt_id': generate_id(),
+                                             'opt_type': enums.OPT.OPT_IN,
+                                             'opt_reason': enums.OPT_REASON.ECONOMIC,
+                                             'ven_id': generate_id(),
+                                             'created_date_time': dt,
+                                             'request_id': generate_id(),
+                                             'event_id': generate_id(),
+                                             'modification_number': 1,
+                                             'targets': []})
+    parsed_type, parsed_msg = parse_message(msg)
+    assert parsed_msg['created_date_time'].tzinfo == timezone.utc
+    assert parsed_msg['created_date_time'] == dt.astimezone(timezone.utc)
+