def test_load_class_from_json(self): self.assertEqual( Util.load_class_from_json(json.dumps(self.service1)), self.service1.__class__, msg=json.dumps(self.service1), ) self.assertEqual( Util.load_class_from_json(json.dumps(self.oauthservice1)), self.oauthservice1.__class__, ) self.assertEqual(Util.load_class_from_json(json.dumps(self.token1)), self.token1.__class__) self.assertEqual( Util.load_class_from_json(json.dumps(self.oauthtoken1)), self.oauthtoken1.__class__, ) self.assertEqual(Util.load_class_from_json(json.dumps(self.user1)), self.user1.__class__)
def test_invalid_input(self): with self.assertRaises(ValueError): Util.load_class_from_json(123) with self.assertRaises(ValueError): Util.load_class_from_json([]) with self.assertRaises(ValueError): Util.load_class_from_json("") with self.assertRaises(ValueError): Util.load_class_from_json("Blub bla bla") with self.assertRaises(ValueError): Util.load_class_from_json(json.dumps({})) with self.assertRaises(ValueError): jsonStr = json.dumps(self.token1) data = json.loads(jsonStr) del data["type"] Util.load_class_from_json(json.dumps(data)) with self.assertRaises(ValueError): Util.initialize_object_from_json(123) with self.assertRaises(ValueError): Util.initialize_object_from_json([]) with self.assertRaises(ValueError): Util.initialize_object_from_json("") with self.assertRaises(ValueError): Util.initialize_object_from_json("blub bla bla")