Skip to content

Commit 21f8b99

Browse files
author
Siddharta Govindaraj
committed
Implementing a spy
1 parent 6003513 commit 21f8b99

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

stock_alerter/tests/test_alert.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,15 @@ def test_action_is_executed_when_rule_matches(self):
2222
alert.connect(exchange)
2323
exchange["GOOG"].update(datetime(2014, 2, 10), 11)
2424
action.execute.assert_called_with("sample alert")
25+
26+
def test_action_doesnt_fire_if_rule_doesnt_match(self):
27+
goog = Stock("GOOG")
28+
exchange = {"GOOG": goog}
29+
rule = PriceRule("GOOG", lambda stock: stock.price > 10)
30+
rule_spy = mock.MagicMock(wraps=rule)
31+
action = mock.MagicMock()
32+
alert = Alert("sample alert", rule_spy, action)
33+
alert.connect(exchange)
34+
alert.check_rule(goog)
35+
rule_spy.matches.assert_called_with(exchange)
36+
self.assertFalse(action.execute.called)

0 commit comments

Comments
 (0)