Skip to content

Commit

Permalink
Issue #92 - Refactoring and adding -default flag to script for testin…
Browse files Browse the repository at this point in the history
…g default notif config options
  • Loading branch information
aywaldron committed Dec 4, 2018
1 parent e79ade3 commit 450df27
Showing 1 changed file with 24 additions and 10 deletions.
34 changes: 24 additions & 10 deletions test_scripts/notification_test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import ait.gui
import ait.core
import mock
import argparse
from collections import defaultdict
from time import sleep
from ait.core import cfg, tlm, limits
Expand All @@ -12,10 +13,28 @@
"""


def main():
global pkt_defn, pkt, limit_dict, limit_defn
pkt_defn, pkt = get_packet_and_defn()
limit_dict = get_limit_dict()
limit_defn = limit_dict[pkt_defn.name]['Voltage_A']

parser = argparse.ArgumentParser()
parser.add_argument('-default', action='store_true',
help='flag for testing the default notif options')

args = parser.parse_args()
enable_monitoring_test(args.default)


@mock.patch('ait.core.notify.trigger_notification')
def enable_monitoring_test(mock_notify):
def enable_monitoring_test(default, mock_notify):
try:
set_notif_options(thrshld=3, freq=2)
if not default:
set_notif_options(thrshld=3, freq=2)
expected = 3
else:
expected = 1
print_notif_options()

ait.gui.init('localhost', 8080)
Expand All @@ -37,11 +56,11 @@ def enable_monitoring_test(mock_notify):
# value 0 should notify 3 times (msg 3, 5, 7)
call_list = [mock.mock.call(
'limit-error',
'Field Voltage_A error out of limit with value 0')] * 3
'Field Voltage_A error out of limit with value 0')] * expected
# value 50 should notify 3 times (msg 3, 5, 7)
call_list.extend([mock.mock.call(
'limit-error',
'Field Voltage_A error out of limit with value 50')] * 3)
'Field Voltage_A error out of limit with value 50')] * expected)

print('Notification was triggered {} times.'
.format(mock_notify.call_count))
Expand Down Expand Up @@ -108,9 +127,4 @@ def set_notif_options(thrshld=None, freq=None):


if __name__ == "__main__":
global pkt_defn, pkt, limit_dict, limit_defn
pkt_defn, pkt = get_packet_and_defn()
limit_dict = get_limit_dict()
limit_defn = limit_dict[pkt_defn.name]['Voltage_A']

enable_monitoring_test()
main()

0 comments on commit 450df27

Please sign in to comment.