From: Tim Van Steenburgh Date: Sun, 6 Nov 2016 00:32:25 +0000 (-0400) Subject: Add Observer tests X-Git-Tag: 0.1.0~55 X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=6d260e15f4122a100d7cbecb81bd5a1a1a2bffa8;p=osm%2FN2VC.git Add Observer tests --- diff --git a/tests/unit/test_model.py b/tests/unit/test_model.py new file mode 100644 index 0000000..97966da --- /dev/null +++ b/tests/unit/test_model.py @@ -0,0 +1,56 @@ +import unittest + + +class TestObserver(unittest.TestCase): + def _make_observer(self, *args): + from juju.model import _Observer + return _Observer(*args) + + def _make_delta(self, entity, type_, data=None): + from juju.delta import ApplicationDelta + return ApplicationDelta([entity, type_, data]) + + def test_cares_about_id(self): + id_ = 'foo' + + o = self._make_observer( + None, None, None, id_, None) + + delta = self._make_delta( + 'application', 'change', dict(name=id_)) + + self.assertTrue(o.cares_about(delta)) + + def test_cares_about_type(self): + type_ = 'application' + + o = self._make_observer( + None, type_, None, None, None) + + delta = self._make_delta( + type_, 'change', dict(name='foo')) + + self.assertTrue(o.cares_about(delta)) + + def test_cares_about_action(self): + action = 'change' + + o = self._make_observer( + None, None, action, None, None) + + delta = self._make_delta( + 'application', action, dict(name='foo')) + + self.assertTrue(o.cares_about(delta)) + + def test_cares_about_predicate(self): + def predicate(delta): + return delta.data.get('fizz') == 'bang' + + o = self._make_observer( + None, None, None, None, predicate) + + delta = self._make_delta( + 'application', 'change', dict(fizz='bang')) + + self.assertTrue(o.cares_about(delta))