1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
|
import unittest
import pykka
from mopidy.models import Ref
from mopidy_soundcloud import Extension, actor
from mopidy_soundcloud.library import (
SoundCloudLibraryProvider,
new_folder,
simplify_search_query,
)
from mopidy_soundcloud.soundcloud import safe_url
class ApiTest(unittest.TestCase):
def setUp(self):
config = Extension().get_config_schema()
config["auth_token"] = "1-35204-61921957-55796ebef403996"
# using this user http://maildrop.cc/inbox/mopidytestuser
self.backend = actor.SoundCloudBackend.start(
config={"soundcloud": config, "proxy": {}}, audio=None
).proxy()
self.library = SoundCloudLibraryProvider(backend=self.backend)
def tearDown(self):
pykka.ActorRegistry.stop_all()
def test_add_folder(self):
assert new_folder("Test", ["test"]) == Ref(
name="Test", type="directory", uri="soundcloud:directory:test"
)
def test_mpc_search(self):
assert (
simplify_search_query({"any": ["explosions in the sky"]})
== "explosions in the sky"
)
def test_moped_search(self):
assert (
simplify_search_query(
{
"track_name": ["explosions in the sky"],
"any": ["explosions in the sky"],
}
)
== "explosions in the sky explosions in the sky"
)
def test_simple_search(self):
assert (
simplify_search_query("explosions in the sky")
== "explosions in the sky"
)
def test_aria_search(self):
assert (
simplify_search_query(["explosions", "in the sky"])
== "explosions in the sky"
)
def test_only_resolves_soundcloud_uris(self):
assert (
self.library.search(
{"uri": "http://www.youtube.com/watch?v=wD6H6Yhluo8"}
)
is None
)
def test_returns_url_safe_string(self):
assert (
safe_url("Alternative/Indie/rock/pop ")
== "Alternative%2FIndie%2Frock%2Fpop+"
)
assert (
safe_url("D∃∃P Hau⑀ iNDiE DᴬNCE | №➊ ²⁰¹⁴")
== "DP+Hau+iNDiE+DANCE+%7C+No+2014"
)
def test_default_folders(self):
assert self.library.browse("soundcloud:directory") == [
Ref(
name="Following",
type="directory",
uri="soundcloud:directory:following",
),
Ref(
name="Liked", type="directory", uri="soundcloud:directory:liked"
),
Ref(name="Sets", type="directory", uri="soundcloud:directory:sets"),
Ref(
name="Stream",
type="directory",
uri="soundcloud:directory:stream",
),
]
|