def test_ToJSON(self): iclist = InteractionComponentList( [{"id": "test1", "description": {"en-US": "test1"}}, {"id": "test2", "description": {"en-US": "test2"}}]) # since the map is unordered, it is ok that to_json() changes ordering self.assertEqual(iclist.to_json(), '[{"id": "test1", "description": {"en-US": "test1"}}, ' '{"id": "test2", "description": {"en-US": "test2"}}]')
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_AsVersion(self): adef = ActivityDefinition({ 'description': {'en-US': 'test'}, 'name': {'en-US': 'test'}, 'type': 'test', 'more_info': 'test', 'interaction_type': 'choice', 'correct_responses_pattern': ['test'], 'choices': InteractionComponentList(), 'scale': InteractionComponentList(), 'source': InteractionComponentList(), 'target': InteractionComponentList(), 'steps': InteractionComponentList(), 'extensions': {'test': 'test'} }) adef2 = adef.as_version() self.assertEqual(adef2, { "name": {"en-US": "test"}, "correctResponsesPattern": ["test"], "scale": [], "description": {"en-US": "test"}, "choices": [], "source": [], "steps": [], "moreInfo": "test", "extensions": {"test": "test"}, "interactionType": "choice", "target": [], "type": "test", })
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_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_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_InitAll(self): adef = ActivityDefinition({ 'name': {'en-US': 'test'}, 'description': {'en-US': 'test'}, 'type': 'test', 'more_info': 'test', 'interaction_type': 'choice', 'correct_responses_pattern': ['test'], 'choices': InteractionComponentList(), 'scale': InteractionComponentList(), 'source': InteractionComponentList(), 'target': InteractionComponentList(), 'steps': InteractionComponentList(), 'extensions': {'test': 'test'} }) self.definitionVerificationHelper(adef)
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_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_ToJSON(self): iclist = InteractionComponentList([{ "id": "test1", "description": { "en-US": "test1" } }, { "id": "test2", "description": { "en-US": "test2" } }]) # since the map is unordered, it is ok that to_json() changes ordering self.assertEqual( json.loads(iclist.to_json()), json.loads('[{"id": "test1", "description": {"en-US": "test1"}}, ' '{"id": "test2", "description": {"en-US": "test2"}}]'))
def test_Init(self): iclist = InteractionComponentList([{ "id": "test1", "description": { "en-US": "test1" } }, { "id": "test2", "description": { "en-US": "test2" } }]) self.listVerificationHelper(iclist)
def test_appendItemCoercion(self): iclist = InteractionComponentList() iclist.append({"id": "test1", "description": {"en-US": "test1"}}) iclist.append({"id": "test2", "description": {"en-US": "test2"}}) self.listVerificationHelper(iclist)
def test_appendItemException(self): iclist = InteractionComponentList() with self.assertRaises(TypeError): iclist.append('not InteractionComponent') self.assertEqual(iclist, [])
def test_ToJSONFromJSON(self): json_str = '[{"id": "test1", "description": {"en-US": "test1"}}, ' \ '{"id": "test2", "description": {"en-US": "test2"}}]' iclist = InteractionComponentList.from_json(json_str) self.listVerificationHelper(iclist) self.assertEqual(json.loads(iclist.to_json()), json.loads(json_str))
def test_extendExceptionNotComponent(self): ic1 = InteractionComponent(id='test1') arglist = [ic1, 'not InteractionComponent'] iclist = InteractionComponentList([InteractionComponent()]) with self.assertRaises(TypeError): iclist.extend(arglist)
def test_FromJSONEmptyList(self): iclist = InteractionComponentList.from_json('[]') self.assertIsInstance(iclist, InteractionComponentList) self.assertEqual(iclist, [])
def test_insertExceptionNotComponent(self): ic1 = InteractionComponent(id='test1') ic2 = InteractionComponent(id='test3') iclist = InteractionComponentList([ic1, ic2]) with self.assertRaises(TypeError): iclist.insert(1, 'not InteractionComponent')
def test_FromJSONExceptionBadJSON(self): with self.assertRaises(ValueError): iclist = InteractionComponentList.from_json('{"bad JSON"}')
def test_AsVersionEmpty(self): iclist = InteractionComponentList() check = iclist.as_version() self.assertEqual(check, [])
def test_InitInteractionComponentList(self): ic1 = InteractionComponent(id='test1', description={"en-US": "test1"}) ic2 = InteractionComponent(id='test2', description={"en-US": "test2"}) arg = InteractionComponentList([ic1, ic2]) iclist = InteractionComponentList(arg) self.listVerificationHelper(iclist)
def test_InitEmpty(self): iclist = InteractionComponentList([]) self.assertEqual(iclist, []) self.assertIsInstance(iclist, InteractionComponentList)
def test_FromJSON(self): iclist = InteractionComponentList.from_json( '[{"id": "test1", "description": {"en-US": "test1"}}, {"id": "test2", "description": {"en-US": "test2"}}]' ) self.listVerificationHelper(iclist)
def test_InitExceptionNotInteractionComponent(self): with self.assertRaises(TypeError): InteractionComponentList( [InteractionComponent(), 'not InteractionComponent'])
def test_FromJSONExceptionNestedObject(self): with self.assertRaises(TypeError): iclist = InteractionComponentList.from_json( '[{"id": "test1", "description": {"en-US": "test1"}}, [{"id": "nested!"}]]' )
def test_FromJSONExceptionBadJSON(self): with self.assertRaises(ValueError): InteractionComponentList.from_json('{"bad JSON"}')
def test_ToJSONFromJSON(self): json_str = '[{"id": "test1", "description": {"en-US": "test1"}}, {"id": "test2", "description": {"en-US": "test2"}}]' iclist = InteractionComponentList.from_json(json_str) self.listVerificationHelper(iclist) self.assertEqual(iclist.to_json(), json_str)
def test_FromJSONExceptionNestedObject(self): with self.assertRaises(TypeError): InteractionComponentList.from_json( '[{"id": "test1", "description": {"en-US": "test1"}}, [{"id": "nested!"}]]' )