Browse Source

Added conformance test 006, interpret all other values than 'false' for testEvent to be True

Stan Janssen 4 years ago
parent
commit
80c18934af
2 changed files with 58 additions and 0 deletions
  1. 4 0
      pyopenadr/utils.py
  2. 54 0
      test/conformance/test_conformance_006.py

+ 4 - 0
pyopenadr/utils.py

@@ -225,6 +225,10 @@ def normalize_dict(ordered_dict):
                 elif 'payload_int' in d[key]:
                 elif 'payload_int' in d[key]:
                     d[key] = int(d[key]['payload_int']['value'])
                     d[key] = int(d[key]['payload_int']['value'])
 
 
+        # All values other than 'false' must be interpreted as True for testEvent (rule 006)
+        elif key == 'test_event' and not isinstance(d[key], bool):
+            d[key] = True
+
         # Promote the 'text' item
         # Promote the 'text' item
         elif isinstance(d[key], dict) and "text" in d[key] and len(d[key]) == 1:
         elif isinstance(d[key], dict) and "text" in d[key] and len(d[key]) == 1:
             if key == 'uid':
             if key == 'uid':

+ 54 - 0
test/conformance/test_conformance_006.py

@@ -0,0 +1,54 @@
+import pytest
+
+from pyopenadr import OpenADRClient, OpenADRServer, enums
+from pyopenadr.utils import generate_id, create_message, parse_message
+from datetime import datetime, timezone, timedelta
+
+from pprint import pprint
+
+
+@pytest.mark.asyncio
+async def test_conformance_006():
+    """
+    The presence of any string except “false” in the oadrDistributeEvent
+    testEvent element MUST be treated as a trigger for a test event.
+    """
+    event_id = generate_id()
+    event = {'event_descriptor':
+                {'event_id': event_id,
+                 'modification_number': 0,
+                 'modification_date': datetime.now(),
+                 'priority': 0,
+                 'market_context': 'MarketContext001',
+                 'created_date_time': datetime.now(),
+                 'event_status': enums.EVENT_STATUS.FAR,
+                 'test_event': "HelloThere",
+                 'vtn_comment': 'No Comment'},
+            'active_period':
+                {'dtstart': datetime.now(),
+                 'duration': timedelta(minutes=5)},
+            'event_signals':
+                [{'intervals': [{'duration': timedelta(minutes=10),
+                                 'signal_payload': 100},
+                                {'duration': timedelta(minutes=10),
+                                 'signal_payload': 200},
+                                {'duration': timedelta(minutes=10),
+                                 'signal_payload': 300}],
+                  'signal_name': enums.SIGNAL_NAME.SIMPLE,
+                  'signal_type': enums.SIGNAL_TYPE.DELTA,
+                  'signal_id': generate_id()
+                }]
+        }
+
+    # Create a message with this event
+    msg = create_message('oadrDistributeEvent',
+                         response={'response_code': 200,
+                                   'response_description': 'OK',
+                                   'request_id': generate_id()},
+                         request_id=generate_id(),
+                         vtn_id=generate_id(),
+                         events=[event])
+
+    parsed_type, parsed_message = parse_message(msg)
+    assert parsed_type == 'oadrDistributeEvent'
+    assert parsed_message['events'][0]['event_descriptor']['test_event'] == True