Code cleanup
This commit is contained in:
@@ -1,8 +1,6 @@
|
|||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
import re
|
import re
|
||||||
import time
|
|
||||||
|
|
||||||
import pykka
|
import pykka
|
||||||
from mopidy import backend
|
from mopidy import backend
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import re
|
|||||||
from mopidy import backend
|
from mopidy import backend
|
||||||
from mopidy.models import Album, Artist, Ref, SearchResult, Track, Image
|
from mopidy.models import Album, Artist, Ref, SearchResult, Track, Image
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
@@ -46,7 +47,7 @@ class RadioNetLibraryProvider(backend.LibraryProvider):
|
|||||||
album = Album(
|
album = Album(
|
||||||
artists=[artist],
|
artists=[artist],
|
||||||
name=name,
|
name=name,
|
||||||
uri="radionet:station:%s" % (radio_data.id),
|
uri="radionet:station:%s" % radio_data.id,
|
||||||
)
|
)
|
||||||
|
|
||||||
track = Track(
|
track = Track(
|
||||||
@@ -55,7 +56,7 @@ class RadioNetLibraryProvider(backend.LibraryProvider):
|
|||||||
name=radio_data.name,
|
name=radio_data.name,
|
||||||
genre=radio_data.genres,
|
genre=radio_data.genres,
|
||||||
comment=radio_data.description,
|
comment=radio_data.description,
|
||||||
uri="radionet:track:%s" % (radio_data.id),
|
uri="radionet:track:%s" % radio_data.id,
|
||||||
)
|
)
|
||||||
return [track]
|
return [track]
|
||||||
|
|
||||||
@@ -234,7 +235,7 @@ class RadioNetLibraryProvider(backend.LibraryProvider):
|
|||||||
|
|
||||||
def station_to_ref(self, station):
|
def station_to_ref(self, station):
|
||||||
return Ref.track(
|
return Ref.track(
|
||||||
uri="radionet:station:%s" % (station.id),
|
uri="radionet:station:%s" % station.id,
|
||||||
name=station.name,
|
name=station.name,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
import re
|
|
||||||
import time
|
import time
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
@@ -84,7 +83,6 @@ class RadioNetClient(object):
|
|||||||
self.update_prefix()
|
self.update_prefix()
|
||||||
|
|
||||||
def update_prefix(self):
|
def update_prefix(self):
|
||||||
tmp_str = self.session.get(self.base_url)
|
|
||||||
lang = self.base_url.split(".")[-1].replace("/", "")
|
lang = self.base_url.split(".")[-1].replace("/", "")
|
||||||
self.api_prefix = "https://api.radio." + lang + "/info/v2"
|
self.api_prefix = "https://api.radio." + lang + "/info/v2"
|
||||||
|
|
||||||
@@ -446,7 +444,7 @@ class RadioNetClient(object):
|
|||||||
class CacheItem(object):
|
class CacheItem(object):
|
||||||
def __init__(self, value, expires=10):
|
def __init__(self, value, expires=10):
|
||||||
self._value = value
|
self._value = value
|
||||||
self._expires = expires = time.time() + expires * 60
|
self._expires = time.time() + expires * 60
|
||||||
|
|
||||||
def expired(self):
|
def expired(self):
|
||||||
return self._expires < time.time()
|
return self._expires < time.time()
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ from mopidy_radionet import backend
|
|||||||
from mopidy_radionet.radionet import RadioNetClient
|
from mopidy_radionet.radionet import RadioNetClient
|
||||||
from mopidy_radionet.library import RadioNetLibraryProvider
|
from mopidy_radionet.library import RadioNetLibraryProvider
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def backend_mock():
|
def backend_mock():
|
||||||
backend_mock = mock.Mock(spec=backend.RadioNetBackend)
|
backend_mock = mock.Mock(spec=backend.RadioNetBackend)
|
||||||
@@ -15,10 +16,12 @@ def backend_mock():
|
|||||||
backend_mock.radionet.set_favorites({'lush'})
|
backend_mock.radionet.set_favorites({'lush'})
|
||||||
return backend_mock
|
return backend_mock
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def library(backend_mock):
|
def library(backend_mock):
|
||||||
return backend_mock.library
|
return backend_mock.library
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def radionet(backend_mock):
|
def radionet(backend_mock):
|
||||||
return backend_mock.radionet
|
return backend_mock.radionet
|
||||||
|
|||||||
@@ -1,13 +1,12 @@
|
|||||||
from unittest import mock
|
|
||||||
|
|
||||||
|
|
||||||
def test_browse_root(library):
|
def test_browse_root(library):
|
||||||
results = library.browse('radionet:root');
|
results = library.browse('radionet:root')
|
||||||
assert 8 == len(results)
|
assert 8 == len(results)
|
||||||
|
|
||||||
|
|
||||||
def test_browse_localstations(library):
|
def test_browse_localstations(library):
|
||||||
results = library.browse('radionet:localstations');
|
results = library.browse('radionet:localstations')
|
||||||
assert len(results) > 0
|
assert len(results) > 0
|
||||||
|
|
||||||
page_uri = results[0].uri if results is not None else None
|
page_uri = results[0].uri if results is not None else None
|
||||||
@@ -19,12 +18,12 @@ def test_browse_localstations(library):
|
|||||||
|
|
||||||
|
|
||||||
def test_browse_topstations(library):
|
def test_browse_topstations(library):
|
||||||
results = library.browse('radionet:topstations');
|
results = library.browse('radionet:topstations')
|
||||||
assert len(results) > 0
|
assert len(results) > 0
|
||||||
|
|
||||||
|
|
||||||
def test_browse_genres(library):
|
def test_browse_genres(library):
|
||||||
results = library.browse('radionet:genres');
|
results = library.browse('radionet:genres')
|
||||||
assert len(results) > 0
|
assert len(results) > 0
|
||||||
|
|
||||||
cat_uri = results[0].uri if results is not None else None
|
cat_uri = results[0].uri if results is not None else None
|
||||||
@@ -47,7 +46,7 @@ def test_browse_genres(library):
|
|||||||
|
|
||||||
|
|
||||||
def test_browse_topics(library):
|
def test_browse_topics(library):
|
||||||
results = library.browse('radionet:topics');
|
results = library.browse('radionet:topics')
|
||||||
assert len(results) > 0
|
assert len(results) > 0
|
||||||
|
|
||||||
cat_uri = results[0].uri if results is not None else None
|
cat_uri = results[0].uri if results is not None else None
|
||||||
@@ -71,7 +70,7 @@ def test_browse_topics(library):
|
|||||||
|
|
||||||
|
|
||||||
def test_browse_languages(library):
|
def test_browse_languages(library):
|
||||||
results = library.browse('radionet:languages');
|
results = library.browse('radionet:languages')
|
||||||
assert len(results) > 0
|
assert len(results) > 0
|
||||||
|
|
||||||
cat_uri = results[5].uri if results is not None else None
|
cat_uri = results[5].uri if results is not None else None
|
||||||
@@ -95,7 +94,7 @@ def test_browse_languages(library):
|
|||||||
|
|
||||||
|
|
||||||
def test_browse_cities(library):
|
def test_browse_cities(library):
|
||||||
results = library.browse('radionet:cities');
|
results = library.browse('radionet:cities')
|
||||||
assert len(results) > 0
|
assert len(results) > 0
|
||||||
|
|
||||||
cat_uri = results[0].uri if results is not None else None
|
cat_uri = results[0].uri if results is not None else None
|
||||||
@@ -119,7 +118,7 @@ def test_browse_cities(library):
|
|||||||
|
|
||||||
|
|
||||||
def test_browse_countries(library):
|
def test_browse_countries(library):
|
||||||
results = library.browse('radionet:countries');
|
results = library.browse('radionet:countries')
|
||||||
assert len(results) > 0
|
assert len(results) > 0
|
||||||
|
|
||||||
cat_uri = results[0].uri if results is not None else None
|
cat_uri = results[0].uri if results is not None else None
|
||||||
@@ -143,11 +142,10 @@ def test_browse_countries(library):
|
|||||||
|
|
||||||
|
|
||||||
def test_browse_favorites(library):
|
def test_browse_favorites(library):
|
||||||
results = library.browse('radionet:favorites');
|
results = library.browse('radionet:favorites')
|
||||||
assert 1 == len(results)
|
assert 1 == len(results)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def test_search(library):
|
def test_search(library):
|
||||||
result = library.search({'any': ['radio ram']})
|
result = library.search({'any': ['radio ram']})
|
||||||
|
|
||||||
@@ -161,7 +159,6 @@ def test_search(library):
|
|||||||
|
|
||||||
|
|
||||||
def test_lookup(library):
|
def test_lookup(library):
|
||||||
|
|
||||||
results = library.browse('radionet:favorites')
|
results = library.browse('radionet:favorites')
|
||||||
assert 1 == len(results)
|
assert 1 == len(results)
|
||||||
|
|
||||||
@@ -170,7 +167,6 @@ def test_lookup(library):
|
|||||||
|
|
||||||
|
|
||||||
def test_track_by_slug(library):
|
def test_track_by_slug(library):
|
||||||
|
|
||||||
results = library.lookup('radionet:track:dancefm')
|
results = library.lookup('radionet:track:dancefm')
|
||||||
assert 1 == len(results)
|
assert 1 == len(results)
|
||||||
assert results[0].uri == 'radionet:track:2180'
|
assert results[0].uri == 'radionet:track:2180'
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
from unittest import mock
|
|
||||||
|
|
||||||
|
|
||||||
def test_get_genres(radionet):
|
def test_get_genres(radionet):
|
||||||
genres = radionet.get_genres();
|
genres = radionet.get_genres()
|
||||||
assert len(genres) > 0
|
assert len(genres) > 0
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user