def test_FromJSON(self): icomp = InteractionComponent.from_json( '{"id": "test", "description": {"en-US": "test"}}') self.assertEqual(icomp.id, 'test') self.descriptionVerificationHelper(icomp.description)
def test_ToJSONFromJSON(self): json_str = '{"id": "test", "description": {"en-US": "test"}}' icomp = InteractionComponent.from_json(json_str) self.assertEqual(icomp.id, 'test') self.descriptionVerificationHelper(icomp.description) self.assertEqual(json.loads(icomp.to_json()), json.loads(json_str))
def test_FromJSONId(self): icomp = InteractionComponent.from_json('{"id": "test"}') self.assertEqual(icomp.id, 'test') self.assertNotIn('description', vars(icomp))
def test_FromJSONExceptionFlatDescription(self): with self.assertRaises(ValueError): InteractionComponent.from_json( '{"id": "test", "description": "flatdescription"}')
def test_FromJSONEmptyObject(self): icomp = InteractionComponent.from_json('{}') self.assertIsNone(icomp.id) self.assertNotIn('description', vars(icomp))
def test_FromJSONExceptionEmpty(self): with self.assertRaises(ValueError): InteractionComponent.from_json('')
def test_FromJSONExceptionBadJSON(self): with self.assertRaises(ValueError): icomp = InteractionComponent.from_json('{"bad JSON"}')
def test_FromJSONEmptyObject(self): icomp = InteractionComponent.from_json("{}") self.assertIsNone(icomp.id) self.assertNotIn("description", vars(icomp))
def test_FromJSON(self): icomp = InteractionComponent.from_json('{"id": "test", "description": {"en-US": "test"}}') self.assertEqual(icomp.id, "test") self.descriptionVerificationHelper(icomp.description)
def test_ToJSONFromJSON(self): json_str = '{"id": "test", "description": {"en-US": "test"}}' icomp = InteractionComponent.from_json(json_str) self.assertEqual(icomp.id, "test") self.descriptionVerificationHelper(icomp.description) self.assertEqual(icomp.to_json(), json_str)
def test_FromJSONExceptionFlatDescription(self): with self.assertRaises(ValueError): icomp = InteractionComponent.from_json('{"id": "test", "description": "flatdescription"}')
def test_FromJSONId(self): icomp = InteractionComponent.from_json('{"id": "test"}') self.assertEqual(icomp.id, "test") self.assertNotIn("description", vars(icomp))
def test_FromJSONExceptionEmpty(self): with self.assertRaises(ValueError): icomp = InteractionComponent.from_json("")
def test_FromJSONExceptionBadJSON(self): with self.assertRaises(ValueError): InteractionComponent.from_json('{"bad JSON"}')
def test_FromJSONExceptionPartiallyMalformedJSON(self): with self.assertRaises(AttributeError): icomp = InteractionComponent.from_json( '{"test": "invalid property", "id": \ "valid property"}' )
def test_FromJSONExceptionPartiallyMalformedJSON(self): with self.assertRaises(AttributeError): InteractionComponent.from_json( '{"test": "invalid property", "id": \ "valid property"}')
def test_FromJSONExceptionMalformedJSON(self): with self.assertRaises(AttributeError): InteractionComponent.from_json('{"test": "invalid property"}')