def test_update_name(self):
        expected = self.read_file(
            os.path.join(self.data_dir, "update_mediaobject_name.txt"))

        created_update = mediaobject.mutation_update_media_object(
            '2eeca6dd-c62c-490e-beb0-2e3899fca74f', name="Rossinyol")
        self.assert_queries_equal(created_update, expected)
 def test_invalid_language(self):
     with pytest.raises(UnsupportedLanguageException):
         mediaobject.mutation_update_media_object(
             '2eeca6dd-c62c-490e-beb0-2e3899fca74f', language="ja")
     with pytest.raises(UnsupportedLanguageException):
         mediaobject.mutation_create_media_object(
             title="Rossinyol",
             description="Traditional choir piece",
             date="1972",
             creator="trompamusic.eu",
             contributor="www.upf.edu",
             format_="text/html",
             encodingformat="text/html",
             source="https://www.cpdl.org/wiki/index.php/Rossinyol",
             contenturl="https://www.cpdl.org/wiki/index.php/Rossinyol",
             language="ja",
             inlanguage="ca")
async def import_tracks(key: str):
    """
    Imports audio fragments from Muziekweb for the key into the Trompa CE.
    """
    print(f"Retrieving release info with key {key} from Muziekweb")
    # Get data from Muziekweb
    tracks = get_mw_audio(key)

    if tracks is None:
        print(f"No track data received for {key}")
        return

    # Loop the tracks on the release to add all references to the 30 seconds music fragment
    for track in tracks:

        track.identifier = await lookupIdentifier("AudioObject", track.source)

        if track.identifier is not None:
            print(f"Updating record {track.identifier} in Trompa CE", end="")
            response = await ce.connection.submit_query(
                mutation_update_media_object(identifier=track.identifier,
                                             title=track.name,
                                             description=track.description,
                                             date=date.today(),
                                             creator=track.creator,
                                             contributor=track.contributor,
                                             format_=track.format,
                                             encodingFormat=track.format,
                                             source=track.source,
                                             subject=track.name,
                                             contentUrl=track.contentUrl,
                                             language=track.language))
            track.identifier = response["data"]["UpdatePerson"]["identifier"]
        else:
            print("Inserting new record in Trompa CE", end="")
            response = await ce.connection.submit_query(
                mutation_create_media_object(name=track.name,
                                             title=track.name,
                                             description=track.description,
                                             date=date.today(),
                                             creator=track.creator,
                                             contributor=track.contributor,
                                             format_=track.format,
                                             encodingFormat=track.format,
                                             source=track.source,
                                             subject=track.name,
                                             contentUrl=track.contentUrl,
                                             language=track.language))
            track.identifier = response["data"]["CreatePerson"]["identifier"]

    print(f"Importing tracks for {key} done.")
 def test_invalid_format(self):
     with pytest.raises(NotAMimeTypeException):
         mediaobject.mutation_update_media_object(
             '2eeca6dd-c62c-490e-beb0-2e3899fca74f', format_="test,html")
     with pytest.raises(NotAMimeTypeException):
         mediaobject.mutation_update_media_object(
             '2eeca6dd-c62c-490e-beb0-2e3899fca74f',
             encodingformat="test,html")
     with pytest.raises(NotAMimeTypeException):
         mediaobject.mutation_update_media_object('2eeca6dd-c62c-490e-beb0-2e3899fca74f', name="Rossinyol", description="Traditional choir piece", \
                                                  date="1972", creator="trompamusic.eu", contributor="www.upf.edu", format_="text,html", encodingformat="text/html", \
                                                  source="https://www.cpdl.org/wiki/index.php/Rossinyol", subject="Catalan choir piece", contenturl="https://www.cpdl.org/wiki/index.php/Rossinyol", \
                                                  language="en", inlanguage="ca")
     with pytest.raises(NotAMimeTypeException):
         mediaobject.mutation_update_media_object('2eeca6dd-c62c-490e-beb0-2e3899fca74f', name="Rossinyol", description="Traditional choir piece", \
                                                  date="1972", creator="trompamusic.eu", contributor="www.upf.edu", format_="text/html", encodingformat="text,html", \
                                                  source="https://www.cpdl.org/wiki/index.php/Rossinyol", subject="Catalan choir piece", contenturl="https://www.cpdl.org/wiki/index.php/Rossinyol", language="en", \
                                                  inlanguage="ca")
    def test_update_all(self):
        expected = self.read_file(
            os.path.join(self.data_dir, "update_mediaobject_all.txt"))

        created_update = mediaobject.mutation_update_media_object(
            '2eeca6dd-c62c-490e-beb0-2e3899fca74f',
            name="Rossinyol",
            description="Traditional choir piece",
            date="1972",
            creator="trompamusic.eu",
            contributor="www.upf.edu",
            format_="text/html",
            encodingformat="text/html",
            source="https://www.cpdl.org/wiki/index.php/Rossinyol",
            contenturl="https://www.cpdl.org/wiki/index.php/Rossinyol",
            language="en")
        self.assert_queries_equal(created_update, expected)
def update_mei_node(mei_id, meiurl):
    filename = os.path.basename(meiurl)
    """Given an MEI MediaObject node id, update it to add the URL """
    imslp_mei = mediaobject.mutation_update_media_object(
        identifier=mei_id,
        # URL on the web that matches contentUrl
        source=meiurl,
        # The <title> of `source`
        title=filename,
        # The mimetype of `source`
        format_="application/mei+xml",
        name=filename,
        # The page that describes the resource
        url=meiurl,
        contenturl=meiurl,
        encodingformat="application/mei+xml")
    mei_response = submit_query(imslp_mei, auth_required=True)
    mei = mei_response.get('data', {}).get('UpdateMediaObject', {})
    if mei:
        return mei["identifier"]
    else:
        return None