def test_to_dict(self): s = DataServiceInfo(**self.TESTDATA) self.assertEqual(s.to_dict(), self.TESTDATA, 'dict representation matches constructed data') s.last_hb_time = time.time() self.assertEqual(s.to_dict(), self.TESTDATA, 'dict representation ignores last_hb_time')
def test_to_json(self): s = DataServiceInfo(**self.TESTDATA) self.assertEqual(json.loads(s.to_json()), self.TESTDATA, 'JSON representation matches constructed data') s.last_hb_time = time.time() self.assertEqual(json.loads(s.to_json()), self.TESTDATA, 'JSON representation ignores last_hb_time')
def test_from_dict(self): s = DataServiceInfo.from_dict(self.TESTDATA) for a in DataServiceInfo.MARSHALL_ATTRS: self.assertEqual(getattr(s, a), self.TESTDATA[a], "Attr '%s' set properly in from_dict" % a) self.assertRaises(KeyError, DataServiceInfo.from_dict, {'bad_attr': 123})
def test_from_json(self): s = DataServiceInfo.from_json(json.dumps(self.TESTDATA)) for a in DataServiceInfo.MARSHALL_ATTRS: self.assertEqual(getattr(s, a), self.TESTDATA[a], "Attr '%s' set properly in from_dict" % a) self.assertRaises(KeyError, DataServiceInfo.from_json, '{"bad_attr": 123}')