def test_constructor(self): fileobject = 'Bender' fo = filemanager.FileObject('futurama/bender', fileobject, 'text/xml') self.assertEqual(fo.element, fileobject) self.assertEqual(fo.media_type, 'text/xml') self.assertEqual(fo.filename, 'futurama/bender') self.assertTrue(fo.zipinfo)
def test_serialisation_element(self): class Element: def tobytes(self): return b'Element' element = Element() fo = filemanager.FileObject('test/element', element, '') self.assertEqual(b'Element', fo.tobytes())
def test_serialisation_xmlelement(self): class XMLElement: def tobytes(self, xml_declaration): return b'XMLElement' element = XMLElement() fo = filemanager.FileObject('test/xml/element', element, 'text/xml') self.assertEqual(b'XMLElement', fo.tobytes())
def test_serialisation_error(self): fo = filemanager.FileObject('futurama/bender', 1000, 'text/xml') with self.assertRaises(TypeError): fo.tobytes()
def test_serialisation_bytes(self): fo = filemanager.FileObject('futurama/bender', b'Bender') self.assertEqual(b'Bender', fo.tobytes())
def test_serialisation_string(self): fo = filemanager.FileObject('futurama/bender', 'Bender', 'text/xml') self.assertEqual(b'Bender', fo.tobytes())