class ApiTest(unittest.TestCase): @my_vcr.use_cassette("sc-login.yaml") def setUp(self): config = Extension().get_config_schema() config["auth_token"] = "1-35204-61921957-55796ebef403996" config["explore_songs"] = 10 self.api = SoundCloudClient({"soundcloud": config, "proxy": {}}) def test_sets_user_agent(self): agent = "Mopidy-SoundCloud/%s Mopidy/" % mopidy_soundcloud.__version__ assert agent in self.api.http_client.headers["user-agent"] def test_resolves_string(self): _id = self.api.parse_track_uri("soundcloud:song.38720262") assert _id == "38720262" @my_vcr.use_cassette("sc-login-error.yaml") def test_responds_with_error(self): with mock.patch("mopidy_soundcloud.soundcloud.logger.error") as d: config = Extension().get_config_schema() config["auth_token"] = "1-fake-token" SoundCloudClient({"soundcloud": config, "proxy": {}}).user d.assert_called_once_with('Invalid "auth_token" used for ' "SoundCloud authentication!") @my_vcr.use_cassette("sc-login.yaml") def test_returns_username(self): user = self.api.user.get("username") assert user == "Nick Steel 3" @my_vcr.use_cassette("sc-resolve-track.yaml") def test_resolves_object(self): trackc = {} trackc["uri"] = "soundcloud:song.38720262" track = Track(**trackc) id = self.api.parse_track_uri(track) assert id == "38720262" @my_vcr.use_cassette("sc-resolve-track-none.yaml") def test_resolves_unknown_track_to_none(self): track = self.api.get_track("s38720262") assert track is None @my_vcr.use_cassette("sc-resolve-track.yaml") def test_resolves_track(self): track = self.api.get_track("13158665") assert isinstance(track, Track) assert track.uri == "soundcloud:song/Munching at Tiannas house.13158665" @my_vcr.use_cassette("sc-resolve-http.yaml") def test_resolves_http_url(self): track = self.api.resolve_url( "https://soundcloud.com/bbc-radio-4/m-w-cloud")[0] assert isinstance(track, Track) assert ( track.uri == "soundcloud:song/That Mitchell and Webb Sound The Cloud.122889665") @my_vcr.use_cassette("sc-resolve-set.yaml") def test_resolves_set_url(self): expected_tracks = [ "01 Dash And Blast", "02 We Flood Empty Lakes", "03 A Song For Starlit Beaches", "04 Illuminate My Heart, My Darling", ] tracks = self.api.resolve_url( "https://soundcloud.com/yndihalda/sets/dash-and-blast") assert len(tracks) == 4 for i, _ in enumerate(expected_tracks): assert isinstance(tracks[i], Track) assert tracks[i].name == expected_tracks[i] assert tracks[i].length > 500 assert len(tracks[i].artists) == 1 assert list(tracks[i].artists)[0].name == "yndi halda" @my_vcr.use_cassette("sc-liked.yaml") def test_get_user_likes(self): tracks = self.api.get_likes() assert len(tracks) == 3 assert isinstance(tracks[0], Track) assert tracks[1].name == "Pelican - Deny The Absolute" @my_vcr.use_cassette("sc-stream.yaml") def test_get_user_stream(self): tracks = self.api.get_user_stream() assert len(tracks) == 10 assert isinstance(tracks[0], Track) assert tracks[2].name == "JW Ep 20- Jeremiah Watkins" @my_vcr.use_cassette("sc-following.yaml") def test_get_followings(self): users = self.api.get_followings() assert len(users) == 10 assert users[0] == ("Young Legionnaire", "992503") assert users[1] == ("Tall Ships", "1710483") assert users[8] == ("Pelican Song", "27945548") assert users[9] == ("sleepmakeswaves", "1739693") @my_vcr.use_cassette("sc-user-tracks.yaml") def test_get_user_tracks(self): expected_tracks = [ "The Wait", "The Cliff (Palms Remix)", "The Cliff (Justin Broadrick Remix)", "The Cliff (Vocal Version)", "Pelican - The Creeper", "Pelican - Lathe Biosas", "Pelican - Ephemeral", "Pelican - Deny the Absolute", "Pelican - Immutable Dusk", "Pelican - Strung Up From The Sky", ] tracks = self.api.get_tracks(27945548) for i, _ in enumerate(expected_tracks): assert isinstance(tracks[i], Track) assert tracks[i].name == expected_tracks[i] assert tracks[i].length > 500 assert len(tracks[i].artists) == 1 @my_vcr.use_cassette("sc-set.yaml") def test_get_set(self): tracks = self.api.get_set("10961826") assert len(tracks) == 1 assert isinstance(tracks[0], dict) @my_vcr.use_cassette("sc-set-invalid.yaml") def test_get_invalid_set(self): tracks = self.api.get_set("blahblahrubbosh") assert tracks == [] @my_vcr.use_cassette("sc-sets.yaml") def test_get_sets(self): sets = self.api.get_sets() assert len(sets) == 2 name, set_id, tracks = sets[1] assert name == "Pelican" assert set_id == "10961826" assert len(tracks) == 1 def test_readeble_url(self): assert "Barsuk Records" == readable_url('"@"Barsuk Records') assert "_Barsuk Records" == readable_url("_Barsuk 'Records'") @my_vcr.use_cassette("sc-resolve-track-id.yaml") def test_resolves_stream_track(self): track = self.api.get_track("13158665", True) assert isinstance(track, Track) assert track.uri == ( "https://cf-media.sndcdn.com/fxguEjG4ax6B.128.mp3?Policy=" "eyJTdGF0ZW1lbnQiOlt7IlJlc291cmNlIjoiKjovL2NmLW1lZGlhLnNu" "ZGNkbi5jb20vZnhndUVqRzRheDZCLjEyOC5tcDMiLCJDb25kaXRpb24i" "OnsiRGF0ZUxlc3NUaGFuIjp7IkFXUzpFcG9jaFRpbWUiOjE0Nzc2MDA1" "NTd9fX1dfQ__&Signature=u9bxAkZOtTTF1VqTmLGmw3ENrqbiSTFK-" "sMvZL-ZsQK85DOepHh5MfPA4MNooszUy~PZqiVyBn4YnElhWyb~4B7kS" "6y0VZ6t-qF78CfTMOimemafpqfWJ8nYXczhM9pUpAwiS--lkNjGks4Qx" "i-FZJDBPG99gAIU0eVW78CADcpuOKLugGpzHl6gRPN2Z4zZ9dVujZ5Ml" "G2OWnPuNiBcE~wUFwcOxt9N6ePTff-wMFQR2PGpEK6wc6bWuB4WFNBkE" "0bmEke4cOQjWHa5FwYEidZN5rvv5lVT1r07zzifnADEipwMaZ2-QYdqz" "OYaM4jymFDhl7DklaU24PY5C5mH0A__&Key-Pair-Id=APKAJAGZ7VMH" "2PFPW6UQ") @my_vcr.use_cassette("sc-search.yaml") def test_search(self): tracks = self.api.search("the great descent") assert len(tracks) == 10 assert isinstance(tracks[0], Track) assert tracks[0].name == "Turn Around (Mix1)"
class ApiTest(unittest.TestCase): @vcr.use_cassette('tests/fixtures/sc-login.yaml') def setUp(self): config = SoundCloudExtension().get_config_schema() config['auth_token'] = '1-35204-61921957-55796ebef403996' config['explore_songs'] = 10 # using this user http://maildrop.cc/inbox/mopidytestuser self.api = SoundCloudClient(config) def test_resolves_string(self): _id = self.api.parse_track_uri('soundcloud:song.38720262') self.assertEquals(_id, '38720262') @vcr.use_cassette('tests/fixtures/sc-login-error.yaml') def test_responds_with_error(self): with mock.patch('mopidy_soundcloud.soundcloud.logger.error') as d: config = SoundCloudExtension().get_config_schema() config['auth_token'] = '1-fake-token' SoundCloudClient(config) d.assert_called_once_with('Invalid "auth_token" used for ' 'SoundCloud authentication!') @vcr.use_cassette('tests/fixtures/sc-resolve-track.yaml') def test_resolves_object(self): trackc = {} trackc[b'uri'] = 'soundcloud:song.38720262' track = Track(**trackc) id = self.api.parse_track_uri(track) self.assertEquals(id, '38720262') @vcr.use_cassette('tests/fixtures/sc-resolve-track-none.yaml') def test_resolves_unknown_track_to_none(self): track = self.api.get_track('s38720262') self.assertIsNone(track) @vcr.use_cassette('tests/fixtures/sc-resolve-track.yaml') def test_resolves_Track(self): track = self.api.get_track('38720262') self.assertIsInstance(track, Track) self.assertEquals( track.uri, 'soundcloud:song/Burial Four Tet - Nova.38720262' ) @vcr.use_cassette('tests/fixtures/sc-resolve-http.yaml') def test_resolves_http_url(self): track = self.api.resolve_url( 'https://soundcloud.com/bbc-radio-4/m-w-cloud' )[0] self.assertIsInstance(track, Track) self.assertEquals( track.uri, 'soundcloud:song/That Mitchell and Webb Sound The Cloud.122889665' ) @vcr.use_cassette('tests/fixtures/sc-liked.yaml') def test_get_user_liked(self): tracks = self.api.get_user_liked() self.assertIsInstance(tracks, list) @vcr.use_cassette('tests/fixtures/sc-stream.yaml') def test_get_user_stream(self): tracks = self.api.get_user_stream() self.assertIsInstance(tracks, list) @vcr.use_cassette('tests/fixtures/sc-explore.yaml') def test_get_explore(self): tracks = self.api.get_explore() self.assertIsInstance(tracks, list) self.assertEquals(tracks[0], 'Popular+Music') @vcr.use_cassette('tests/fixtures/sc-popular.yaml') def test_get_explore_popular_music(self): tracks = self.api.get_explore('1') self.assertIsInstance(tracks, list) self.assertIsInstance(tracks[0], Track) @vcr.use_cassette('tests/fixtures/sc-following.yaml') def test_get_followings(self): tracks = self.api.get_followings() self.assertIsInstance(tracks, list) @vcr.use_cassette('tests/fixtures/sc-sets.yaml') def test_get_sets(self): tracks = self.api.get_sets() self.assertIsInstance(tracks, list) @vcr.use_cassette('tests/fixtures/sc-groups.yaml') def test_get_groups(self): tracks = self.api.get_groups() self.assertIsInstance(tracks, list) @vcr.use_cassette('tests/fixtures/sc-tracks.yaml') def test_get_group_tracks(self): tracks = self.api.get_groups(136) self.assertIsInstance(tracks[0], Track) def test_readeble_url(self): self.assertEquals('Barsuk Records', readable_url('"@"Barsuk Records')) self.assertEquals('_Barsuk Records', readable_url('_Barsuk \'Records\'')) @vcr.use_cassette('tests/fixtures/sc-resolve-track-id.yaml') def test_resolves_stream_track(self): track = self.api.get_track('38720262', True) self.assertIsInstance(track, Track) self.assertEquals( track.uri, 'https://api.soundcloud.com/tracks/' '38720262/stream?client_id=93e33e327fd8a9b77becd179652272e2' )
class ApiTest(unittest.TestCase): @vcr.use_cassette("tests/fixtures/sc-login.yaml") def setUp(self): config = SoundCloudExtension().get_config_schema() config["auth_token"] = "1-35204-61921957-55796ebef403996" config["explore_songs"] = 10 # using this user http://maildrop.cc/inbox/mopidytestuser self.api = SoundCloudClient(config) def test_resolves_string(self): _id = self.api.parse_track_uri("soundcloud:song.38720262") self.assertEquals(_id, "38720262") @vcr.use_cassette("tests/fixtures/sc-login-error.yaml") def test_responds_with_error(self): with mock.patch("mopidy_soundcloud.soundcloud.logger.error") as d: config = SoundCloudExtension().get_config_schema() config["auth_token"] = "1-fake-token" SoundCloudClient(config) d.assert_called_once_with('Invalid "auth_token" used for ' "SoundCloud authentication!") @vcr.use_cassette("tests/fixtures/sc-resolve-track.yaml") def test_resolves_object(self): trackc = {} trackc[b"uri"] = "soundcloud:song.38720262" track = Track(**trackc) id = self.api.parse_track_uri(track) self.assertEquals(id, "38720262") @vcr.use_cassette("tests/fixtures/sc-resolve-track-none.yaml") def test_resolves_emptyTrack(self): track = self.api.get_track("s38720262") self.assertIsInstance(track, Track) self.assertEquals(track.uri, None) @vcr.use_cassette("tests/fixtures/sc-resolve-track.yaml") def test_resolves_Track(self): track = self.api.get_track("38720262") self.assertIsInstance(track, Track) self.assertEquals(track.uri, "soundcloud:song/Burial Four Tet - Nova.38720262") @vcr.use_cassette("tests/fixtures/sc-resolve-http.yaml") def test_resolves_http_url(self): track = self.api.resolve_url("https://soundcloud.com/bbc-radio-4/m-w-cloud")[0] self.assertIsInstance(track, Track) self.assertEquals(track.uri, "soundcloud:song/That Mitchell and Webb Sound The Cloud.122889665") @vcr.use_cassette("tests/fixtures/sc-liked.yaml") def test_get_user_liked(self): tracks = self.api.get_user_liked() self.assertIsInstance(tracks, list) @vcr.use_cassette("tests/fixtures/sc-stream.yaml") def test_get_user_stream(self): tracks = self.api.get_user_stream() self.assertIsInstance(tracks, list) @vcr.use_cassette("tests/fixtures/sc-explore.yaml") def test_get_explore(self): tracks = self.api.get_explore() self.assertIsInstance(tracks, list) self.assertEquals(tracks[0], "Popular+Music") @vcr.use_cassette("tests/fixtures/sc-popular.yaml") def test_get_explore_popular_music(self): tracks = self.api.get_explore("1") self.assertIsInstance(tracks, list) self.assertIsInstance(tracks[0], Track) @vcr.use_cassette("tests/fixtures/sc-following.yaml") def test_get_followings(self): tracks = self.api.get_followings() self.assertIsInstance(tracks, list) @vcr.use_cassette("tests/fixtures/sc-sets.yaml") def test_get_sets(self): tracks = self.api.get_sets() self.assertIsInstance(tracks, list) @vcr.use_cassette("tests/fixtures/sc-groups.yaml") def test_get_groups(self): tracks = self.api.get_groups() self.assertIsInstance(tracks, list) @vcr.use_cassette("tests/fixtures/sc-tracks.yaml") def test_get_group_tracks(self): tracks = self.api.get_groups(136) self.assertIsInstance(tracks[0], Track) def test_readeble_url(self): self.assertEquals("Barsuk Records", readable_url('"@"Barsuk Records')) self.assertEquals("_Barsuk Records", readable_url("_Barsuk 'Records'")) @vcr.use_cassette("tests/fixtures/sc-resolve-track-id.yaml") def test_resolves_stream_Track(self): track = self.api.get_track("38720262", True) self.assertIsInstance(track, Track) self.assertEquals( track.uri, "https://api.soundcloud.com/tracks/" "38720262/stream?client_id=93e33e327fd8a9b77becd179652272e2" )
class ApiTest(unittest.TestCase): @my_vcr.use_cassette("sc-login.yaml") def setUp(self): config = Extension().get_config_schema() config["auth_token"] = "3-35204-970067440-lVY4FovkEcKrEGw" config["explore_songs"] = 10 self.api = SoundCloudClient({"soundcloud": config, "proxy": {}}) def test_sets_user_agent(self): agent = "Mopidy-SoundCloud/%s Mopidy/" % mopidy_soundcloud.__version__ assert agent in self.api.http_client.headers["user-agent"] def test_public_client_no_token(self): token_key = "authorization" assert token_key not in self.api.public_stream_client.headers._store def test_resolves_string(self): _id = self.api.parse_track_uri("soundcloud:song.38720262") assert _id == "38720262" @my_vcr.use_cassette("sc-login-error.yaml") def test_responds_with_error(self): with mock.patch("mopidy_soundcloud.soundcloud.logger.error") as d: config = Extension().get_config_schema() config["auth_token"] = "1-fake-token" SoundCloudClient({"soundcloud": config, "proxy": {}}).user d.assert_called_once_with( 'Invalid "auth_token" used for SoundCloud authentication!') @my_vcr.use_cassette("sc-login.yaml") def test_returns_username(self): user = self.api.user.get("username") assert user == "Nick Steel 3" @my_vcr.use_cassette("sc-resolve-track.yaml") def test_resolves_object(self): trackc = {} trackc["uri"] = "soundcloud:song.38720262" track = Track(**trackc) id = self.api.parse_track_uri(track) assert id == "38720262" @my_vcr.use_cassette("sc-resolve-track-none.yaml") def test_resolves_unknown_track_to_none(self): track = self.api.get_track("s38720262") assert track is None @my_vcr.use_cassette("sc-resolve-track.yaml") def test_resolves_track(self): track = self.api.get_track("13158665") assert isinstance(track, Track) assert track.uri == "soundcloud:song/Munching at Tiannas house.13158665" @my_vcr.use_cassette("sc-resolve-http.yaml") def test_resolves_http_url(self): track = self.api.resolve_url( "https://soundcloud.com/bbc-radio-4/m-w-cloud")[0] assert isinstance(track, Track) assert ( track.uri == "soundcloud:song/That Mitchell and Webb Sound The Cloud.122889665") @my_vcr.use_cassette("sc-resolve-set.yaml") def test_resolves_set_url(self): expected_tracks = [ "01 Dash And Blast", "02 We Flood Empty Lakes", "03 A Song For Starlit Beaches", "04 Illuminate My Heart, My Darling", ] tracks = self.api.resolve_url( "https://soundcloud.com/yndihalda/sets/dash-and-blast") assert len(tracks) == 4 for i, _ in enumerate(expected_tracks): assert isinstance(tracks[i], Track) assert tracks[i].name == expected_tracks[i] assert tracks[i].length > 500 assert len(tracks[i].artists) == 1 assert list(tracks[i].artists)[0].name == "yndi halda" @my_vcr.use_cassette("sc-liked.yaml") def test_get_user_likes(self): tracks = self.api.get_likes() assert len(tracks) == 3 assert isinstance(tracks[0], Track) assert tracks[1].name == "Pelican - Deny The Absolute" @my_vcr.use_cassette("sc-stream.yaml") def test_get_user_stream(self): tracks = self.api.get_user_stream() assert len(tracks) == 10 assert isinstance(tracks[0], Track) assert tracks[2].name == "JW Ep 20- Jeremiah Watkins" @my_vcr.use_cassette("sc-following.yaml") def test_get_followings(self): users = self.api.get_followings() assert len(users) == 10 assert users[0] == ("Young Legionnaire", "992503") assert users[1] == ("Tall Ships", "1710483") assert users[8] == ("Pelican Song", "27945548") assert users[9] == ("sleepmakeswaves", "1739693") @my_vcr.use_cassette("sc-user-tracks.yaml") def test_get_user_tracks(self): expected_tracks = [ "The Wait", "The Cliff (Palms Remix)", "The Cliff (Justin Broadrick Remix)", "The Cliff (Vocal Version)", "Pelican - The Creeper", "Pelican - Lathe Biosas", "Pelican - Ephemeral", "Pelican - Deny the Absolute", "Pelican - Immutable Dusk", "Pelican - Strung Up From The Sky", ] tracks = self.api.get_tracks(27945548) for i, _ in enumerate(expected_tracks): assert isinstance(tracks[i], Track) assert tracks[i].name == expected_tracks[i] assert tracks[i].length > 500 assert len(tracks[i].artists) == 1 @my_vcr.use_cassette("sc-set.yaml") def test_get_set(self): tracks = self.api.get_set("10961826") assert len(tracks) == 1 assert isinstance(tracks[0], dict) @my_vcr.use_cassette("sc-set-invalid.yaml") def test_get_invalid_set(self): tracks = self.api.get_set("blahblahrubbosh") assert tracks == [] @my_vcr.use_cassette("sc-sets.yaml") def test_get_sets(self): sets = self.api.get_sets() assert len(sets) == 2 name, set_id, tracks = sets[1] assert name == "Pelican" assert set_id == "10961826" assert len(tracks) == 1 def test_readeble_url(self): assert "Barsuk Records" == readable_url('"@"Barsuk Records') assert "_Barsuk Records" == readable_url("_Barsuk 'Records'") @my_vcr.use_cassette("sc-resolve-track-id.yaml") def test_resolves_stream_track(self): track = self.api.get_track("13158665", True) assert isinstance(track, Track) assert track.uri == ( "https://cf-media.sndcdn.com/fxguEjG4ax6B.128.mp3?Policy=" "eyJTdGF0ZW1lbnQiOlt7IlJlc291cmNlIjoiKjovL2NmLW1lZGlhLnNu" "ZGNkbi5jb20vZnhndUVqRzRheDZCLjEyOC5tcDMiLCJDb25kaXRpb24i" "OnsiRGF0ZUxlc3NUaGFuIjp7IkFXUzpFcG9jaFRpbWUiOjE2MTc3MzMy" "MDJ9fX1dfQ__&Signature=R6mfsrmYiPXF8Q-Eh0vsmtiqnIAkFMckw" "6qETd0gjJlXnxzjXq~ZiY4ClwgChjfv9e5NdID54hcSrq3jamUCuQ-Gr" "94WH0beJFXa9itVnV2A83~FE6Fye~ocTsVx7fzrpDFKJ80csI-QtLkV3" "3E06oMClsMPbjvdw3d1caFpGfkck7OCmV0Z9Jat0dYDkRfjGZF7HqGRP" "-upiIJ3l0cWfSyhRJ~F5o29TASJMQMQAigjCV0by9DsK2Naw1tcAW4DH" "YJF4oOUQkTLRwtw0B5mJXfKfFGQxjj1RSGZNFZxG0oV2nD1-svYX-Enz" "ldPOUBDvyUr-nNmS0wR9Qm5XsTAbQ__&Key-Pair-Id=APKAI6TU7MMX" "M5DG6EPQ") @my_vcr.use_cassette("sc-resolve-track-id.yaml") def test_unstreamable_track(self): track = self.api._get("tracks/13158665") track["streamable"] = False track = self.api.parse_track(track) assert track is None @my_vcr.use_cassette("sc-resolve-app-client-id.yaml") def test_resolves_app_client_id(self): track = self.api._get("tracks/13158665") track["sharing"] = "private" track = self.api.parse_track(track, True) assert track.uri == ( "https://cf-media.sndcdn.com/fxguEjG4ax6B.128.mp3?Policy=" "eyJTdGF0ZW1lbnQiOlt7IlJlc291cmNlIjoiKjovL2NmLW1lZGlhLnNu" "ZGNkbi5jb20vZnhndUVqRzRheDZCLjEyOC5tcDMiLCJDb25kaXRpb24i" "OnsiRGF0ZUxlc3NUaGFuIjp7IkFXUzpFcG9jaFRpbWUiOjE2MTc3Mzcw" "ODV9fX1dfQ__&Signature=AT7ZL9gDe~34stPzDOORReIeNTbEpo~27" "VP-set6t-T2mIW-W1fuWW6ny4-kd5XsW7mgndht1poURixYx1bUNTJFt" "SX1LjjfvUaGfA5w3eDbfSHvlmh8fqIVN6RZAbCwQUbcndn8TI5Q1EPfP" "8Aq-DLsIdUEE~3gxIVvX-YgzDZtxRMue0eefgp5oxk5z3KbHILPAyeS-" "GQx4JIgMxSWaMKiG0Dx0raTNW8JFNugs9u5h62J21BxGSd6aifU9boff" "khg1yWR9ccqHjMdDSRGpHLSBin6iNNHRzHj9vC4cq--DexYnyLQtdZp3" "UlaXbFlP~-3XBMf6FLNiPbUA4HxgA__&Key-Pair-Id=APKAI6TU7MMX" "M5DG6EPQ") @my_vcr.use_cassette("sc-resolve-track-id-invalid-client-id.yaml") def test_resolves_stream_track_invalid_id(self): self.api.public_client_id = "blahblahrubbosh" track = self.api.get_track("13158665", True) assert isinstance(track, Track) assert track.uri == ( "https://cf-media.sndcdn.com/fxguEjG4ax6B.128.mp3?Policy=" "eyJTdGF0ZW1lbnQiOlt7IlJlc291cmNlIjoiKjovL2NmLW1lZGlhLnNu" "ZGNkbi5jb20vZnhndUVqRzRheDZCLjEyOC5tcDMiLCJDb25kaXRpb24i" "OnsiRGF0ZUxlc3NUaGFuIjp7IkFXUzpFcG9jaFRpbWUiOjE2MTc1NDI2" "MDh9fX1dfQ__&Signature=SwnMkrFlBL1Es-S7DMuHLiAzYxgKdl4bk" "sjUny73MKN9d~54MhUzYOmgzETiERC73tyGo3iovjjk6P556J3FvAibn" "adM7ip5pPNT5HpyS4~xE2zCAg9s1DnDSypcUzOT6pvKKTJ3F95w6~kr3" "lRbRfDHsuq6O1HKB4k~NBVdTMRFhDRZJPdGg2BJFiI5M-IA-Ut5CQUJS" "kYNXG1kQtvIJNenAUQAuQm0iKv-um7C5YbgkdOpZC~HU49YiLcCw8T~b" "VYRgspxMctUQssmTg5yysD65vkQk8QVWpx9kE9kxdCL7oFqdAbv9tsgu" "s7~nptZlygrOVi9TIyikLsi6BeMQw__&Key-Pair-Id=APKAI6TU7MMX" "M5DG6EPQ") def test_parse_fail_reason(self): test_reason = "Unknown" reason_res = self.api.parse_fail_reason(test_reason) assert reason_res == "" @my_vcr.use_cassette("sc-search.yaml") def test_search(self): tracks = self.api.search("the great descent") assert len(tracks) == 10 assert isinstance(tracks[0], Track) assert tracks[0].name == "Turn Around (Mix1)"
class ApiTest(unittest.TestCase): def setUp(self): config = SoundCloudExtension().get_config_schema() config['auth_token'] = '1-35204-61921957-55796ebef403996' # using this user http://maildrop.cc/inbox/mopidytestuser self.api = SoundCloudClient(config) def test_resolves_string(self): id = self.api.parse_track_uri('soundcloud:song.38720262') self.assertEquals(id, '38720262') def test_resolves_object(self): trackc = {} trackc[b'uri'] = 'soundcloud:song.38720262' track = Track(**trackc) id = self.api.parse_track_uri(track) self.assertEquals(id, '38720262') def test_resolves_emptyTrack(self): track = self.api.get_track('s38720262') self.assertIsInstance(track, Track) self.assertEquals(track.uri, None) def test_resolves_Track(self): track = self.api.get_track('38720262') self.assertIsInstance(track, Track) self.assertEquals( track.uri, 'soundcloud:song/Burial Four Tet - Nova.38720262' ) def test_resolves_http_url(self): track = self.api.resolve_url( 'https://soundcloud.com/swedensfinestmusicblog/' 'robert-parker-brooklyn-brigde' )[0] self.assertIsInstance(track, Track) self.assertEquals( track.uri, 'soundcloud:song/Robert Parker - Brooklyn Brigde.135101951' ) def test_get_user_liked(self): tracks = self.api.get_user_liked() self.assertIsInstance(tracks, list) def test_get_user_stream(self): tracks = self.api.get_user_stream() self.assertIsInstance(tracks, list) def test_get_explore(self): tracks = self.api.get_explore() self.assertIsInstance(tracks, list) self.assertEquals(tracks[0], 'Popular+Music') def test_get_explore_popular_music(self): tracks = self.api.get_explore('1') self.assertIsInstance(tracks, list) self.assertIsInstance(tracks[0], Track) def test_get_followings(self): tracks = self.api.get_followings() self.assertIsInstance(tracks, list) def test_get_sets(self): tracks = self.api.get_sets() self.assertIsInstance(tracks, list) def test_safe_url(self): self.assertEquals('Barsuk Records', self.api.safe_url('"@"Barsuk Records')) self.assertEquals('_Barsuk Records', self.api.safe_url('_Barsuk \'Records\'')) def test_resolves_stream_Track(self): track = self.api.get_track('38720262', True) self.assertIsInstance(track, Track) self.assertEquals( track.uri, 'https://api.soundcloud.com/tracks/' '38720262/stream?client_id=93e33e327fd8a9b77becd179652272e2' )
class ApiTest(unittest.TestCase): def setUp(self): config = SoundCloudExtension().get_config_schema() config['auth_token'] = '1-35204-61921957-55796ebef403996' # using this user http://maildrop.cc/inbox/mopidytestuser self.api = SoundCloudClient(config) def test_resolves_string(self): id = self.api.parse_track_uri('soundcloud:song.38720262') self.assertEquals(id, '38720262') def test_resolves_object(self): trackc = {} trackc[b'uri'] = 'soundcloud:song.38720262' track = Track(**trackc) id = self.api.parse_track_uri(track) self.assertEquals(id, '38720262') def test_resolves_emptyTrack(self): track = self.api.get_track('s38720262') self.assertIsInstance(track, Track) self.assertEquals(track.uri, None) def test_resolves_Track(self): track = self.api.get_track('38720262') self.assertIsInstance(track, Track) self.assertEquals( track.uri, 'soundcloud:song/Burial Four Tet - Nova.38720262' ) def test_resolves_http_url(self): track = self.api.resolve_url( 'https://soundcloud.com/bbc-radio-4/m-w-cloud' )[0] self.assertIsInstance(track, Track) self.assertEquals( track.uri, 'soundcloud:song/That Mitchell and Webb Sound The Cloud.122889665' ) def test_get_user_liked(self): tracks = self.api.get_user_liked() self.assertIsInstance(tracks, list) def test_get_user_stream(self): tracks = self.api.get_user_stream() self.assertIsInstance(tracks, list) def test_get_explore(self): tracks = self.api.get_explore() self.assertIsInstance(tracks, list) self.assertEquals(tracks[0], 'Popular+Music') def test_get_explore_popular_music(self): tracks = self.api.get_explore('1') self.assertIsInstance(tracks, list) self.assertIsInstance(tracks[0], Track) def test_get_followings(self): tracks = self.api.get_followings() self.assertIsInstance(tracks, list) def test_get_sets(self): tracks = self.api.get_sets() self.assertIsInstance(tracks, list) def test_get_groups(self): tracks = self.api.get_groups() self.assertIsInstance(tracks, list) def test_get_group_tracks(self): tracks = self.api.get_groups(136) self.assertIsInstance(tracks[0], Track) def test_readeble_url(self): self.assertEquals('Barsuk Records', readable_url('"@"Barsuk Records')) self.assertEquals('_Barsuk Records', readable_url('_Barsuk \'Records\'')) def test_resolves_stream_Track(self): track = self.api.get_track('38720262', True) self.assertIsInstance(track, Track) self.assertEquals( track.uri, 'https://api.soundcloud.com/tracks/' '38720262/stream?client_id=93e33e327fd8a9b77becd179652272e2' )
class ApiTest(unittest.TestCase): @my_vcr.use_cassette('sc-login.yaml') def setUp(self): config = SoundCloudExtension().get_config_schema() config['auth_token'] = '1-35204-61921957-55796ebef403996' config['explore_songs'] = 10 self.api = SoundCloudClient({'soundcloud': config, 'proxy': {}}) def test_sets_user_agent(self): agent = 'Mopidy-SoundCloud/%s Mopidy/' % mopidy_soundcloud.__version__ self.assertTrue(agent in self.api.http_client.headers['user-agent']) def test_resolves_string(self): _id = self.api.parse_track_uri('soundcloud:song.38720262') self.assertEquals(_id, '38720262') @my_vcr.use_cassette('sc-login-error.yaml') def test_responds_with_error(self): with mock.patch('mopidy_soundcloud.soundcloud.logger.error') as d: config = SoundCloudExtension().get_config_schema() config['auth_token'] = '1-fake-token' SoundCloudClient({'soundcloud': config, 'proxy': {}}).user d.assert_called_once_with('Invalid "auth_token" used for ' 'SoundCloud authentication!') @my_vcr.use_cassette('sc-login.yaml') def test_returns_username(self): user = self.api.user.get('username') self.assertEquals(user, 'Nick Steel 3') @my_vcr.use_cassette('sc-resolve-track.yaml') def test_resolves_object(self): trackc = {} trackc[b'uri'] = 'soundcloud:song.38720262' track = Track(**trackc) id = self.api.parse_track_uri(track) self.assertEquals(id, '38720262') @my_vcr.use_cassette('sc-resolve-track-none.yaml') def test_resolves_unknown_track_to_none(self): track = self.api.get_track('s38720262') self.assertIsNone(track) @my_vcr.use_cassette('sc-resolve-track.yaml') def test_resolves_Track(self): track = self.api.get_track('13158665') self.assertIsInstance(track, Track) self.assertEquals( track.uri, 'soundcloud:song/Munching at Tiannas house.13158665') @my_vcr.use_cassette('sc-resolve-http.yaml') def test_resolves_http_url(self): track = self.api.resolve_url( 'https://soundcloud.com/bbc-radio-4/m-w-cloud')[0] self.assertIsInstance(track, Track) self.assertEquals( track.uri, 'soundcloud:song/That Mitchell and Webb Sound The Cloud.122889665') @my_vcr.use_cassette('sc-resolve-set.yaml') def test_resolves_set_url(self): expected_tracks = [ '01 Dash And Blast', '02 We Flood Empty Lakes', '03 A Song For Starlit Beaches', '04 Illuminate My Heart, My Darling' ] tracks = self.api.resolve_url( 'https://soundcloud.com/yndihalda/sets/dash-and-blast') self.assertEquals(len(tracks), 4) for i, t in enumerate(expected_tracks): self.assertIsInstance(tracks[i], Track) self.assertEquals(tracks[i].name, expected_tracks[i]) self.assertTrue(tracks[i].length > 500) self.assertEquals(len(tracks[i].artists), 1) self.assertEquals(list(tracks[i].artists)[0].name, 'yndi halda') @my_vcr.use_cassette('sc-liked.yaml') def test_get_user_likes(self): tracks = self.api.get_likes() self.assertEquals(len(tracks), 3) self.assertIsInstance(tracks[0], Track) self.assertEquals(tracks[1].name, 'Pelican - Deny The Absolute') @my_vcr.use_cassette('sc-stream.yaml') def test_get_user_stream(self): tracks = self.api.get_user_stream() self.assertEquals(len(tracks), 10) self.assertIsInstance(tracks[0], Track) self.assertEquals(tracks[2].name, 'JW Ep 20- Jeremiah Watkins') @my_vcr.use_cassette('sc-following.yaml') def test_get_followings(self): users = self.api.get_followings() self.assertEquals(len(users), 10) self.assertEquals(users[0], (u'Young Legionnaire', '992503')) self.assertEquals(users[1], (u'Tall Ships', '1710483')) self.assertEquals(users[8], (u'Pelican Song', '27945548')) self.assertEquals(users[9], (u'sleepmakeswaves', '1739693')) @my_vcr.use_cassette('sc-user-tracks.yaml') def test_get_user_tracks(self): expected_tracks = [ 'The Wait', 'The Cliff (Palms Remix)', 'The Cliff (Justin Broadrick Remix)', 'The Cliff (Vocal Version)', 'Pelican - The Creeper', 'Pelican - Lathe Biosas', 'Pelican - Ephemeral', 'Pelican - Deny the Absolute', 'Pelican - Immutable Dusk', 'Pelican - Strung Up From The Sky' ] tracks = self.api.get_tracks(27945548) for i, t in enumerate(expected_tracks): self.assertIsInstance(tracks[i], Track) self.assertEquals(tracks[i].name, expected_tracks[i]) self.assertTrue(tracks[i].length > 500) self.assertEquals(len(tracks[i].artists), 1) @my_vcr.use_cassette('sc-set.yaml') def test_get_set(self): tracks = self.api.get_set('10961826') self.assertEquals(len(tracks), 1) self.assertIsInstance(tracks[0], dict) @my_vcr.use_cassette('sc-set-invalid.yaml') def test_get_invalid_set(self): tracks = self.api.get_set('blahblahrubbosh') self.assertEquals(tracks, []) @my_vcr.use_cassette('sc-sets.yaml') def test_get_sets(self): sets = self.api.get_sets() self.assertEquals(len(sets), 2) name, set_id, tracks = sets[1] self.assertEquals(name, 'Pelican') self.assertEquals(set_id, '10961826') self.assertEquals(len(tracks), 1) def test_readeble_url(self): self.assertEquals('Barsuk Records', readable_url('"@"Barsuk Records')) self.assertEquals('_Barsuk Records', readable_url('_Barsuk \'Records\'')) @my_vcr.use_cassette('sc-resolve-track-id.yaml') def test_resolves_stream_track(self): track = self.api.get_track('13158665', True) self.assertIsInstance(track, Track) self.assertEquals( track.uri, 'https://cf-media.sndcdn.com/fxguEjG4ax6B.128.mp3?Policy=eyJTdGF0Z' 'W1lbnQiOlt7IlJlc291cmNlIjoiKjovL2NmLW1lZGlhLnNuZGNkbi5jb20vZnhndU' 'VqRzRheDZCLjEyOC5tcDMiLCJDb25kaXRpb24iOnsiRGF0ZUxlc3NUaGFuIjp7IkF' 'XUzpFcG9jaFRpbWUiOjE0Nzc2MDA1NTd9fX1dfQ__&Signature=u9bxAkZOtTTF1' 'VqTmLGmw3ENrqbiSTFK-sMvZL-ZsQK85DOepHh5MfPA4MNooszUy~PZqiVyBn4YnE' 'lhWyb~4B7kS6y0VZ6t-qF78CfTMOimemafpqfWJ8nYXczhM9pUpAwiS--lkNjGks4' 'Qxi-FZJDBPG99gAIU0eVW78CADcpuOKLugGpzHl6gRPN2Z4zZ9dVujZ5MlG2OWnPu' 'NiBcE~wUFwcOxt9N6ePTff-wMFQR2PGpEK6wc6bWuB4WFNBkE0bmEke4cOQjWHa5F' 'wYEidZN5rvv5lVT1r07zzifnADEipwMaZ2-QYdqzOYaM4jymFDhl7DklaU24PY5C5' 'mH0A__&Key-Pair-Id=APKAJAGZ7VMH2PFPW6UQ') @my_vcr.use_cassette('sc-search.yaml') def test_search(self): tracks = self.api.search('the great descent') self.assertEquals(len(tracks), 10) self.assertIsInstance(tracks[0], Track) self.assertEquals(tracks[0].name, 'Turn Around (Mix1)')