def test_example1(self): doc = imscp.ManifestDocument() doc.read(src=io.BytesIO(EXAMPLE_1)) root = doc.root self.assertTrue(isinstance(root, imscp.Manifest)) self.assertTrue(root.ns == imscp.IMSCP_NAMESPACE and root.xmlname == 'manifest') self.assertTrue(root.id == 'test')
def test_delete_file(self): doc = imscp.ManifestDocument() doc.read(src=io.BytesIO(EXAMPLE_2)) r = doc.get_element_by_id('choice') index = len(r.File) f = r.File[0] f1 = r.File[1] r.DeleteFile(f) self.assertTrue(len(r.File) == index - 1 and r.File[0] is f1)
def test_new_file(self): doc = imscp.ManifestDocument() doc.read(src=io.BytesIO(EXAMPLE_2)) r = doc.get_element_by_id('choice') index = len(r.File) f = r.add_child(r.FileClass) f.set_attribute('href', 'Extra.txt') self.assertTrue(isinstance(f, imscp.File)) self.assertTrue(len(r.File) == index + 1 and r.File[index] is f)
def test_set_i_d(self): doc = imscp.ManifestDocument() doc.read(src=io.BytesIO(EXAMPLE_1)) manifest = doc.get_element_by_id("test") self.assertTrue(doc.root is manifest) manifest.set_id("manifest") self.assertTrue(doc.get_element_by_id("test") is None, "Old identifier still declared") self.assertTrue(doc.get_element_by_id("manifest") is manifest, "New identifier not declared")
def test_example2(self): doc = imscp.ManifestDocument() doc.read(src=io.BytesIO(EXAMPLE_2)) resources = doc.root.Resources self.assertTrue(len(resources.Resource) == 1 and isinstance(resources.Resource[0], imscp.Resource)) manifest = doc.get_element_by_id("MANIFEST-QTI-1") self.assertTrue(doc.root is manifest and isinstance(manifest, imscp.Manifest)) resource = doc.get_element_by_id("choice") self.assertTrue(resource is resources.Resource[0])
def test_new_resource(self): doc = imscp.ManifestDocument(root=imscp.Manifest) resources = doc.root.Resources try: resource = resources.add_child(resources.ResourceClass) resource.set_id('resource#1') resource.type = 'imsqti_item_xmlv2p1' self.fail("Invalid Name for resource identifier") except xml.XMLIDValueError: pass resource.set_id('resource_1') resource.type = 'imsqti_item_xmlv2p1' self.assertTrue(isinstance(resource, imscp.Resource)) self.assertTrue(doc.get_element_by_id('resource_1') is resource) self.assertTrue(len(resources.Resource) == 1 and resources.Resource[0] is resource)
def testCaseExample1(self): doc = imscp.ManifestDocument() doc.read(src=StringIO(EXAMPLE_1)) r = doc.get_element_by_id('choice') self.assertTrue(isinstance(list(r.Metadata.get_children())[0], LOM), "LOM")
def test_constructor(self): doc = imscp.ManifestDocument() self.assertTrue(isinstance(doc, xmlns.XMLNSDocument)) doc = imscp.ManifestDocument(root=imscp.Manifest) root = doc.root self.assertTrue(isinstance(root, imscp.Manifest))
def testCaseExample1(self): doc = imscp.ManifestDocument() doc.Read(src=StringIO(EXAMPLE_1)) r = doc.GetElementByID('choice') self.assertTrue(isinstance(list(r.Metadata.GetChildren())[0], LOM), "LOM")