def test_setItemException(self): ic1 = InteractionComponent(id='test1', description={"en-US": "test1"}) ic2 = InteractionComponent(id='test2', description={"en-US": "test2"}) iclist = InteractionComponentList([ic1, ic2]) with self.assertRaises(TypeError): iclist[0] = 'not InteractionComponent' self.listVerificationHelper(iclist)
def test_appendItem(self): ic1 = InteractionComponent(id='test1', description={"en-US": "test1"}) ic2 = InteractionComponent(id='test2', description={"en-US": "test2"}) iclist = InteractionComponentList() iclist.append(ic1) iclist.append(ic2) self.listVerificationHelper(iclist)
def test_setItem(self): iclist = InteractionComponentList( [InteractionComponent(), InteractionComponent()]) iclist[0] = {"id": "test1", "description": {"en-US": "test1"}} iclist[1] = InteractionComponent(id="test2", description={"en-US": "test2"}) self.listVerificationHelper(iclist)
def test_insert(self): ic1 = InteractionComponent(id='test1') ic2 = InteractionComponent(id='test3') iclist = InteractionComponentList([ic1, ic2]) iclist.insert(1, InteractionComponent(id='test2')) self.assertEqual(len(iclist), 3) self.assertEqual(iclist[0].id, 'test1') self.assertEqual(iclist[1].id, 'test2') self.assertEqual(iclist[2].id, 'test3')
def test_ToJSON(self): icomp = InteractionComponent(**{ "id": "test", "description": { "en-US": "test" } }) self.assertEqual(icomp.to_json(), '{"id": "test", "description": {"en-US": "test"}}')
def test_extend(self): ic1 = InteractionComponent(id='test1') ic2 = InteractionComponent(id='test2') arglist = InteractionComponentList([ic1, ic2]) iclist = InteractionComponentList([InteractionComponent(id='test3')]) iclist.extend(arglist) self.assertEqual(len(iclist), 3) self.assertEqual(iclist[0].id, 'test3') self.assertEqual(iclist[1].id, 'test1') self.assertEqual(iclist[2].id, 'test2')
def test_AsVersionNotEmpty(self): ic1 = InteractionComponent(id='test1', description={"en-US": "test1"}) ic2 = InteractionComponent(id='test2', description={"en-US": "test2"}) iclist = InteractionComponentList([ic1, ic2]) check = iclist.as_version() self.assertEqual(check, [{ "id": "test1", "description": { "en-US": "test1" } }, { "id": "test2", "description": { "en-US": "test2" } }])
def test_InitEmpty(self): icomp = InteractionComponent() self.assertIsNone(icomp.id) self.assertNotIn('description', vars(icomp))
def test_InitId(self): icomp = InteractionComponent(id='test') self.assertEqual(icomp.id, 'test') self.assertNotIn('description', vars(icomp))
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_ToJSONIgnoreNoneId(self): icomp = InteractionComponent(description={"en-US": "test"}) self.assertEqual(icomp.to_json(), '{"description": {"en-US": "test"}}')
def test_FromJSONExceptionFlatDescription(self): with self.assertRaises(ValueError): InteractionComponent.from_json( '{"id": "test", "description": "flatdescription"}')
def test_AsVersionEmpty(self): icomp = InteractionComponent() icomp2 = icomp.as_version("1.0.0") self.assertEqual(icomp2, {})
def test_FromJSONExceptionBadJSON(self): with self.assertRaises(ValueError): icomp = InteractionComponent.from_json('{"bad JSON"}')
def test_AsVersionNotEmpty(self): icomp = InteractionComponent(**{"id": "test"}) icomp2 = icomp.as_version() self.assertEqual(icomp2, {"id": "test"})
def test_ToJSONIgnoreNoneId(self): icomp = InteractionComponent(description={"en-US": "test"}) self.assertEqual(icomp.to_json(), '{"description": {"en-US": "test"}}')
def test_ToJSONEmpty(self): icomp = InteractionComponent() self.assertEqual(icomp.to_json(), "{}")
def test_ToJSONIgnoreNoneDescription(self): icomp = InteractionComponent(id="test") self.assertEqual(icomp.to_json(), '{"id": "test"}')
def test_ToJSON(self): icomp = InteractionComponent(**{"id": "test", "description": {"en-US": "test"}}) self.assertEqual(icomp.to_json(), '{"id": "test", "description": {"en-US": "test"}}')
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_InitLanguageMapDescription(self): icomp = InteractionComponent(id='test', description=LanguageMap({"en-US": "test"})) self.assertEqual(icomp.id, 'test') self.descriptionVerificationHelper(icomp.description)
def test_FromJSONExceptionPartiallyMalformedJSON(self): with self.assertRaises(AttributeError): icomp = InteractionComponent.from_json( '{"test": "invalid property", "id": \ "valid property"}' )
def test_InitUnpackDescription(self): obj = {"description": {"en-US": "test"}} icomp = InteractionComponent(**obj) self.descriptionVerificationHelper(icomp.description)
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_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): icomp = InteractionComponent.from_json('{"id": "test", "description": "flatdescription"}')
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_FromJSONId(self): icomp = InteractionComponent.from_json('{"id": "test"}') self.assertEqual(icomp.id, "test") self.assertNotIn("description", vars(icomp))
def test_AsVersionNotEmpty(self): icomp = InteractionComponent(**{'id': 'test'}) icomp2 = icomp.as_version() self.assertEqual(icomp2, {'id': 'test'})
def test_FromJSONExceptionEmpty(self): with self.assertRaises(ValueError): icomp = InteractionComponent.from_json("")
def test_ToJSONIgnoreNoneDescription(self): icomp = InteractionComponent(id='test') self.assertEqual(icomp.to_json(), '{"id": "test"}')
def test_FromJSONEmptyObject(self): icomp = InteractionComponent.from_json("{}") self.assertIsNone(icomp.id) self.assertNotIn("description", vars(icomp))
def test_ToJSONEmpty(self): icomp = InteractionComponent() self.assertEqual(icomp.to_json(), '{}')
def test_InitExceptionUnpackEmptyId(self): obj = {"id": ""} with self.assertRaises(ValueError): InteractionComponent(**obj)
def test_InitExceptionEmptyId(self): with self.assertRaises(ValueError): InteractionComponent(id='')
def test_FromJSONExceptionBadJSON(self): with self.assertRaises(ValueError): InteractionComponent.from_json('{"bad JSON"}')
def test_InitDescription(self): icomp = InteractionComponent(description={"en-US": "test"}) self.assertIsNone(icomp.id) self.descriptionVerificationHelper(icomp.description)
def test_FromJSONExceptionMalformedJSON(self): with self.assertRaises(AttributeError): InteractionComponent.from_json('{"test": "invalid property"}')
def test_InitEmptyLanguageMapDescription(self): icomp = InteractionComponent(id='test', description=LanguageMap({})) self.assertEqual(icomp.id, 'test') self.assertIsInstance(icomp.description, LanguageMap) self.assertEqual(len(vars(icomp.description)), 0)
def test_FromJSONExceptionEmpty(self): with self.assertRaises(ValueError): InteractionComponent.from_json('')
def test_InitUnpack(self): obj = {"id": "test", "description": {"en-US": "test"}} icomp = InteractionComponent(**obj) self.assertEqual(icomp.id, 'test') self.descriptionVerificationHelper(icomp.description)
def test_AsVersionEmpty(self): icomp = InteractionComponent() icomp2 = icomp.as_version("1.0.0") self.assertEqual(icomp2, {})
def test_InitExceptionUnpackFlatDescription(self): obj = {"id": "test", "description": "test"} with self.assertRaises(ValueError): InteractionComponent(**obj)
def test_FromJSONEmptyObject(self): icomp = InteractionComponent.from_json('{}') self.assertIsNone(icomp.id) self.assertNotIn('description', vars(icomp))
def test_FromJSONExceptionPartiallyMalformedJSON(self): with self.assertRaises(AttributeError): InteractionComponent.from_json( '{"test": "invalid property", "id": \ "valid property"}')
def test_AsVersionNotEmpty(self): icomp = InteractionComponent(**{'id': 'test'}) icomp2 = icomp.as_version() self.assertEqual(icomp2, {'id': 'test'})