Browse Source

Added conformance test 009, add limitation to payload values for SIMPLE events

Stan Janssen 4 years ago
parent
commit
a2b01761a8

+ 8 - 0
pyopenadr/preflight.py

@@ -28,3 +28,11 @@ def preflight_oadrDistributeEvent(message_payload):
                               f" The active_period duration has been adjusted to ({signal_durations[0]}).")
                               f" The active_period duration has been adjusted to ({signal_durations[0]}).")
                 event['active_period']['duration'] = signal_durations[0]
                 event['active_period']['duration'] = signal_durations[0]
 
 
+    # Check that payload values with signal name SIMPLE are constricted (rule 9)
+    for event in message_payload['events']:
+        for event_signal in event['event_signals']:
+            if event_signal['signal_name'] == "SIMPLE":
+                for interval in event_signal['intervals']:
+                    if interval['signal_payload'] not in (0, 1, 2, 3):
+                        raise ValueError("Payload Values used with Signal Name SIMPLE must be one of"
+                                         "0, 1, 2 or 3")

+ 6 - 6
test/conformance/test_conformance_002.py

@@ -31,11 +31,11 @@ async def test_conformance_002():
                  'duration': timedelta(minutes=30)},
                  'duration': timedelta(minutes=30)},
             'event_signals':
             'event_signals':
                 [{'intervals': [{'duration': timedelta(minutes=10),
                 [{'intervals': [{'duration': timedelta(minutes=10),
-                                 'signal_payload': 100},
+                                 'signal_payload': 1},
                                 {'duration': timedelta(minutes=10),
                                 {'duration': timedelta(minutes=10),
-                                 'signal_payload': 200},
+                                 'signal_payload': 2},
                                 {'duration': timedelta(minutes=10),
                                 {'duration': timedelta(minutes=10),
-                                 'signal_payload': 300}],
+                                 'signal_payload': 3}],
                   'signal_name': enums.SIGNAL_NAME.SIMPLE,
                   'signal_name': enums.SIGNAL_NAME.SIMPLE,
                   'signal_type': enums.SIGNAL_TYPE.DELTA,
                   'signal_type': enums.SIGNAL_TYPE.DELTA,
                   'signal_id': generate_id()
                   'signal_id': generate_id()
@@ -58,8 +58,8 @@ async def test_conformance_002():
 
 
     # Verify that the interval uid's are numbered consecutively and starting at 0
     # Verify that the interval uid's are numbered consecutively and starting at 0
     assert intervals[0]['uid'] == 0
     assert intervals[0]['uid'] == 0
-    assert intervals[0]['signal_payload'] == 100
+    assert intervals[0]['signal_payload'] == 1
     assert intervals[1]['uid'] == 1
     assert intervals[1]['uid'] == 1
-    assert intervals[1]['signal_payload'] == 200
+    assert intervals[1]['signal_payload'] == 2
     assert intervals[2]['uid'] == 2
     assert intervals[2]['uid'] == 2
-    assert intervals[2]['signal_payload'] == 300
+    assert intervals[2]['signal_payload'] == 3

+ 3 - 3
test/conformance/test_conformance_006.py

@@ -29,11 +29,11 @@ async def test_conformance_006():
                  'duration': timedelta(minutes=30)},
                  'duration': timedelta(minutes=30)},
             'event_signals':
             'event_signals':
                 [{'intervals': [{'duration': timedelta(minutes=10),
                 [{'intervals': [{'duration': timedelta(minutes=10),
-                                 'signal_payload': 100},
+                                 'signal_payload': 1},
                                 {'duration': timedelta(minutes=10),
                                 {'duration': timedelta(minutes=10),
-                                 'signal_payload': 200},
+                                 'signal_payload': 2},
                                 {'duration': timedelta(minutes=10),
                                 {'duration': timedelta(minutes=10),
-                                 'signal_payload': 300}],
+                                 'signal_payload': 3}],
                   'signal_name': enums.SIGNAL_NAME.SIMPLE,
                   'signal_name': enums.SIGNAL_NAME.SIMPLE,
                   'signal_type': enums.SIGNAL_TYPE.DELTA,
                   'signal_type': enums.SIGNAL_TYPE.DELTA,
                   'signal_id': generate_id()
                   'signal_id': generate_id()

+ 9 - 9
test/conformance/test_conformance_008.py

@@ -30,11 +30,11 @@ async def test_conformance_008_autocorrect():
                  'duration': timedelta(minutes=5)},
                  'duration': timedelta(minutes=5)},
             'event_signals':
             'event_signals':
                 [{'intervals': [{'duration': timedelta(minutes=10),
                 [{'intervals': [{'duration': timedelta(minutes=10),
-                                 'signal_payload': 100},
+                                 'signal_payload': 1},
                                 {'duration': timedelta(minutes=10),
                                 {'duration': timedelta(minutes=10),
-                                 'signal_payload': 200},
+                                 'signal_payload': 2},
                                 {'duration': timedelta(minutes=10),
                                 {'duration': timedelta(minutes=10),
-                                 'signal_payload': 300}],
+                                 'signal_payload': 3}],
                   'signal_name': enums.SIGNAL_NAME.SIMPLE,
                   'signal_name': enums.SIGNAL_NAME.SIMPLE,
                   'signal_type': enums.SIGNAL_TYPE.DELTA,
                   'signal_type': enums.SIGNAL_TYPE.DELTA,
                   'signal_id': generate_id()
                   'signal_id': generate_id()
@@ -79,21 +79,21 @@ async def test_conformance_008_raise():
                  'duration': timedelta(minutes=5)},
                  'duration': timedelta(minutes=5)},
             'event_signals':
             'event_signals':
                 [{'intervals': [{'duration': timedelta(minutes=10),
                 [{'intervals': [{'duration': timedelta(minutes=10),
-                                 'signal_payload': 100},
+                                 'signal_payload': 1},
                                 {'duration': timedelta(minutes=10),
                                 {'duration': timedelta(minutes=10),
-                                 'signal_payload': 200},
+                                 'signal_payload': 2},
                                 {'duration': timedelta(minutes=10),
                                 {'duration': timedelta(minutes=10),
-                                 'signal_payload': 300}],
+                                 'signal_payload': 3}],
                   'signal_name': enums.SIGNAL_NAME.SIMPLE,
                   'signal_name': enums.SIGNAL_NAME.SIMPLE,
                   'signal_type': enums.SIGNAL_TYPE.DELTA,
                   'signal_type': enums.SIGNAL_TYPE.DELTA,
                   'signal_id': generate_id()
                   'signal_id': generate_id()
                 },
                 },
                 {'intervals': [{'duration': timedelta(minutes=1),
                 {'intervals': [{'duration': timedelta(minutes=1),
-                                 'signal_payload': 100},
+                                 'signal_payload': 1},
                                 {'duration': timedelta(minutes=2),
                                 {'duration': timedelta(minutes=2),
-                                 'signal_payload': 200},
+                                 'signal_payload': 2},
                                 {'duration': timedelta(minutes=2),
                                 {'duration': timedelta(minutes=2),
-                                 'signal_payload': 300}],
+                                 'signal_payload': 3}],
                   'signal_name': enums.SIGNAL_NAME.SIMPLE,
                   'signal_name': enums.SIGNAL_NAME.SIMPLE,
                   'signal_type': enums.SIGNAL_TYPE.DELTA,
                   'signal_type': enums.SIGNAL_TYPE.DELTA,
                   'signal_id': generate_id()
                   'signal_id': generate_id()

+ 93 - 0
test/conformance/test_conformance_009.py

@@ -0,0 +1,93 @@
+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
+import warnings
+
+
+@pytest.mark.asyncio
+async def test_conformance_009_pass():
+    """
+    oadrDistributeEvent eiEventSignal’s with a signalName of “SIMPLE” MUST
+use signalPayload values of 0=normal; 1=moderate; 2=high; 3=special.
+    """
+    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=30)},
+            'event_signals':
+                [{'intervals': [{'duration': timedelta(minutes=10),
+                                 'signal_payload': 1},
+                                {'duration': timedelta(minutes=10),
+                                 'signal_payload': 2},
+                                {'duration': timedelta(minutes=10),
+                                 'signal_payload': 3}],
+                  '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])
+
+@pytest.mark.asyncio
+async def test_conformance_009_raise():
+    """
+    oadrDistributeEvent eiEventSignal’s with a signalName of “SIMPLE” MUST
+use signalPayload values of 0=normal; 1=moderate; 2=high; 3=special.
+    """
+    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': False,
+                 'vtn_comment': 'No Comment'},
+            'active_period':
+                {'dtstart': datetime.now(),
+                 'duration': timedelta(minutes=30)},
+            'event_signals':
+                [{'intervals': [{'duration': timedelta(minutes=10),
+                                 'signal_payload': 10},
+                                {'duration': timedelta(minutes=10),
+                                 'signal_payload': 20},
+                                {'duration': timedelta(minutes=10),
+                                 'signal_payload': 30}],
+                  'signal_name': enums.SIGNAL_NAME.SIMPLE,
+                  'signal_type': enums.SIGNAL_TYPE.DELTA,
+                  'signal_id': generate_id()
+                }]
+        }
+
+    with pytest.raises(ValueError):
+        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])