def test_non_200(HttpMock): api_key = get_random_md5() content = '<xml><this xml is malformed</xml>' http = build_http_mock(HttpMock, response_status=400, content=content) client = harvestmedia.api.client.Client(api_key=api_key, debug_level='DEBUG') client.get_service_info()
def test_album_tracks(HttpMock): client = init_client() album_id = '1c5f47572d9152f3' album_xml = ET.fromstring( textwrap.dedent( """<album featured="false" code="HM001" detail="Razor-sharp pop& rock bristling with spiky guitars & infectious, feelgood inspiration … and tons of attitude." name="HM 001 Sample Album" displaytitle="HM 001 Sample Album " id="%s"/> """ % (album_id))) return_values = [ (200, """<responsetracks> <tracks> <track tracknumber="1" time="02:50" lengthseconds="170" comment="Make sure you’re down the front for this fiery Post Punk workout." composer=""S. Milton, J. Wygens"" publisher="" name="Guerilla Pop" albumid="%(album_id)s" id="17376d36f309f18d" keywords="" displaytitle="Guerilla Pop" genre="Pop / Rock" tempo="" instrumentation="" bpm="" mixout="" frequency="44100" bitrate="1411" dateingested="2008-05-15 06:08:18"/> <track tracknumber="2" time="02:46" lengthseconds="166" comment="Poignant electric guitars. Brooding acoustic strums." composer=""S. Milton, J. Wygens"" publisher="" name="Hat And Feather" albumid="%(album_id)s" id="635f90a4db673855" keywords="" displaytitle="Hat And Feather" genre="Pop / Rock" tempo="" instrumentation="" bpm="" mixout="" frequency="44100" bitrate="1411" dateingested="2008-05-15 06:08:18"/> </tracks> </responsetracks>""" % locals()), ] http = build_http_mock(HttpMock, responses=return_values) album = Album._from_xml(album_xml, client) tracks = album.get_tracks(get_full_detail=False) assert tracks[0].albumid == album_id
def test_get_library_albums(HttpMock): client = init_client() test_album_id = get_random_md5() return_values = [ (200, """<ResponseLibraries> <libraries> <library id="abc123" name="VIDEOHELPER" detail="Library description" /> <library id="abc125" name="MODULES" detail="Library description" /> </libraries> </ResponseLibraries>"""), (200, """<responsealbums> <albums> <album libraryid="abc123" featured="false" code="HM001" detail="Razor-sharp pop& rock bristling with spiky guitars & infectious, feelgood inspiration … and tons of attitude." name="HM 001 Sample Album" displaytitle="HM 001 Sample Album " id="%(test_album_id)s"/> <album libraryid="19b8f5935503adde" featured="false" code="HM002" detail=" Contemporary beats fused with orchestral elements." name="HM 002 Sample Album " displaytitle="HM 002 Sample Album " id="67a6aed83a741a06"/> </albums> </responsealbums>""" % {'test_album_id': test_album_id}), ] http = build_http_mock(HttpMock, responses=return_values) libraries = Library.query.get_libraries(client) assert isinstance(libraries, list) library = libraries[0] albums = library.get_albums() assert isinstance(albums, list) assert albums[0].id == test_album_id
def test_register_no_client(HttpMock): client = init_client() test_member_id = get_random_md5() username = '******' first_name = 'Test' last_name = 'User' email = '*****@*****.**' xml_response = """<?xml version="1.0" encoding="utf-8"?> <ResponseMember> <memberaccount id="%(test_member_id)s"> <username>%(username)s</username> <first_name>%(first_name)s</first_name> <last_name>%(last_name)s</last_name> <email>%(email)s</email> </memberaccount> </ResponseMember>""" % {'test_member_id': test_member_id, 'username': username, 'first_name': first_name, 'last_name': last_name, 'email': email} username = username first_name = first_name last_name = last_name email = email termsaccept = 'true' fileformat = 'MP3' http = build_http_mock(HttpMock, content=xml_response) member = Member.register(username=username, first_name=first_name, last_name=last_name, email=email, termsaccept=termsaccept, fileformat=fileformat)
def test_remove_track(HttpMock): client = init_client() test_member_id = get_random_md5() username = '******' firstname = 'Test' lastname = 'User' email = '*****@*****.**' xml_str = """<memberaccount id="%(test_member_id)s"> <username>%(username)s</username> <firstname>%(firstname)s</firstname> <lastname>%(lastname)s</lastname> <email>%(email)s</email> </memberaccount>""" % \ {'test_member_id': test_member_id, 'username': username, 'firstname': firstname, 'lastname': lastname, 'email': email} member_xml = ET.fromstring(xml_str) member = Member._from_xml(member_xml, client) xml_response = """<?xml version="1.0" encoding="utf-8"?> <responsecode xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <code>OK</code> </responsecode>""" http = build_http_mock(HttpMock, content=xml_response) test_track_id = get_random_md5() member.remove_favourite(test_track_id)
def test_xml_failure(HttpMock): api_key = get_random_md5() content = '<xml><this xml is malformed</xml>' http = build_http_mock(HttpMock, content=content) client = harvestmedia.api.client.Client(api_key=api_key, debug_level='DEBUG') client.get_service_info()
def test_album_notracks(HttpMock): client = init_client() album_id = '1c5f47572d9152f3' album_xml = ET.fromstring( textwrap.dedent( """<album featured="false" code="HM001" detail="Razor-sharp pop& rock bristling with spiky guitars & infectious, feelgood inspiration … and tons of attitude." name="HM 001 Sample Album" displaytitle="HM 001 Sample Album " id="%s"/> """ % (album_id))) return_values = [ ( 200, """<responsetracks> <tracks> </tracks> </responsetracks>""" % locals(), ), ] http = build_http_mock(HttpMock, responses=return_values) album = Album._from_xml(album_xml, client) tracks = album.get_tracks(get_full_detail=False) assert len(tracks) == 0
def test_remove(HttpMock): client = init_client() test_member_id = get_random_md5() test_playlist_id = get_random_md5() test_playlist_name = 'test playlist' test_track_id = get_random_md5() return_values = [ (200, """<?xml version="1.0" encoding="utf-8"?> <ResponsePlaylists> <playlists> <playlist id="%(test_playlist_id)s" name="%(test_playlist_name)s"> <tracks> <track tracknumber="001" time="02:50" lengthseconds="170" comment="Make sure you’re down the front for this fiery Post Punk workout." composer=""S. Milton, J. Wygens"" publisher="HM" name="Guerilla Pop" id="%(test_track_id)s" keywords="" lyrics="" displaytitle="Guerilla Pop" genre="Pop / Rock" tempo="" instrumentation="" bpm="" mixout="" frequency="44100" bitrate="1411" /> </tracks> </playlist> </playlists> </ResponsePlaylists>""" % locals()), (200, """<?xml version="1.0" encoding="utf-8"?> <responsecode xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <code>OK</code> </responsecode>""",), ] http = build_http_mock(HttpMock, responses=return_values) member = Member(_client=client) member.id = test_member_id playlists = member.get_playlists() playlists[0].remove()
def test_album_tracks(HttpMock): client = init_client() album_id = '1c5f47572d9152f3' album_xml = ET.fromstring(textwrap.dedent("""<album featured="false" code="HM001" detail="Razor-sharp pop& rock bristling with spiky guitars & infectious, feelgood inspiration … and tons of attitude." name="HM 001 Sample Album" displaytitle="HM 001 Sample Album " id="%s"/> """ % (album_id))) return_values = [ (200, """<responsetracks> <tracks> <track tracknumber="1" time="02:50" lengthseconds="170" comment="Make sure you’re down the front for this fiery Post Punk workout." composer=""S. Milton, J. Wygens"" publisher="" name="Guerilla Pop" albumid="%(album_id)s" id="17376d36f309f18d" keywords="" displaytitle="Guerilla Pop" genre="Pop / Rock" tempo="" instrumentation="" bpm="" mixout="" frequency="44100" bitrate="1411" dateingested="2008-05-15 06:08:18"/> <track tracknumber="2" time="02:46" lengthseconds="166" comment="Poignant electric guitars. Brooding acoustic strums." composer=""S. Milton, J. Wygens"" publisher="" name="Hat And Feather" albumid="%(album_id)s" id="635f90a4db673855" keywords="" displaytitle="Hat And Feather" genre="Pop / Rock" tempo="" instrumentation="" bpm="" mixout="" frequency="44100" bitrate="1411" dateingested="2008-05-15 06:08:18"/> </tracks> </responsetracks>""" % locals()), ] http = build_http_mock(HttpMock, responses=return_values) album = Album._from_xml(album_xml, client) tracks = album.get_tracks(get_full_detail=False) assert tracks[0].albumid == album_id
def test_incorrect_input_data_missing_description(HttpMock): api_key = get_random_md5() content = """<?xml version="1.0" encoding="utf-8"?> <memberaccount> <error> <code>2</code> </error> </memberaccount>""" http = build_http_mock(HttpMock, content=content) client = harvestmedia.api.client.Client(api_key=api_key) libraries = Library.get_libraries(client)
def test_send_password(HttpMock): client = init_client() test_username = '******' content = """<?xml version="1.0" encoding="utf-8"?> <responsecode xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <code>OK</code> </responsecode>""" http = build_http_mock(HttpMock, content=content) Member.send_password(test_username, client)
def test_get_categories(HttpMock): client = init_client() cwd = os.path.dirname(__file__) categories_xml = ET.parse(os.path.join(cwd, 'categories.xml')) http = build_http_mock(HttpMock, content=ET.tostring(categories_xml.getroot())) categories = Category.query.get_categories(client) categories_in_xml = len(categories_xml.getroot().find('categories').findall('category')) client_categories = len(categories) assert categories_in_xml == client_categories, 'Category counts do not match %s != %s' % \ (categories_in_xml, client_categories)
def test_invalid_token(HttpMock): api_key = get_random_md5() content = """<?xml version="1.0" encoding="utf-8"?> <memberaccount> <error> <code>5</code> <description>Invalid Token</description> </error> </memberaccount>""" http = build_http_mock(HttpMock, content=content) client = harvestmedia.api.client.Client(api_key=api_key) libraries = Library.get_libraries(client)
def test_member_invalid(HttpMock): client = init_client() test_member_id = get_random_md5() content = """<?xml version="1.0" encoding="utf-8"?> <responsemember> <error> <code>7</code> <description>Member Does Not Exist</description> </error> </responsemember>""" http = build_http_mock(HttpMock, content=content) member = Member.query.get_by_id(test_member_id, client)
def test_get_member_playlists(HttpMock): client = init_client() test_member_id = get_random_md5() username = '******' firstname = 'Test' lastname = 'User' email = '*****@*****.**' member_xml = ET.fromstring("""<memberaccount id="%(test_member_id)s"> <username>%(username)s</username> <firstname>%(firstname)s</firstname> <lastname>%(lastname)s</lastname> <email>%(email)s</email> </memberaccount>""" % {'test_member_id': test_member_id, 'username': username, 'firstname': firstname, 'lastname': lastname, 'email': email}) member = Member._from_xml(member_xml, client) test_playlist_id = get_random_md5() test_playlist_name = 'test playlist' content = """<?xml version="1.0" encoding="utf-8"?> <ResponsePlaylists> <playlists> <playlist id="%(id)s" name="%(name)s"> <tracks> <track tracknumber="001" time="02:50" lengthseconds="170" comment="Make sure you’re down the front for this fiery Post Punk workout." composer=""S. Milton, J. Wygens"" publisher="HM" name="Guerilla Pop" id="17376d36f309f18d" keywords="" lyrics="" displaytitle="Guerilla Pop" genre="Pop / Rock" tempo="" instrumentation="" bpm="" mixout="" frequency="44100" bitrate="1411" /> </tracks> </playlist> </playlists> </ResponsePlaylists>""" % {'id': test_playlist_id, 'name': test_playlist_name} http = build_http_mock(HttpMock, content=content) playlists = member.get_playlists() assert isinstance(playlists, list) playlist = playlists[0] assert playlist.id == test_playlist_id assert playlist.name == test_playlist_name
def test_get_categories(HttpMock): client = init_client() cwd = os.path.dirname(__file__) categories_xml = ET.parse(os.path.join(cwd, 'categories.xml')) http = build_http_mock(HttpMock, content=ET.tostring(categories_xml.getroot())) categories = Category.query.get_categories(client) categories_in_xml = len( categories_xml.getroot().find('categories').findall('category')) client_categories = len(categories) assert categories_in_xml == client_categories, 'Category counts do not match %s != %s' % \ (categories_in_xml, client_categories)
def test_member_authenticate_fail(HttpMock): client = init_client() test_username = '******' test_password = get_random_md5() content = """<?xml version="1.0" encoding="utf-8"?> <responsemember> <error> <code>6</code> <description>Invalid Login Details</description> </error> </responsemember>""" http = build_http_mock(HttpMock, content=content) member = Member.authenticate(test_username, test_password, client)
def test_add_track(HttpMock): client = init_client() test_playlist_id = get_random_md5() track_id = get_random_md5() content = """<?xml version="1.0" encoding="utf-8"?> <responsecode xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <code>OK</code> </responsecode>""" http = build_http_mock(HttpMock, content=content) playlist = Playlist(_client=client) playlist.member_id = 123 playlist.id = test_playlist_id playlist.add_track(track_id)
def test_get_member_favourites(HttpMock): client = init_client() test_member_id = get_random_md5() username = '******' firstname = 'Test' lastname = 'User' email = '*****@*****.**' member_xml = ET.fromstring("""<memberaccount id="%(test_member_id)s"> <username>%(username)s</username> <firstname>%(firstname)s</firstname> <lastname>%(lastname)s</lastname> <email>%(email)s</email> </memberaccount>""" % \ {'test_member_id': test_member_id, 'username': username, 'firstname': firstname, 'lastname': lastname, 'email': email}) member = Member._from_xml(member_xml, client) test_track_id = get_random_md5() test_track_name = 'test track' xml_response = """<?xml version="1.0" encoding="utf-8"?> <ResponseFavourites> <favourites> <tracks> <track id="%(id)s" name="%(name)s" /> </tracks> </favourites> </ResponseFavourites>""" % { 'id': test_track_id, 'name': test_track_name } http = build_http_mock(HttpMock, content=xml_response) favourites = member.get_favourites() assert isinstance(favourites, list) favourite = favourites[0] assert favourite.id == test_track_id assert favourite.name == test_track_name
def test_get_cover_url(HttpMock): client = init_client() album_id = '1c5f47572d9152f3' album_xml = ET.fromstring( textwrap.dedent( """<album featured="false" code="HM001" detail="Razor-sharp pop& rock bristling with spiky guitars & infectious, feelgood inspiration … and tons of attitude." name="HM 001 Sample Album" displaytitle="HM 001 Sample Album " id="%s"/> """ % (album_id))) album_art_url = "http://asset.harvestmedia.net/albumart/8185d768cd8fcaa7/{id}/{width}/{height}" expiry = datetime.datetime.now() test_token = get_random_md5() return_values = [ (200, """<?xml version="1.0" encoding="utf-8"?> <responseservicetoken> <token value="%s" expiry="%s"/> </responseservicetoken>""" % \ (test_token, expiry.strftime("%Y-%m-%dT%H:%M:%S"))), (200, """<?xml version="1.0" encoding="utf-8"?> <responseserviceinfo> <asseturl albumart="%(album_art_url)s" waveform="http://asset.harvestmedia.net/waveform/8185d768cd8fcaa7/{id}/{width}/{height}" trackstream="http://asset.harvestmedia.net/trackstream/8185d768cd8fcaa7/{id}" trackdownload=" http://asset.harvestmedia.net/trackdownload/8185d768cd8fcaa7/{id}/{trackformat}" /> <trackformats> <trackformat identifier="8185d768cd8fcaa7" extension="mp3" bitrate="320" samplerate="48" samplesize="16" /> <trackformat identifier="768cd8fcaa8185d7" extension="wav" bitrate="1536" samplerate="48" samplesize="16" /> <trackformat identifier="7jsi8fcaa818df57" extension="aif" bitrate="1536" samplerate="48" samplesize="16" /> </trackformats> </responseserviceinfo>""" % locals()), ] http = build_http_mock(HttpMock, responses=return_values) width = 200 height = 300 album = Album._from_xml(album_xml, client) cover_art_url = album.get_cover_url(width, height) expected_url = album_art_url.replace('{id}', album_id).replace( '{width}', str(width)).replace('{height}', str(height)) assert cover_art_url == expected_url
def test_get_member_favourites(HttpMock): client = init_client() test_member_id = get_random_md5() username = '******' firstname = 'Test' lastname = 'User' email = '*****@*****.**' member_xml = ET.fromstring("""<memberaccount id="%(test_member_id)s"> <username>%(username)s</username> <firstname>%(firstname)s</firstname> <lastname>%(lastname)s</lastname> <email>%(email)s</email> </memberaccount>""" % \ {'test_member_id': test_member_id, 'username': username, 'firstname': firstname, 'lastname': lastname, 'email': email}) member = Member._from_xml(member_xml, client) test_track_id = get_random_md5() test_track_name = 'test track' xml_response = """<?xml version="1.0" encoding="utf-8"?> <ResponseFavourites> <favourites> <tracks> <track id="%(id)s" name="%(name)s" /> </tracks> </favourites> </ResponseFavourites>""" % {'id': test_track_id, 'name': test_track_name} http = build_http_mock(HttpMock, content=xml_response) favourites = member.get_favourites() assert isinstance(favourites, list) favourite = favourites[0] assert favourite.id == test_track_id assert favourite.name == test_track_name
def test_get_service_token(HttpMock): api_key = get_random_md5() now = datetime.datetime.utcnow() expiry = now + datetime.timedelta( hours=16) # offset for HM timezone and lifetime (10 + 6) test_token = get_random_md5() return_values = [ (200, """<?xml version="1.0" encoding="utf-8"?> <responseservicetoken> <token value="%s" expiry="%s"/> </responseservicetoken>""" % \ (test_token, expiry.strftime("%Y-%m-%dT%H:%M:%S"))), (200, """<?xml version="1.0" encoding="utf-8"?> <responseserviceinfo> <asseturl albumart="http://asset.harvestmedia.net/albumart/8185d768cd8fcaa7/{id}/{width}/{height}" waveform="http://asset.harvestmedia.net/waveform/8185d768cd8fcaa7/{id}/{width}/{height}" trackstream="http://asset.harvestmedia.net/trackstream/8185d768cd8fcaa7/{id}" trackdownload=" http://asset.harvestmedia.net/trackdownload/8185d768cd8fcaa7/{id}/{trackformat}" /> <trackformats> <trackformat identifier="8185d768cd8fcaa7" extension="mp3" bitrate="320" samplerate="48" samplesize="16" /> <trackformat identifier="768cd8fcaa8185d7" extension="wav" bitrate="1536" samplerate="48" samplesize="16" /> <trackformat identifier="7jsi8fcaa818df57" extension="aif" bitrate="1536" samplerate="48" samplesize="16" /> </trackformats> </responseserviceinfo>"""), ] http = build_http_mock(HttpMock, responses=return_values) client = harvestmedia.api.client.Client(api_key=api_key, debug_level='DEBUG') # get the debug level to cover the getter client.debug_level assert client.config.service_token.token == test_token utc_expiration = now + datetime.timedelta(hours=6) # make TZ aware and remove ms utc_expiration = utc_expiration.replace(tzinfo=pytz.UTC, microsecond=0) assert client.config.service_token._expiry_dt.isoformat() == utc_expiration.isoformat(), 'token expiration %s != utc expiration %s' % \ (client.config.service_token._expiry_dt.isoformat(), utc_expiration.isoformat())
def test_album_notracks(HttpMock): client = init_client() album_id = '1c5f47572d9152f3' album_xml = ET.fromstring(textwrap.dedent("""<album featured="false" code="HM001" detail="Razor-sharp pop& rock bristling with spiky guitars & infectious, feelgood inspiration … and tons of attitude." name="HM 001 Sample Album" displaytitle="HM 001 Sample Album " id="%s"/> """ % (album_id))) return_values = [ (200, """<responsetracks> <tracks> </tracks> </responsetracks>""" % locals(),), ] http = build_http_mock(HttpMock, responses=return_values) album = Album._from_xml(album_xml, client) tracks = album.get_tracks(get_full_detail=False) assert len(tracks) == 0
def test_register_member(HttpMock): client = init_client() test_member_id = get_random_md5() username = '******' first_name = 'Test' last_name = 'User' email = '*****@*****.**' xml_response = """<?xml version="1.0" encoding="utf-8"?> <ResponseMember> <memberaccount id="%(test_member_id)s"> <username>%(username)s</username> <first_name>%(first_name)s</first_name> <last_name>%(last_name)s</last_name> <email>%(email)s</email> </memberaccount> </ResponseMember>""" % { 'test_member_id': test_member_id, 'username': username, 'first_name': first_name, 'last_name': last_name, 'email': email } username = username first_name = first_name last_name = last_name email = email termsaccept = 'true' fileformat = 'MP3' http = build_http_mock(HttpMock, content=xml_response) member = Member.register(_client=client, username=username, firstname=first_name, lastname=last_name, email=email, termsaccept=termsaccept, fileformat=fileformat) assert member.id == test_member_id assert member.username == username
def test_get_playlist_art_url(HttpMock): client = init_client() playlist_id = '112358' playlist_xml = ET.fromstring(textwrap.dedent("""<playlist name="EFF!" id="%s" createddate="2012-04-17 06:24:45" trackcount="0" />""" % (playlist_id))) playlist_art_url = 'http://download.harvestmedia.net/wsplaylistart/8185d768cd8fcaa7/{id}/{width}/{height}' expiry = datetime.datetime.now() test_token = get_random_md5() return_values = [ (200, """<?xml version="1.0" encoding="utf-8"?> <responseservicetoken> <token value="%s" expiry="%s"/> </responseservicetoken>""" % \ (test_token, expiry.strftime("%Y-%m-%dT%H:%M:%S"))), (200, """<?xml version="1.0" encoding="utf-8"?> <responseserviceinfo> <asseturl waveform="http://asset.harvestmedia.net/waveform/8185d768cd8fcaa7/{id}/{width}/{height}" trackstream="http://asset.harvestmedia.net/trackstream/8185d768cd8fcaa7/{id}" trackdownload=" http://asset.harvestmedia.net/trackdownload/8185d768cd8fcaa7/{id}/{trackformat}" playlistart="%(playlist_art_url)s" /> <trackformats> <trackformat identifier="8185d768cd8fcaa7" extension="mp3" bitrate="320" samplerate="48" samplesize="16" /> <trackformat identifier="768cd8fcaa8185d7" extension="wav" bitrate="1536" samplerate="48" samplesize="16" /> <trackformat identifier="7jsi8fcaa818df57" extension="aif" bitrate="1536" samplerate="48" samplesize="16" /> </trackformats> </responseserviceinfo>""" % locals()), ] http = build_http_mock(HttpMock, responses=return_values) width = 200 height = 300 playlist = Playlist._from_xml(playlist_xml, client) cover_art_url = playlist.get_cover_url(width, height) expected_url = playlist_art_url.replace('{id}', playlist_id).replace('{width}', str(width)).replace('{height}', str(height)) assert cover_art_url == expected_url
def test_get_service_token(HttpMock): api_key = get_random_md5() now = datetime.datetime.utcnow() expiry = now + datetime.timedelta(hours=16) # offset for HM timezone and lifetime (10 + 6) test_token = get_random_md5() return_values = [ (200, """<?xml version="1.0" encoding="utf-8"?> <responseservicetoken> <token value="%s" expiry="%s"/> </responseservicetoken>""" % \ (test_token, expiry.strftime("%Y-%m-%dT%H:%M:%S"))), (200, """<?xml version="1.0" encoding="utf-8"?> <responseserviceinfo> <asseturl albumart="http://asset.harvestmedia.net/albumart/8185d768cd8fcaa7/{id}/{width}/{height}" waveform="http://asset.harvestmedia.net/waveform/8185d768cd8fcaa7/{id}/{width}/{height}" trackstream="http://asset.harvestmedia.net/trackstream/8185d768cd8fcaa7/{id}" trackdownload=" http://asset.harvestmedia.net/trackdownload/8185d768cd8fcaa7/{id}/{trackformat}" /> <trackformats> <trackformat identifier="8185d768cd8fcaa7" extension="mp3" bitrate="320" samplerate="48" samplesize="16" /> <trackformat identifier="768cd8fcaa8185d7" extension="wav" bitrate="1536" samplerate="48" samplesize="16" /> <trackformat identifier="7jsi8fcaa818df57" extension="aif" bitrate="1536" samplerate="48" samplesize="16" /> </trackformats> </responseserviceinfo>"""), ] http = build_http_mock(HttpMock, responses=return_values) client = harvestmedia.api.client.Client(api_key=api_key, debug_level='DEBUG') # get the debug level to cover the getter client.debug_level assert client.config.service_token.token == test_token utc_expiration = now + datetime.timedelta(hours=6) # make TZ aware and remove ms utc_expiration = utc_expiration.replace(tzinfo=pytz.UTC, microsecond=0) assert client.config.service_token._expiry_dt.isoformat() == utc_expiration.isoformat(), 'token expiration %s != utc expiration %s' % \ (client.config.service_token._expiry_dt.isoformat(), utc_expiration.isoformat())
def test_add_playlist(HttpMock): client = init_client() test_member_id = get_random_md5() test_playlist_id = get_random_md5() test_playlist_name = 'test playlist' content = """<?xml version="1.0" encoding="utf-8"?> <ResponsePlaylists> <playlists> <playlist id="%(id)s" name="%(name)s" /> </playlists> </ResponsePlaylists>""" % \ {'id': test_playlist_id, 'name': test_playlist_name} http = build_http_mock(HttpMock, content=content) playlist = Playlist.add(_client=client, member_id=test_member_id, playlist_name=test_playlist_name) assert playlist.id == test_playlist_id assert playlist.name == test_playlist_name
def test_get_libraries(HttpMock): client = init_client() return_values = [ (200, """<ResponseLibraries> <libraries> <library id="abc123" name="VIDEOHELPER" detail="Library description" /> <library id="abc125" name="MODULES" detail="Library description" /> </libraries> </ResponseLibraries>"""), ] http = build_http_mock(HttpMock, responses=return_values) libraries = Library.query.get_libraries(client) assert isinstance(libraries, list) library = libraries[0] assert library.id == 'abc123' assert library.name == 'VIDEOHELPER'
def test_get_cover_url(HttpMock): client = init_client() album_id = '1c5f47572d9152f3' album_xml = ET.fromstring(textwrap.dedent("""<album featured="false" code="HM001" detail="Razor-sharp pop& rock bristling with spiky guitars & infectious, feelgood inspiration … and tons of attitude." name="HM 001 Sample Album" displaytitle="HM 001 Sample Album " id="%s"/> """ % (album_id))) album_art_url = "http://asset.harvestmedia.net/albumart/8185d768cd8fcaa7/{id}/{width}/{height}" expiry = datetime.datetime.now() test_token = get_random_md5() return_values = [ (200, """<?xml version="1.0" encoding="utf-8"?> <responseservicetoken> <token value="%s" expiry="%s"/> </responseservicetoken>""" % \ (test_token, expiry.strftime("%Y-%m-%dT%H:%M:%S"))), (200, """<?xml version="1.0" encoding="utf-8"?> <responseserviceinfo> <asseturl albumart="%(album_art_url)s" waveform="http://asset.harvestmedia.net/waveform/8185d768cd8fcaa7/{id}/{width}/{height}" trackstream="http://asset.harvestmedia.net/trackstream/8185d768cd8fcaa7/{id}" trackdownload=" http://asset.harvestmedia.net/trackdownload/8185d768cd8fcaa7/{id}/{trackformat}" /> <trackformats> <trackformat identifier="8185d768cd8fcaa7" extension="mp3" bitrate="320" samplerate="48" samplesize="16" /> <trackformat identifier="768cd8fcaa8185d7" extension="wav" bitrate="1536" samplerate="48" samplesize="16" /> <trackformat identifier="7jsi8fcaa818df57" extension="aif" bitrate="1536" samplerate="48" samplesize="16" /> </trackformats> </responseserviceinfo>""" % locals()), ] http = build_http_mock(HttpMock, responses=return_values) width = 200 height = 300 album = Album._from_xml(album_xml, client) cover_art_url = album.get_cover_url(width, height) expected_url = album_art_url.replace('{id}', album_id).replace('{width}', str(width)).replace('{height}', str(height)) assert cover_art_url == expected_url
def test_member_authenticate(HttpMock): client = init_client() test_member_id = get_random_md5() test_username = '******' test_password = get_random_md5() test_firstname = 'first' test_lastname = 'last' test_email = '*****@*****.**' content = """<?xml version="1.0" encoding="utf-8"?> <ResponseMember> <memberaccount id="%(test_member_id)s"> <username>%(test_username)s</username> <firstname>%(test_firstname)s</firstname> <lastname>%(test_lastname)s</lastname> <email>%(test_email)s</email> </memberaccount> </ResponseMember>""" % locals() http = build_http_mock(HttpMock, content=content) member = Member.authenticate(test_username, test_password, client) assert member.id == test_member_id
def test_expired_token_refetch(HttpMock): api_key = get_random_md5() expiry = datetime.datetime.now() expiry2 = expiry + datetime.timedelta(hours=22) test_second_token = get_random_md5() return_values = [ (200, """<?xml version="1.0" encoding="utf-8"?> <responseservicetoken> <token value="%s" expiry="%s"/> </responseservicetoken>""" % \ (test_second_token, expiry2.strftime("%Y-%m-%dT%H:%M:%S"))), (200, """<?xml version="1.0" encoding="utf-8"?> <responseserviceinfo> <asseturl albumart="http://asset.harvestmedia.net/albumart/8185d768cd8fcaa7/{id}/{width}/{height}" waveform="http://asset.harvestmedia.net/waveform/8185d768cd8fcaa7/{id}/{width}/{height}" trackstream="http://asset.harvestmedia.net/trackstream/8185d768cd8fcaa7/{id}" trackdownload=" http://asset.harvestmedia.net/trackdownload/8185d768cd8fcaa7/{id}/{trackformat}" /> <trackformats> <trackformat identifier="8185d768cd8fcaa7" extension="mp3" bitrate="320" samplerate="48" samplesize="16" /> <trackformat identifier="768cd8fcaa8185d7" extension="wav" bitrate="1536" samplerate="48" samplesize="16" /> <trackformat identifier="7jsi8fcaa818df57" extension="aif" bitrate="1536" samplerate="48" samplesize="16" /> </trackformats> </responseserviceinfo>"""), ] client = init_client() # force-expire the token client.config.service_token.expiry = ( datetime.datetime.now() - datetime.timedelta(hours=12)).isoformat() http = build_http_mock(HttpMock, responses=return_values) # this should fetch a new token since the old one is expired client.get_service_info() # token should match the SECOND token assert client.config.service_token.token == test_second_token
def test_expired_token_refetch(HttpMock): api_key = get_random_md5() expiry = datetime.datetime.now() expiry2 = expiry + datetime.timedelta(hours=22) test_second_token = get_random_md5() return_values = [ (200, """<?xml version="1.0" encoding="utf-8"?> <responseservicetoken> <token value="%s" expiry="%s"/> </responseservicetoken>""" % \ (test_second_token, expiry2.strftime("%Y-%m-%dT%H:%M:%S"))), (200, """<?xml version="1.0" encoding="utf-8"?> <responseserviceinfo> <asseturl albumart="http://asset.harvestmedia.net/albumart/8185d768cd8fcaa7/{id}/{width}/{height}" waveform="http://asset.harvestmedia.net/waveform/8185d768cd8fcaa7/{id}/{width}/{height}" trackstream="http://asset.harvestmedia.net/trackstream/8185d768cd8fcaa7/{id}" trackdownload=" http://asset.harvestmedia.net/trackdownload/8185d768cd8fcaa7/{id}/{trackformat}" /> <trackformats> <trackformat identifier="8185d768cd8fcaa7" extension="mp3" bitrate="320" samplerate="48" samplesize="16" /> <trackformat identifier="768cd8fcaa8185d7" extension="wav" bitrate="1536" samplerate="48" samplesize="16" /> <trackformat identifier="7jsi8fcaa818df57" extension="aif" bitrate="1536" samplerate="48" samplesize="16" /> </trackformats> </responseserviceinfo>"""), ] client = init_client() # force-expire the token client.config.service_token.expiry = (datetime.datetime.now() - datetime.timedelta(hours=12)).isoformat() http = build_http_mock(HttpMock, responses=return_values) # this should fetch a new token since the old one is expired client.get_service_info() # token should match the SECOND token assert client.config.service_token.token == test_second_token
def test_invalid_remote_token(HttpMock): api_key = get_random_md5() expiry = datetime.datetime.now() expiry += datetime.timedelta(hours=22) # offset for HM timezone test_token = get_random_md5() return_values = [ (200, """<?xml version="1.0" encoding="utf-8"?> <responseservicetoken> <token value="%s" expiry="%s"/> </responseservicetoken>""" % \ (test_token, expiry.strftime("%Y-%m-%dT%H:%M:%S"))), (200, """<memberaccount> <error> <code>5</code> <description>Invalid Token</description> </error> </memberaccount>"""), ] http = build_http_mock(HttpMock, responses=return_values) client = harvestmedia.api.client.Client(api_key=api_key) libraries = Library.get_libraries(client)
def test_member_update(HttpMock): client = init_client() test_member_id = get_random_md5() test_username = '******' test_email = '*****@*****.**' test_firstname = 'test' test_lastname = 'user' test_username_update = 'new name' return_values = [ (200, """<?xml version="1.0" encoding="utf-8"?> <ResponseMember> <memberaccount id="%(test_member_id)s"> <username>%(test_username)s</username> <firstname>%(test_firstname)s</firstname> <lastname>%(test_lastname)s</lastname> <email>%(test_email)s</email> </memberaccount> </ResponseMember>""" % locals()), (200, """<?xml version="1.0" encoding="utf-8"?> <ResponseMember> <memberaccount id="%(test_member_id)s"> <username>%(test_username_update)s</username> <firstname>%(test_firstname)s</firstname> <lastname>%(test_lastname)s</lastname> <email>%(test_email)s</email> </memberaccount> </ResponseMember>""" % locals()), ] http = build_http_mock(HttpMock, responses=return_values) member = Member.query.get_by_id(test_member_id, client) assert member.username == test_username member.username = test_username_update member.update() assert member.username == test_username_update
def test_get_featured_playlists(HttpMock): client = init_client() test_playlist_id = get_random_md5() test_playlist_name = 'test playlist' content = """<?xml version="1.0" encoding="utf-8"?> <responsefeaturedplaylists> <playlists> <playlist id="%(id)s" name="%(name)s"> <tracks> <track tracknumber="001" time="01:07" lengthseconds="67" comment="If a certain animated film studio were to remake The Andy Griffith Show as a digital short, we'd nominate this for the theme. Warm, chunky, a little slow on the uptake... a.k.a. the anti-lemonade song. Ending starts @ 1:08. Lite Mix, without main rhythm acoustic guitars." composer="D. Holter/K. White" publisher="TLL UNDERscore Nashcap (ASCAP)" name="Pencilneck Strut" id="902dea1d377473df" keywords="Cute, Goofy, Lighthearted, Happy, Comical, Twang, Rural, Fun, Mischievous, Celebration, Campy, Childlike, Cheerful, Simple, Quirky, Swampy, Playful" lyrics="" displaytitle="Pencilneck Strut" genre="Country" tempo="Medium" instrumentation="Acoustic Guitar, Banjo, Percussion" bpm="130" mixout="Alt2" frequency="2650" bitrate="24" /> </tracks> </playlist> </playlists> </responsefeaturedplaylists> """ % {'id': test_playlist_id, 'name': test_playlist_name} http = build_http_mock(HttpMock, content=content) playlists = Playlist.query.get_featured_playlists(client) assert isinstance(playlists, list) playlist = playlists[0] assert playlist.id == test_playlist_id assert playlist.name == test_playlist_name
def test_album_tracks_fulldetail(HttpMock): client = init_client() album_id = '1c5f47572d9152f3' album_xml = ET.fromstring(textwrap.dedent("""<album featured="false" code="HM001" detail="Razor-sharp pop& rock bristling with spiky guitars & infectious, feelgood inspiration … and tons of attitude." name="HM 001 Sample Album" displaytitle="HM 001 Sample Album " id="%s"/> """ % (album_id))) return_values = [ (200, """<responsetracks> <tracks> <track tracknumber="1" time="02:50" lengthseconds="170" comment="Make sure you’re down the front for this fiery Post Punk workout." composer=""S. Milton, J. Wygens"" publisher="" name="Guerilla Pop" albumid="%(album_id)s" id="17376d36f309f18d" keywords="" displaytitle="Guerilla Pop" genre="Pop / Rock" tempo="" instrumentation="" bpm="" mixout="" frequency="44100" bitrate="1411" dateingested="2008-05-15 06:08:18"/> <track tracknumber="2" time="02:46" lengthseconds="166" comment="Poignant electric guitars. Brooding acoustic strums." composer=""S. Milton, J. Wygens"" publisher="" name="Hat And Feather" albumid="%(album_id)s" id="635f90a4db673855" keywords="" displaytitle="Hat And Feather" genre="Pop / Rock" tempo="" instrumentation="" bpm="" mixout="" frequency="44100" bitrate="1411" dateingested="2008-05-15 06:08:18"/> </tracks> </responsetracks>""" % locals(),), (200, """<responsetracks> <tracks> <track tracknumber="1" time="02:50" lengthseconds="170" comment="Make sure you’re down the front for this fiery Post Punk workout." composer=""S. Milton, J. Wygens"" publisher="" name="Guerilla Pop" albumid="%(album_id)s" id="17376d36f309f18d" keywords="" displaytitle="Guerilla Pop" genre="Pop / Rock" tempo="" instrumentation="" bpm="" mixout="" frequency="44100" bitrate="1411" dateingested="2008-05-15 06:08:18"> <categories> <category name="Tuning" id="07615de0da9a3d50"> <attributes> <attribute name="Energy" id="a7cc2fe1b4075e51"> <attributes> <attribute name="4" In="" Motion="" id="97fda140bf94f8ca" /> </attributes> </attribute> <attribute name="Genetics" id="a5306d79fa80d3da"> <attributes> <attribute name="3" Blended="" id="387b65044f597b48" /> </attributes> </attribute> <attribute name="Mood" id="05c1d9f5bb63b113"> <attributes> <attribute name="1" id="527d6c887023f4ee" /> </attributes> </attribute> <attribute name="Tempo" id="65ea5898a4549788"> <attributes> <attribute name="3" Medium="" id="b7f9cd0ca260b61a" /> </attributes> </attribute> <attribute name="Tone" id="22aadd9f2935aabe"> <attributes> <attribute name="2" Leaning="" Dark="" id="aa9c33fef3c5756f" /> </attributes> </attribute> <attribute name="Vocals" id="ea584a3d9b4fb116"> <attributes> <attribute name="0" id="da2362b0e30b131f" /> </attributes> </attribute> </attributes> </category> <category name="Instrumentation" id="7907138b683424f4"> <attributes> <attribute name="Guitars" id="abf2d935cb4182b7"> <attributes> <attribute name="Electric" Distorted="" id="96d809f485c198d4" /> </attributes> </attribute> <attribute name="Bass" id="080a1841ed350bbb"> <attributes> <attribute name="Electric" id="a4fc0c1d3ad2cd64" /> </attributes> </attribute> <attribute name="Drums" id="16fd25d513dce9dd"> <attributes> <attribute name="Live" id="35babb65b41e2028" /> </attributes> </attribute> <attribute name="Percussion" id="aa2850c4d1579d12"> <attributes> <attribute name="Electronic" id="29aefdd818757ea3" /> </attributes> </attribute> <attribute name="Keyboards" id="660d379e9f7a6faf"> <attributes> <attribute name="Synth" id="61454b4396a1f362" /> </attributes> </attribute> </attributes> </category> </categories> </track> <track tracknumber="2" time="02:46" lengthseconds="166" comment="Poignant electric guitars. Brooding acoustic strums." composer=""S. Milton, J. Wygens"" publisher="" name="Hat And Feather" albumid="%(album_id)s" id="635f90a4db673855" keywords="" displaytitle="Hat And Feather" genre="Pop / Rock" tempo="" instrumentation="" bpm="" mixout="" frequency="44100" bitrate="1411" dateingested="2008-05-15 06:08:18"/> </tracks> </responsetracks>""" % locals(),), ] http = build_http_mock(HttpMock, responses=return_values) album = Album._from_xml(album_xml, client) tracks = album.get_tracks() assert tracks[0].albumid == album_id
def test_album_tracks_fulldetail(HttpMock): client = init_client() album_id = '1c5f47572d9152f3' album_xml = ET.fromstring( textwrap.dedent( """<album featured="false" code="HM001" detail="Razor-sharp pop& rock bristling with spiky guitars & infectious, feelgood inspiration … and tons of attitude." name="HM 001 Sample Album" displaytitle="HM 001 Sample Album " id="%s"/> """ % (album_id))) return_values = [ ( 200, """<responsetracks> <tracks> <track tracknumber="1" time="02:50" lengthseconds="170" comment="Make sure you’re down the front for this fiery Post Punk workout." composer=""S. Milton, J. Wygens"" publisher="" name="Guerilla Pop" albumid="%(album_id)s" id="17376d36f309f18d" keywords="" displaytitle="Guerilla Pop" genre="Pop / Rock" tempo="" instrumentation="" bpm="" mixout="" frequency="44100" bitrate="1411" dateingested="2008-05-15 06:08:18"/> <track tracknumber="2" time="02:46" lengthseconds="166" comment="Poignant electric guitars. Brooding acoustic strums." composer=""S. Milton, J. Wygens"" publisher="" name="Hat And Feather" albumid="%(album_id)s" id="635f90a4db673855" keywords="" displaytitle="Hat And Feather" genre="Pop / Rock" tempo="" instrumentation="" bpm="" mixout="" frequency="44100" bitrate="1411" dateingested="2008-05-15 06:08:18"/> </tracks> </responsetracks>""" % locals(), ), ( 200, """<responsetracks> <tracks> <track tracknumber="1" time="02:50" lengthseconds="170" comment="Make sure you’re down the front for this fiery Post Punk workout." composer=""S. Milton, J. Wygens"" publisher="" name="Guerilla Pop" albumid="%(album_id)s" id="17376d36f309f18d" keywords="" displaytitle="Guerilla Pop" genre="Pop / Rock" tempo="" instrumentation="" bpm="" mixout="" frequency="44100" bitrate="1411" dateingested="2008-05-15 06:08:18"> <categories> <category name="Tuning" id="07615de0da9a3d50"> <attributes> <attribute name="Energy" id="a7cc2fe1b4075e51"> <attributes> <attribute name="4" In="" Motion="" id="97fda140bf94f8ca" /> </attributes> </attribute> <attribute name="Genetics" id="a5306d79fa80d3da"> <attributes> <attribute name="3" Blended="" id="387b65044f597b48" /> </attributes> </attribute> <attribute name="Mood" id="05c1d9f5bb63b113"> <attributes> <attribute name="1" id="527d6c887023f4ee" /> </attributes> </attribute> <attribute name="Tempo" id="65ea5898a4549788"> <attributes> <attribute name="3" Medium="" id="b7f9cd0ca260b61a" /> </attributes> </attribute> <attribute name="Tone" id="22aadd9f2935aabe"> <attributes> <attribute name="2" Leaning="" Dark="" id="aa9c33fef3c5756f" /> </attributes> </attribute> <attribute name="Vocals" id="ea584a3d9b4fb116"> <attributes> <attribute name="0" id="da2362b0e30b131f" /> </attributes> </attribute> </attributes> </category> <category name="Instrumentation" id="7907138b683424f4"> <attributes> <attribute name="Guitars" id="abf2d935cb4182b7"> <attributes> <attribute name="Electric" Distorted="" id="96d809f485c198d4" /> </attributes> </attribute> <attribute name="Bass" id="080a1841ed350bbb"> <attributes> <attribute name="Electric" id="a4fc0c1d3ad2cd64" /> </attributes> </attribute> <attribute name="Drums" id="16fd25d513dce9dd"> <attributes> <attribute name="Live" id="35babb65b41e2028" /> </attributes> </attribute> <attribute name="Percussion" id="aa2850c4d1579d12"> <attributes> <attribute name="Electronic" id="29aefdd818757ea3" /> </attributes> </attribute> <attribute name="Keyboards" id="660d379e9f7a6faf"> <attributes> <attribute name="Synth" id="61454b4396a1f362" /> </attributes> </attribute> </attributes> </category> </categories> </track> <track tracknumber="2" time="02:46" lengthseconds="166" comment="Poignant electric guitars. Brooding acoustic strums." composer=""S. Milton, J. Wygens"" publisher="" name="Hat And Feather" albumid="%(album_id)s" id="635f90a4db673855" keywords="" displaytitle="Hat And Feather" genre="Pop / Rock" tempo="" instrumentation="" bpm="" mixout="" frequency="44100" bitrate="1411" dateingested="2008-05-15 06:08:18"/> </tracks> </responsetracks>""" % locals(), ), ] http = build_http_mock(HttpMock, responses=return_values) album = Album._from_xml(album_xml, client) tracks = album.get_tracks() assert tracks[0].albumid == album_id
def test_tracks_get_by_id(HttpMock): client = init_client() track_id = '17376d36f309f18d' track_name = 'Guerilla Pop' track_xml = ET.fromstring(textwrap.dedent("""<track tracknumber="1" time="02:50" lengthseconds="170" comment="Make sure you’re down the front for this fiery Post Punk workout." composer=""S. Milton, J. Wygens"" publisher="" name="%(track_name)s" albumid="1c5f47572d9152f3" id="%(track_id)s" keywords="" displaytitle="Guerilla Pop" genre="Pop / Rock" tempo="" instrumentation="" bpm="" mixout="" frequency="44100" bitrate="1411" dateingested="2008-05-15 06:08:18"/>""") % locals()) return_values = [ (200, """<responsetracks> <tracks> <track tracknumber="1" time="02:50" lengthseconds="170" comment="Make sure you’re down the front for this fiery Post Punk workout." composer=""S. Milton, J. Wygens"" publisher="" name="%(track_name)s" albumid="1111001010001aaabeb" id="17376d36f309f18d" keywords="" displaytitle="Guerilla Pop" genre="Pop / Rock" tempo="" instrumentation="" bpm="" mixout="" frequency="44100" bitrate="1411" dateingested="2008-05-15 06:08:18"> <categories> <category name="Tuning" id="07615de0da9a3d50"> <attributes> <attribute name="Energy" id="a7cc2fe1b4075e51"> <attributes> <attribute name="4" In="" Motion="" id="97fda140bf94f8ca" /> </attributes> </attribute> <attribute name="Genetics" id="a5306d79fa80d3da"> <attributes> <attribute name="3" Blended="" id="387b65044f597b48" /> </attributes> </attribute> <attribute name="Mood" id="05c1d9f5bb63b113"> <attributes> <attribute name="1" id="527d6c887023f4ee" /> </attributes> </attribute> <attribute name="Tempo" id="65ea5898a4549788"> <attributes> <attribute name="3" Medium="" id="b7f9cd0ca260b61a" /> </attributes> </attribute> <attribute name="Tone" id="22aadd9f2935aabe"> <attributes> <attribute name="2" Leaning="" Dark="" id="aa9c33fef3c5756f" /> </attributes> </attribute> <attribute name="Vocals" id="ea584a3d9b4fb116"> <attributes> <attribute name="0" id="da2362b0e30b131f" /> </attributes> </attribute> </attributes> </category> <category name="Instrumentation" id="7907138b683424f4"> <attributes> <attribute name="Guitars" id="abf2d935cb4182b7"> <attributes> <attribute name="Electric" Distorted="" id="96d809f485c198d4" /> </attributes> </attribute> <attribute name="Bass" id="080a1841ed350bbb"> <attributes> <attribute name="Electric" id="a4fc0c1d3ad2cd64" /> </attributes> </attribute> <attribute name="Drums" id="16fd25d513dce9dd"> <attributes> <attribute name="Live" id="35babb65b41e2028" /> </attributes> </attribute> <attribute name="Percussion" id="aa2850c4d1579d12"> <attributes> <attribute name="Electronic" id="29aefdd818757ea3" /> </attributes> </attribute> <attribute name="Keyboards" id="660d379e9f7a6faf"> <attributes> <attribute name="Synth" id="61454b4396a1f362" /> </attributes> </attribute> </attributes> </category> </categories> </track> </tracks> </responsetracks>""" % locals(),), ] http = build_http_mock(HttpMock, responses=return_values) track = Track.query.get_by_id(track_id, client) assert track.id == track_id assert track.name == track_name
def test_tracks_get_by_id(HttpMock): client = init_client() track_id = '17376d36f309f18d' track_name = 'Guerilla Pop' track_xml = ET.fromstring( textwrap.dedent( """<track tracknumber="1" time="02:50" lengthseconds="170" comment="Make sure you’re down the front for this fiery Post Punk workout." composer=""S. Milton, J. Wygens"" publisher="" name="%(track_name)s" albumid="1c5f47572d9152f3" id="%(track_id)s" keywords="" displaytitle="Guerilla Pop" genre="Pop / Rock" tempo="" instrumentation="" bpm="" mixout="" frequency="44100" bitrate="1411" dateingested="2008-05-15 06:08:18"/>""" ) % locals()) return_values = [ ( 200, """<responsetracks> <tracks> <track tracknumber="1" time="02:50" lengthseconds="170" comment="Make sure you’re down the front for this fiery Post Punk workout." composer=""S. Milton, J. Wygens"" publisher="" name="%(track_name)s" albumid="1111001010001aaabeb" id="17376d36f309f18d" keywords="" displaytitle="Guerilla Pop" genre="Pop / Rock" tempo="" instrumentation="" bpm="" mixout="" frequency="44100" bitrate="1411" dateingested="2008-05-15 06:08:18"> <categories> <category name="Tuning" id="07615de0da9a3d50"> <attributes> <attribute name="Energy" id="a7cc2fe1b4075e51"> <attributes> <attribute name="4" In="" Motion="" id="97fda140bf94f8ca" /> </attributes> </attribute> <attribute name="Genetics" id="a5306d79fa80d3da"> <attributes> <attribute name="3" Blended="" id="387b65044f597b48" /> </attributes> </attribute> <attribute name="Mood" id="05c1d9f5bb63b113"> <attributes> <attribute name="1" id="527d6c887023f4ee" /> </attributes> </attribute> <attribute name="Tempo" id="65ea5898a4549788"> <attributes> <attribute name="3" Medium="" id="b7f9cd0ca260b61a" /> </attributes> </attribute> <attribute name="Tone" id="22aadd9f2935aabe"> <attributes> <attribute name="2" Leaning="" Dark="" id="aa9c33fef3c5756f" /> </attributes> </attribute> <attribute name="Vocals" id="ea584a3d9b4fb116"> <attributes> <attribute name="0" id="da2362b0e30b131f" /> </attributes> </attribute> </attributes> </category> <category name="Instrumentation" id="7907138b683424f4"> <attributes> <attribute name="Guitars" id="abf2d935cb4182b7"> <attributes> <attribute name="Electric" Distorted="" id="96d809f485c198d4" /> </attributes> </attribute> <attribute name="Bass" id="080a1841ed350bbb"> <attributes> <attribute name="Electric" id="a4fc0c1d3ad2cd64" /> </attributes> </attribute> <attribute name="Drums" id="16fd25d513dce9dd"> <attributes> <attribute name="Live" id="35babb65b41e2028" /> </attributes> </attribute> <attribute name="Percussion" id="aa2850c4d1579d12"> <attributes> <attribute name="Electronic" id="29aefdd818757ea3" /> </attributes> </attribute> <attribute name="Keyboards" id="660d379e9f7a6faf"> <attributes> <attribute name="Synth" id="61454b4396a1f362" /> </attributes> </attribute> </attributes> </category> </categories> </track> </tracks> </responsetracks>""" % locals(), ), ] http = build_http_mock(HttpMock, responses=return_values) track = Track.query.get_by_id(track_id, client) assert track.id == track_id assert track.name == track_name