class TestView(unittest.TestCase): def setUp(self): self.data = BlockMeta() self.data.set_notifier_path(Mock(), ["block", "meta"]) self.controller = Mock() self.context = Mock() self.o = make_view(self.controller, self.context, self.data) def test_init(self): assert hasattr(self.o, "description") assert hasattr(self.o, "subscribe_description") assert hasattr(self.o, "tags") assert hasattr(self.o, "subscribe_tags") assert hasattr(self.o, "writeable") assert hasattr(self.o, "subscribe_writeable") assert hasattr(self.o, "label") assert hasattr(self.o, "subscribe_label") def test_get_view(self): v = self.o.description self.controller.make_view.assert_called_once_with( self.context, self.data, "description") assert v == self.controller.make_view.return_value def test_second_subclass(self): data2 = {"a": 2} o2 = make_view(self.controller, self.context, data2) assert hasattr(o2, "a") assert hasattr(o2, "subscribe_a") assert not hasattr(self.o, "a") assert not hasattr(self.o, "subscribe_a") def test_subscribe_view(self): cb = Mock() f = self.o.subscribe_label(cb) self.context.subscribe.assert_called_once_with( ["block", "meta", "label"], cb) assert f == self.context.subscribe.return_value def test_view_init_fails(self): with self.assertRaises(NotImplementedError): v = View()
def test_from_dict(self): m = BlockMeta.from_dict(self.serialized) self.assertEquals(m.description, "desc") self.assertEquals(m.tags, []) self.assertEquals(m.writeable, False) self.assertEquals(m.label, "")
def test_to_dict(self): m = BlockMeta("desc") self.assertEqual(m.to_dict(), self.serialized)
def create_meta(self): self.meta = BlockMeta() return "meta", self.meta, None
def test_from_dict(self): m = BlockMeta.from_dict(self.serialized) self.assertEquals(m.description, "desc") self.assertEquals(m.tags, [])
def setUp(self): self.data = BlockMeta() self.data.set_notifier_path(Mock(), ["block", "meta"]) self.controller = Mock() self.context = Mock() self.o = make_view(self.controller, self.context, self.data)
def test_from_dict(self): m = BlockMeta.from_dict(self.serialized) self.assertEquals(m.description, "desc") self.assertEquals(m.tags, ()) self.assertEquals(m.writeable, False) self.assertEquals(m.label, "")
def test_init(self): block_meta = BlockMeta("desc") self.assertEqual("malcolm:core/BlockMeta:1.0", block_meta.typeid)
def test_from_dict(self): m = BlockMeta.from_dict(self.serialized) assert m.description == "desc" assert m.tags == () assert m.writeable == False assert m.label == ""
def test_to_dict(self): m = BlockMeta("desc") assert m.to_dict() == self.serialized