def test_datastream_list(self):
     datastreams = Fedora.get_datastream_list('changeme:9')
     assert len(datastreams) == 5
     assert datastreams == ['DC', 'annotation', 'RELS-EXT', 'specifictarget', 'selector']
    def serialize(cls, pids, format=None, check_object=None):
        """
        Get list of datastreams from an array of PIDs

        With those, get all rdf:Description elements and output
        in the format specified.

        Format options are:
            - rdf/xml or xml (default)
            - rdf/json or json
            - turtle or ttl
            - nt
            - n3

        Optional "check_object" parameter will check the object's
        content model before serializing to make sure it is equal to the
        default content type for annotate objects set in the config.
        """
        if format is None:
            format = "xml"

        if check_object is None:
            check_object = True

        xmls = []

        for pid in pids:

            # Make sure we only serialize Annotation objects
            if check_object:
                try:
                    content_models = Fedora.get_content_models(pid)
                except:
                    raise AnnotationError("PID %s not found in Fedora" % pid)

                oac_model = "info:fedora/%s" % app.config.get("DEFUALT_ANNOTATION_CONTENT_MODEL")
                if oac_model not in content_models:
                    continue

            datastreams = Fedora.get_datastream_list(pid)
            if not isinstance(datastreams, list):
                # There was an error with this PID, skip it
                continue
            for d in datastreams:
                [xmls.append(x) for x in Foxml.get_rdf_descriptions(Fedora.get_datastream(pid, d))]

        rdf_xml_string = Foxml.get_rdf_string_from_descriptions(list(xmls))

        out = Graph()
        out.parse(data=rdf_xml_string, format="application/rdf+xml")

        if format.lower() == "rdf/xml" or format.lower() == "xml":
            return out.serialize(format="xml"), "application/rdf+xml"
        if format.lower() == "n3":
            return out.serialize(format="n3"), "text/rdf+n3"
        elif format.lower() == "turtle" or format.lower() == "ttl":
            return out.serialize(format="turtle"), "text/turtle"
        elif format.lower() == "nt":
            return out.serialize(format="nt"), "text/nt"
        elif format.lower() == "rdf/json" or format.lower() == "json":
            return out.serialize(format="rdf-json"), "application/rdf+json"
        else:
            raise AnnotationError("Serialization format '%s' is not supported.")