def test_load_from_zipfile_filename_not_found(self): strm = BytesIO() zipf = zipfile.ZipFile(strm, 'w') zipf.writestr('foo.foo', '') zipf.close() colls = [get_root_collection(IMyEntity)] load_into_collections_from_zipfile(colls, strm) self.assert_equal(len(colls[0]), 0)
def test_load_from_zipfile_filename_not_found(self): strm = BytesIO() zipf = zipfile.ZipFile(strm, 'w') zipf.writestr('foo.foo', '') zipf.close() colls = [get_root_collection(IMyEntity)] load_into_collections_from_zipfile(colls, strm) self.assert_equal(len(colls[0]), 0)
def test_load_from_zipfile_invalid_extension(self): strm = BytesIO() zipf = zipfile.ZipFile(strm, 'w') coll_name = get_collection_name(get_collection_class(IMyEntity)) zipf.writestr('%s.foo' % coll_name, '') zipf.close() colls = [get_root_collection(IMyEntity)] with self.assert_raises(ValueError) as cm: load_into_collections_from_zipfile(colls, strm) exc_msg = 'Could not infer MIME type' self.assert_true(str(cm.exception).startswith(exc_msg))
def test_load_from_zipfile_invalid_extension(self): strm = BytesIO() zipf = zipfile.ZipFile(strm, 'w') coll_name = get_collection_name(get_collection_class(IMyEntity)) zipf.writestr('%s.foo' % coll_name, '') zipf.close() colls = [get_root_collection(IMyEntity)] with self.assert_raises(ValueError) as cm: load_into_collections_from_zipfile(colls, strm) exc_msg = 'Could not infer MIME type' self.assert_true(str(cm.exception).startswith(exc_msg))
def test_load_from_zipfile(self): member = _make_test_entity_member() strm = BytesIO() dump_resource_to_zipfile(member, strm) colls = [ get_root_collection(IMyEntityParent), get_root_collection(IMyEntity), get_root_collection(IMyEntityChild), get_root_collection(IMyEntityGrandchild), ] self.assert_equal(len(colls[0]), 0) self.assert_equal(len(colls[1]), 0) self.assert_equal(len(colls[2]), 0) self.assert_equal(len(colls[3]), 0) load_into_collections_from_zipfile(colls, strm) self.assert_equal(len(colls[0]), 1) self.assert_equal(len(colls[1]), 1) self.assert_equal(len(colls[2]), 1) self.assert_equal(len(colls[3]), 1)
def test_load_from_zipfile(self): member = _make_test_entity_member() strm = BytesIO() dump_resource_to_zipfile(member, strm) colls = [ get_root_collection(IMyEntityParent), get_root_collection(IMyEntity), get_root_collection(IMyEntityChild), get_root_collection(IMyEntityGrandchild), ] self.assert_equal(len(colls[0]), 0) self.assert_equal(len(colls[1]), 0) self.assert_equal(len(colls[2]), 0) self.assert_equal(len(colls[3]), 0) load_into_collections_from_zipfile(colls, strm) self.assert_equal(len(colls[0]), 1) self.assert_equal(len(colls[1]), 1) self.assert_equal(len(colls[2]), 1) self.assert_equal(len(colls[3]), 1)