From 5509f7d1c86b9667baf1f7743e4b4b1a55f70d1d Mon Sep 17 00:00:00 2001 From: Tim Kuhlman Date: Thu, 20 Mar 2014 09:52:19 -0600 Subject: [PATCH] Added a simple unit test and the test framework --- tests/__init__.py | 0 {test => tests/manual}/README.md | 0 {test => tests/manual}/invalid.json | 0 {test => tests/manual}/no-op.json | 0 {test => tests/manual}/notify.json | 0 .../manual}/sample_notifications.sql | 0 tests/test_notification.py | 28 +++++++++++++++++++ 7 files changed, 28 insertions(+) create mode 100644 tests/__init__.py rename {test => tests/manual}/README.md (100%) rename {test => tests/manual}/invalid.json (100%) rename {test => tests/manual}/no-op.json (100%) rename {test => tests/manual}/notify.json (100%) rename {test => tests/manual}/sample_notifications.sql (100%) create mode 100644 tests/test_notification.py diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/test/README.md b/tests/manual/README.md similarity index 100% rename from test/README.md rename to tests/manual/README.md diff --git a/test/invalid.json b/tests/manual/invalid.json similarity index 100% rename from test/invalid.json rename to tests/manual/invalid.json diff --git a/test/no-op.json b/tests/manual/no-op.json similarity index 100% rename from test/no-op.json rename to tests/manual/no-op.json diff --git a/test/notify.json b/tests/manual/notify.json similarity index 100% rename from test/notify.json rename to tests/manual/notify.json diff --git a/test/sample_notifications.sql b/tests/manual/sample_notifications.sql similarity index 100% rename from test/sample_notifications.sql rename to tests/manual/sample_notifications.sql diff --git a/tests/test_notification.py b/tests/test_notification.py new file mode 100644 index 0000000..48785fc --- /dev/null +++ b/tests/test_notification.py @@ -0,0 +1,28 @@ +"""Tests the notification class.""" + +import json +from mon_notification import notification + +def test_json(): + """Test the to_json method to verify it behaves as expected. + """ + alarm = {'alarmId': 'alarmId', + 'alarmName': 'alarmName', + 'timestamp': 'timestamp', + 'stateChangeReason': 'stateChangeReason', + 'newState': 'newState', + 'tenantId': 'tenantId'} + test_notification = notification.Notification('ntype', 'src_partition', 'src_offset', 'name', 'address', alarm) + + expected_dict = {u'name': u'name', + u'notification_timestamp': None, + u'tenant_id': u'tenantId', + u'alarm_name': u'alarmName', + u'alarm_id': u'alarmId', + u'state': u'newState', + u'alarm_timestamp': u'timestamp', + u'address': u'address', + u'message': u'stateChangeReason'} + # Compare as dicts so ordering is not an issue + assert json.loads(test_notification.to_json()) == expected_dict +