|
@@ -23,6 +23,24 @@ from datetime import datetime, timezone, timedelta
|
|
|
|
|
|
DATE_FORMAT = "%Y-%m-%dT%H:%M:%S.%fZ"
|
|
|
|
|
|
+def test_messages():
|
|
|
+ for message_type, data in testcases:
|
|
|
+ _test_message(message_type, **data)
|
|
|
+
|
|
|
+def _test_message(message_type, **data):
|
|
|
+ message = create_message(message_type, **data)
|
|
|
+ # print(message)
|
|
|
+ parsed = parse_message(message)[1]
|
|
|
+
|
|
|
+ if parsed == data:
|
|
|
+ print(colored(f"pass {message_type}", "green"))
|
|
|
+ else:
|
|
|
+ pprint(data)
|
|
|
+ print(message)
|
|
|
+ pprint(parsed)
|
|
|
+ print(colored(f"fail {message_type}", "red"))
|
|
|
+ quit(1)
|
|
|
+
|
|
|
def create_dummy_event(ven_id):
|
|
|
"""
|
|
|
Creates a dummy event
|
|
@@ -63,34 +81,21 @@ def create_dummy_event(ven_id):
|
|
|
'response_required': 'always'}
|
|
|
return event
|
|
|
|
|
|
-def test_message(message_type, **data):
|
|
|
- message = create_message(message_type, **data)
|
|
|
- # print(message)
|
|
|
- parsed = parse_message(message)[1]
|
|
|
-
|
|
|
- if parsed == data:
|
|
|
- print(colored(f"pass {message_type}", "green"))
|
|
|
- else:
|
|
|
- pprint(data)
|
|
|
- print(message)
|
|
|
- pprint(parsed)
|
|
|
- print(colored(f"fail {message_type}", "red"))
|
|
|
- quit(1)
|
|
|
-
|
|
|
-test_message('oadrCanceledOpt', response={'response_code': 200, 'response_description': 'OK', 'request_id': generate_id()}, opt_id=generate_id())
|
|
|
-test_message('oadrCanceledPartyRegistration', response={'response_code': 200, 'response_description': 'OK', 'request_id': generate_id()}, registration_id=generate_id(), ven_id='123ABC')
|
|
|
-test_message('oadrCanceledReport', response={'response_code': 200, 'response_description': 'OK', 'request_id': generate_id()}, pending_reports=[{'request_id': generate_id()}, {'request_id': generate_id()}])
|
|
|
-test_message('oadrCanceledReport', response={'response_code': 200, 'response_description': 'OK', 'request_id': generate_id()}, pending_reports=[{'request_id': generate_id()}, {'request_id': generate_id()}], ven_id='123ABC')
|
|
|
-test_message('oadrCancelOpt', request_id=generate_id(), ven_id='123ABC', opt_id=generate_id())
|
|
|
-test_message('oadrCancelPartyRegistration', request_id=generate_id(), ven_id='123ABC', registration_id=generate_id())
|
|
|
-test_message('oadrCancelReport', request_id=generate_id(), ven_id='123ABC', report_request_id=generate_id(), report_to_follow=True)
|
|
|
-test_message('oadrCreatedEvent', response={'response_code': 200, 'response_description': 'OK', 'request_id': generate_id()},
|
|
|
+testcases = [
|
|
|
+('oadrCanceledOpt', dict(response={'response_code': 200, 'response_description': 'OK', 'request_id': generate_id()}, opt_id=generate_id())),
|
|
|
+('oadrCanceledPartyRegistration', dict(response={'response_code': 200, 'response_description': 'OK', 'request_id': generate_id()}, registration_id=generate_id(), ven_id='123ABC')),
|
|
|
+('oadrCanceledReport', dict(response={'response_code': 200, 'response_description': 'OK', 'request_id': generate_id()}, pending_reports=[{'request_id': generate_id()}, {'request_id': generate_id()}])),
|
|
|
+('oadrCanceledReport', dict(response={'response_code': 200, 'response_description': 'OK', 'request_id': generate_id()}, pending_reports=[{'request_id': generate_id()}, {'request_id': generate_id()}], ven_id='123ABC')),
|
|
|
+('oadrCancelOpt', dict(request_id=generate_id(), ven_id='123ABC', opt_id=generate_id())),
|
|
|
+('oadrCancelPartyRegistration', dict(request_id=generate_id(), ven_id='123ABC', registration_id=generate_id())),
|
|
|
+('oadrCancelReport', dict(request_id=generate_id(), ven_id='123ABC', report_request_id=generate_id(), report_to_follow=True)),
|
|
|
+('oadrCreatedEvent', dict(response={'response_code': 200, 'response_description': 'OK', 'request_id': generate_id()},
|
|
|
event_responses=[{'response_code': 200, 'response_description': 'OK', 'request_id': generate_id(), 'event_id': generate_id(), 'modification_number': 1, 'opt_type': 'optIn'},
|
|
|
{'response_code': 200, 'response_description': 'OK', 'request_id': generate_id(), 'event_id': generate_id(), 'modification_number': 1, 'opt_type': 'optIn'},
|
|
|
{'response_code': 200, 'response_description': 'OK', 'request_id': generate_id(), 'event_id': generate_id(), 'modification_number': 1, 'opt_type': 'optIn'}],
|
|
|
- ven_id='123ABC')
|
|
|
-test_message('oadrCreatedReport', response={'response_code': 200, 'response_description': 'OK', 'request_id': generate_id()}, pending_reports=[{'request_id': generate_id()}, {'request_id': generate_id()}], ven_id='123ABC')
|
|
|
-test_message('oadrCreatedEvent', response={'response_code': 200, 'response_description': 'OK', 'request_id': generate_id()},
|
|
|
+ ven_id='123ABC')),
|
|
|
+('oadrCreatedReport', dict(response={'response_code': 200, 'response_description': 'OK', 'request_id': generate_id()}, pending_reports=[{'request_id': generate_id()}, {'request_id': generate_id()}], ven_id='123ABC')),
|
|
|
+('oadrCreatedEvent', dict(response={'response_code': 200, 'response_description': 'OK', 'request_id': generate_id()},
|
|
|
event_responses=[{'response_code': 200, 'response_description': 'OK', 'request_id': generate_id(),
|
|
|
'event_id': generate_id(),
|
|
|
'modification_number': 1,
|
|
@@ -99,15 +104,15 @@ test_message('oadrCreatedEvent', response={'response_code': 200, 'response_descr
|
|
|
'event_id': generate_id(),
|
|
|
'modification_number': 1,
|
|
|
'opt_type': 'optOut'}],
|
|
|
- ven_id='123ABC')
|
|
|
-test_message('oadrCreatedPartyRegistration', response={'response_code': 200, 'response_description': 'OK', 'request_id': generate_id()},
|
|
|
+ ven_id='123ABC')),
|
|
|
+('oadrCreatedPartyRegistration', dict(response={'response_code': 200, 'response_description': 'OK', 'request_id': generate_id()},
|
|
|
registration_id=generate_id(),
|
|
|
ven_id='123ABC',
|
|
|
profiles=[{'profile_name': '2.0b',
|
|
|
'transports': [{'transport_name': 'simpleHttp'}]}],
|
|
|
- vtn_id='VTN123')
|
|
|
-test_message('oadrCreatedReport', response={'response_code': 200, 'response_description': 'OK', 'request_id': generate_id()}, pending_reports=[{'request_id': generate_id()}, {'request_id': generate_id()}])
|
|
|
-test_message('oadrCreateOpt', opt_id=generate_id(),
|
|
|
+ vtn_id='VTN123')),
|
|
|
+('oadrCreatedReport', dict(response={'response_code': 200, 'response_description': 'OK', 'request_id': generate_id()}, pending_reports=[{'request_id': generate_id()}, {'request_id': generate_id()}])),
|
|
|
+('oadrCreateOpt', dict(opt_id=generate_id(),
|
|
|
opt_type='optIn',
|
|
|
opt_reason='participating',
|
|
|
created_date_time=datetime.now(timezone.utc),
|
|
@@ -115,9 +120,9 @@ test_message('oadrCreateOpt', opt_id=generate_id(),
|
|
|
event_id=generate_id(),
|
|
|
modification_number=1,
|
|
|
targets=[{'ven_id': '123ABC'}],
|
|
|
- ven_id='VEN123')
|
|
|
-test_message('oadrCreatePartyRegistration', request_id=generate_id(), ven_id='123ABC', profile_name='2.0b', transport_name='simpleHttp', transport_address='http://localhost', report_only=False, xml_signature=False, ven_name='test', http_pull_model=True)
|
|
|
-test_message('oadrCreateReport', request_id=generate_id(),
|
|
|
+ ven_id='VEN123')),
|
|
|
+('oadrCreatePartyRegistration', dict(request_id=generate_id(), ven_id='123ABC', profile_name='2.0b', transport_name='simpleHttp', transport_address='http://localhost', report_only=False, xml_signature=False, ven_name='test', http_pull_model=True)),
|
|
|
+('oadrCreateReport', dict(request_id=generate_id(),
|
|
|
ven_id='123ABC',
|
|
|
report_requests=[{'report_request_id': 'd2b7bade5f',
|
|
|
'report_specifier': {'granularity': timedelta(seconds=900),
|
|
@@ -127,11 +132,11 @@ test_message('oadrCreateReport', request_id=generate_id(),
|
|
|
'tolerance': {'tolerate': {'startafter': timedelta(seconds=300)}}},
|
|
|
'report_specifier_id': '9c8bdc00e7',
|
|
|
'specifier_payload': {'r_id': 'd6e2e07485',
|
|
|
- 'reading_type': 'Direct Read'}}}])
|
|
|
-test_message('oadrDistributeEvent', request_id=generate_id(), response={'request_id': 123, 'response_code': 200, 'response_description': 'OK'}, events=[create_dummy_event(ven_id='123ABC')], vtn_id='VTN123')
|
|
|
-test_message('oadrPoll', ven_id='123ABC')
|
|
|
-test_message('oadrQueryRegistration', request_id=generate_id())
|
|
|
-test_message('oadrRegisteredReport', ven_id='VEN123', response={'response_code': 200, 'response_description': 'OK', 'request_id': generate_id()},
|
|
|
+ 'reading_type': 'Direct Read'}}}])),
|
|
|
+('oadrDistributeEvent', dict(request_id=generate_id(), response={'request_id': 123, 'response_code': 200, 'response_description': 'OK'}, events=[create_dummy_event(ven_id='123ABC')], vtn_id='VTN123')),
|
|
|
+('oadrPoll', dict(ven_id='123ABC')),
|
|
|
+('oadrQueryRegistration', dict(request_id=generate_id())),
|
|
|
+('oadrRegisteredReport', dict(ven_id='VEN123', response={'response_code': 200, 'response_description': 'OK', 'request_id': generate_id()},
|
|
|
report_requests=[{'report_request_id': generate_id(),
|
|
|
'report_specifier': {'report_specifier_id': generate_id(),
|
|
|
'granularity': timedelta(minutes=15),
|
|
@@ -155,10 +160,10 @@ test_message('oadrRegisteredReport', ven_id='VEN123', response={'response_code':
|
|
|
'ramp_up': timedelta(minutes=15),
|
|
|
'recovery': timedelta(minutes=5)},
|
|
|
'specifier_payload': {'r_id': generate_id(),
|
|
|
- 'reading_type': 'Direct Read'}}}])
|
|
|
-test_message('oadrRequestEvent', request_id=generate_id(), ven_id='123ABC')
|
|
|
-test_message('oadrRequestReregistration', ven_id='123ABC')
|
|
|
-test_message('oadrRegisterReport', request_id=generate_id(), reports=[{'report_id': generate_id(),
|
|
|
+ 'reading_type': 'Direct Read'}}}])),
|
|
|
+('oadrRequestEvent', dict(request_id=generate_id(), ven_id='123ABC')),
|
|
|
+('oadrRequestReregistration', dict(ven_id='123ABC')),
|
|
|
+('oadrRegisterReport', dict(request_id=generate_id(), reports=[{'report_id': generate_id(),
|
|
|
'report_descriptions': {
|
|
|
generate_id(): {
|
|
|
'report_subjects': [{'ven_id': '123ABC'}],
|
|
@@ -172,72 +177,72 @@ test_message('oadrRegisterReport', request_id=generate_id(), reports=[{'report_i
|
|
|
'report_name': 'HISTORY_USAGE',
|
|
|
'created_date_time': datetime.now(timezone.utc)}],
|
|
|
ven_id='123ABC',
|
|
|
- report_request_id=generate_id())
|
|
|
-test_message('oadrRegisterReport', **{'request_id': '8a4f859883', 'reports': [{'report_id': generate_id(),
|
|
|
- 'duration': timedelta(seconds=7200),
|
|
|
- 'report_descriptions': {'resource1_status': {
|
|
|
- 'report_data_sources': [{'resource_id': 'resource1'}],
|
|
|
- 'report_type': 'x-resourceStatus',
|
|
|
- 'reading_type': 'x-notApplicable',
|
|
|
- 'market_context': 'http://MarketContext1',
|
|
|
- 'sampling_rate': {'min_period': timedelta(seconds=60), 'max_period': timedelta(seconds=60), 'on_change': False}}},
|
|
|
- 'report_request_id': '0',
|
|
|
- 'report_specifier_id': '789ed6cd4e_telemetry_status',
|
|
|
- 'report_name': 'METADATA_TELEMETRY_STATUS',
|
|
|
- 'created_date_time': datetime(2019, 11, 20, 15, 4, 52, 638621, tzinfo=timezone.utc)},
|
|
|
- {'report_id': generate_id(),
|
|
|
- 'duration': timedelta(seconds=7200),
|
|
|
- 'report_descriptions': {'resource1_energy': {
|
|
|
- 'report_data_sources': [{'resource_id': 'resource1'}],
|
|
|
- 'report_type': 'usage',
|
|
|
- 'energy_real': {'item_description': 'RealEnergy',
|
|
|
- 'item_units': 'Wh',
|
|
|
- 'si_scale_code': 'n'},
|
|
|
- 'reading_type': 'Direct Read',
|
|
|
- 'market_context': 'http://MarketContext1',
|
|
|
- 'sampling_rate': {'min_period': timedelta(seconds=60), 'max_period': timedelta(seconds=60), 'on_change': False}},
|
|
|
- 'resource1_power': {
|
|
|
- 'report_data_sources': [{'resource_id': 'resource1'}],
|
|
|
- 'report_type': 'usage',
|
|
|
- 'power_real': {'item_description': 'RealPower',
|
|
|
- 'item_units': 'W',
|
|
|
- 'si_scale_code': 'n',
|
|
|
- 'power_attributes': {'hertz': 60, 'voltage': 110, 'ac': False}},
|
|
|
- 'reading_type': 'Direct Read',
|
|
|
- 'market_context': 'http://MarketContext1',
|
|
|
- 'sampling_rate': {'min_period': timedelta(seconds=60), 'max_period': timedelta(seconds=60), 'on_change': False}}},
|
|
|
- 'report_request_id': '0',
|
|
|
- 'report_specifier_id': '789ed6cd4e_telemetry_usage',
|
|
|
- 'report_name': 'METADATA_TELEMETRY_USAGE',
|
|
|
- 'created_date_time': datetime(2019, 11, 20, 15, 4, 52, 638621, tzinfo=timezone.utc)},
|
|
|
- {'report_id': generate_id(),
|
|
|
- 'duration': timedelta(seconds=7200),
|
|
|
- 'report_descriptions': {'resource1_energy': {
|
|
|
- 'report_data_sources': [{'resource_id': 'resource1'}],
|
|
|
- 'report_type': 'usage',
|
|
|
- 'energy_real': {'item_description': 'RealEnergy',
|
|
|
- 'item_units': 'Wh',
|
|
|
- 'si_scale_code': 'n'},
|
|
|
- 'reading_type': 'Direct Read',
|
|
|
- 'market_context': 'http://MarketContext1',
|
|
|
- 'sampling_rate': {'min_period': timedelta(seconds=60), 'max_period': timedelta(seconds=60), 'on_change': False}},
|
|
|
- 'resource1_power': {
|
|
|
- 'report_data_sources': [{'resource_id': 'resource1'}],
|
|
|
- 'report_type': 'usage',
|
|
|
- 'power_real': {'item_description': 'RealPower',
|
|
|
- 'item_units': 'W', 'si_scale_code': 'n',
|
|
|
- 'power_attributes': {'hertz': 60, 'voltage': 110, 'ac': False}},
|
|
|
- 'reading_type': 'Direct Read',
|
|
|
- 'market_context': 'http://MarketContext1',
|
|
|
- 'sampling_rate': {'min_period': timedelta(seconds=60), 'max_period': timedelta(seconds=60), 'on_change': False}}},
|
|
|
- 'report_request_id': '0',
|
|
|
- 'report_specifier_id': '789ed6cd4e_history_usage',
|
|
|
- 'report_name': 'METADATA_HISTORY_USAGE',
|
|
|
- 'created_date_time': datetime(2019, 11, 20, 15, 4, 52, 638621, tzinfo=timezone.utc)}], 'ven_id': 's3cc244ee6'})
|
|
|
-test_message('oadrResponse', response={'response_code': 200, 'response_description': 'OK', 'request_id': generate_id()}, ven_id='123ABC')
|
|
|
-test_message('oadrResponse', response={'response_code': 200, 'response_description': 'OK', 'request_id': None}, ven_id='123ABC')
|
|
|
-test_message('oadrUpdatedReport', response={'response_code': 200, 'response_description': 'OK', 'request_id': generate_id()}, ven_id='123ABC', cancel_report={'request_id': generate_id(), 'report_request_id': [generate_id(), generate_id(), generate_id()], 'report_to_follow': False, 'ven_id': '123ABC'})
|
|
|
-test_message('oadrUpdateReport', request_id=generate_id(), reports=[{'report_id': generate_id(),
|
|
|
+ report_request_id=generate_id())),
|
|
|
+('oadrRegisterReport', {'request_id': '8a4f859883', 'reports': [{'report_id': generate_id(),
|
|
|
+ 'duration': timedelta(seconds=7200),
|
|
|
+ 'report_descriptions': {'resource1_status': {
|
|
|
+ 'report_data_sources': [{'resource_id': 'resource1'}],
|
|
|
+ 'report_type': 'x-resourceStatus',
|
|
|
+ 'reading_type': 'x-notApplicable',
|
|
|
+ 'market_context': 'http://MarketContext1',
|
|
|
+ 'sampling_rate': {'min_period': timedelta(seconds=60), 'max_period': timedelta(seconds=60), 'on_change': False}}},
|
|
|
+ 'report_request_id': '0',
|
|
|
+ 'report_specifier_id': '789ed6cd4e_telemetry_status',
|
|
|
+ 'report_name': 'METADATA_TELEMETRY_STATUS',
|
|
|
+ 'created_date_time': datetime(2019, 11, 20, 15, 4, 52, 638621, tzinfo=timezone.utc)},
|
|
|
+ {'report_id': generate_id(),
|
|
|
+ 'duration': timedelta(seconds=7200),
|
|
|
+ 'report_descriptions': {'resource1_energy': {
|
|
|
+ 'report_data_sources': [{'resource_id': 'resource1'}],
|
|
|
+ 'report_type': 'usage',
|
|
|
+ 'energy_real': {'item_description': 'RealEnergy',
|
|
|
+ 'item_units': 'Wh',
|
|
|
+ 'si_scale_code': 'n'},
|
|
|
+ 'reading_type': 'Direct Read',
|
|
|
+ 'market_context': 'http://MarketContext1',
|
|
|
+ 'sampling_rate': {'min_period': timedelta(seconds=60), 'max_period': timedelta(seconds=60), 'on_change': False}},
|
|
|
+ 'resource1_power': {
|
|
|
+ 'report_data_sources': [{'resource_id': 'resource1'}],
|
|
|
+ 'report_type': 'usage',
|
|
|
+ 'power_real': {'item_description': 'RealPower',
|
|
|
+ 'item_units': 'W',
|
|
|
+ 'si_scale_code': 'n',
|
|
|
+ 'power_attributes': {'hertz': 60, 'voltage': 110, 'ac': False}},
|
|
|
+ 'reading_type': 'Direct Read',
|
|
|
+ 'market_context': 'http://MarketContext1',
|
|
|
+ 'sampling_rate': {'min_period': timedelta(seconds=60), 'max_period': timedelta(seconds=60), 'on_change': False}}},
|
|
|
+ 'report_request_id': '0',
|
|
|
+ 'report_specifier_id': '789ed6cd4e_telemetry_usage',
|
|
|
+ 'report_name': 'METADATA_TELEMETRY_USAGE',
|
|
|
+ 'created_date_time': datetime(2019, 11, 20, 15, 4, 52, 638621, tzinfo=timezone.utc)},
|
|
|
+ {'report_id': generate_id(),
|
|
|
+ 'duration': timedelta(seconds=7200),
|
|
|
+ 'report_descriptions': {'resource1_energy': {
|
|
|
+ 'report_data_sources': [{'resource_id': 'resource1'}],
|
|
|
+ 'report_type': 'usage',
|
|
|
+ 'energy_real': {'item_description': 'RealEnergy',
|
|
|
+ 'item_units': 'Wh',
|
|
|
+ 'si_scale_code': 'n'},
|
|
|
+ 'reading_type': 'Direct Read',
|
|
|
+ 'market_context': 'http://MarketContext1',
|
|
|
+ 'sampling_rate': {'min_period': timedelta(seconds=60), 'max_period': timedelta(seconds=60), 'on_change': False}},
|
|
|
+ 'resource1_power': {
|
|
|
+ 'report_data_sources': [{'resource_id': 'resource1'}],
|
|
|
+ 'report_type': 'usage',
|
|
|
+ 'power_real': {'item_description': 'RealPower',
|
|
|
+ 'item_units': 'W', 'si_scale_code': 'n',
|
|
|
+ 'power_attributes': {'hertz': 60, 'voltage': 110, 'ac': False}},
|
|
|
+ 'reading_type': 'Direct Read',
|
|
|
+ 'market_context': 'http://MarketContext1',
|
|
|
+ 'sampling_rate': {'min_period': timedelta(seconds=60), 'max_period': timedelta(seconds=60), 'on_change': False}}},
|
|
|
+ 'report_request_id': '0',
|
|
|
+ 'report_specifier_id': '789ed6cd4e_history_usage',
|
|
|
+ 'report_name': 'METADATA_HISTORY_USAGE',
|
|
|
+ 'created_date_time': datetime(2019, 11, 20, 15, 4, 52, 638621, tzinfo=timezone.utc)}], 'ven_id': 's3cc244ee6'}),
|
|
|
+('oadrResponse', dict(response={'response_code': 200, 'response_description': 'OK', 'request_id': generate_id()}, ven_id='123ABC')),
|
|
|
+('oadrResponse', dict(response={'response_code': 200, 'response_description': 'OK', 'request_id': None}, ven_id='123ABC')),
|
|
|
+('oadrUpdatedReport', dict(response={'response_code': 200, 'response_description': 'OK', 'request_id': generate_id()}, ven_id='123ABC', cancel_report={'request_id': generate_id(), 'report_request_id': [generate_id(), generate_id(), generate_id()], 'report_to_follow': False, 'ven_id': '123ABC'})),
|
|
|
+('oadrUpdateReport', dict(request_id=generate_id(), reports=[{'report_id': generate_id(),
|
|
|
'report_name': enums.REPORT_NAME.values[0],
|
|
|
'created_date_time': datetime.now(timezone.utc),
|
|
|
'report_request_id': generate_id(),
|
|
@@ -249,11 +254,11 @@ test_message('oadrUpdateReport', request_id=generate_id(), reports=[{'report_id'
|
|
|
'market_context': 'http://localhost',
|
|
|
'sampling_rate': {'min_period': timedelta(minutes=1),
|
|
|
'max_period': timedelta(minutes=2),
|
|
|
- 'on_change': False}}}}], ven_id='123ABC')
|
|
|
+ 'on_change': False}}}}], ven_id='123ABC'))
|
|
|
# for report_name in enums.REPORT_NAME.values:
|
|
|
# for reading_type in enums.READING_TYPE.values:
|
|
|
# for report_type in enums.REPORT_TYPE.values:
|
|
|
-# test_message('oadrUpdateReport', request_id=generate_id(), reports=[{'report_id': generate_id(),
|
|
|
+# ('oadrUpdateReport', dict(request_id=generate_id(), reports=[{'report_id': generate_id()),
|
|
|
# 'report_name': report_name,
|
|
|
# 'created_date_time': datetime.now(timezone.utc),
|
|
|
# 'report_request_id': generate_id(),
|
|
@@ -268,3 +273,4 @@ test_message('oadrUpdateReport', request_id=generate_id(), reports=[{'report_id'
|
|
|
# 'max_period': timedelta(minutes=2),
|
|
|
# 'on_change': False}}]}], ven_id='123ABC')
|
|
|
|
|
|
+]
|