Skip to content

Commit

Permalink
Add soundcloud fixtures
Browse files Browse the repository at this point in the history
  • Loading branch information
dz0ny committed Jan 2, 2015
1 parent 4f49243 commit a2851ac
Show file tree
Hide file tree
Showing 23 changed files with 1,514 additions and 20 deletions.
3 changes: 2 additions & 1 deletion .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
omit =
*/pyshared/*
*/python?.?/*
*/site-packages/nose/*
*/site-packages/nose/*
*/site-packages/mopidy/*
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ build/
cover
dist/
xunit-*.xml
cover-*.xml
8 changes: 4 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
language: python

python:
- "2.7_with_system_site_packages"
- "2.7"

env:
- TOX_ENV=py27
Expand All @@ -10,9 +10,9 @@ env:
install:
- "wget -O - http://apt.mopidy.com/mopidy.gpg | sudo apt-key add -"
- "sudo wget -O /etc/apt/sources.list.d/mopidy.list http://apt.mopidy.com/mopidy.list"
- "sudo apt-get update || true"
- "sudo apt-get install mopidy-soundcloud"
- "pip install tox"
- "sudo apt-get update -qf --force-yes || true"
- "sudo apt-get install -qf --force-yes mopidy-soundcloud"
- "sudo pip install tox"

script:
- "tox -e $TOX_ENV"
Expand Down
2 changes: 1 addition & 1 deletion mopidy_soundcloud/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def get_config_schema(self):
schema['explore_pages'] = config.Deprecated()
return schema

def validate_config(self, config):
def validate_config(self, config): # no_coverage
if not config.getboolean('soundcloud', 'enabled'):
return
if not config.get('soundcloud', 'auth_token'):
Expand Down
15 changes: 9 additions & 6 deletions mopidy_soundcloud/soundcloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class SoundCloudClient(object):
def __init__(self, config):
super(SoundCloudClient, self).__init__()
token = config['auth_token']
self.explore_songs = config['explore_songs']
self.explore_songs = config.get('explore_songs', 10)
self.http_client = requests.Session()
self.http_client.headers.update({'Authorization': 'OAuth %s' % token})

Expand Down Expand Up @@ -113,10 +113,13 @@ def get_explore_categories(self):
def get_explore(self, query_explore_id=None):
explore = self.get_explore_categories()
if query_explore_id:
urn = explore[int(query_explore_id)]
web_tracks = self._get(
'explore/%s?tag=%s&limit=%s&offset=0&linked_partitioning=1' % (
urn, 'out-of-experiment', self.explore_songs), 'api-v2')

url = 'explore/{urn}?limit={limit}&offset=0&linked_partitioning=1'\
.format(
urn=explore[int(query_explore_id)],
limit=self.explore_songs
)
web_tracks = self._get(url, 'api-v2')
track_ids = map(lambda x: x.get('id'), web_tracks.get('tracks'))
return self.resolve_tracks(track_ids)
return explore
Expand Down Expand Up @@ -316,7 +319,7 @@ def resolve_tracks(self, track_ids):
:param track_ids:list of track ids
:return:list `Track`
"""
pool = ThreadPool(processes=6)
pool = ThreadPool(processes=16)
tracks = pool.map(self.resolve_track, track_ids)
pool.close()
return tracks
Expand Down
8 changes: 7 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,14 @@ def get_version(filename):
'Pykka >= 1.1',
'requests >= 2.0.0',
],
test_suite='nose.collector',
tests_require=[
'nose',
'mock >= 1.0',
'vcrpy',
],
entry_points={
b'mopidy.ext': [
'mopidy.ext': [
'soundcloud = mopidy_soundcloud:SoundCloudExtension',
],
},
Expand Down
32 changes: 32 additions & 0 deletions tests/fixtures/sc-explore.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
interactions:
- request:
body: null
headers:
Accept: ['*/*']
Accept-Encoding: ['gzip, deflate']
Authorization: [!!python/unicode 'OAuth 1-35204-61921957-55796ebef403996']
Connection: [keep-alive]
User-Agent: [python-requests/2.4.3 CPython/2.7.8 Linux/3.16.0-28-generic]
method: GET
uri: https://api-v2.soundcloud.com:443/explore/categories?client_id=93e33e327fd8a9b77becd179652272e2
response:
body:
string: !!binary |
H4sIAAAAAAAAAExRwU7DMAz9l0qcOi4cOHBjK2gghqp1Ege0Q5ZaxVpqV07CtCH+nTjdOk5+fkme
n19+ChNb5OLhs6h5iM5I+ZiJWZHrjnnvUzOPHgm8wgX30B4TeKIAEgxSDxRS/wZGCKlL8B0Ovry5
uy9rdhjQ6rs1OOyQKfPNgIIhmnSqUo1FIAuKBpag15vAcgzg3Ki4AftF7Lg7FttZ0Sc79r/pVSaS
aZc8kQn4DeWa7V6pfoejwYUzPl0zLm8RKYjOrsw4uQIYyiVHnxv0VkOoJPbZ8Nzk5au48wEG3d6B
DcJXRNnAMzsdujTSWhYoR9/KoKrry8uMF2pxcvlqTifNMFmnVFcQss0VEvbGXWVqNGPNUrVwJ+lb
dN2LbB1JBdfJ9VyrGXL4XWf09DyuSamC3DZM3SF9BIhyHN056UlsmruRc0wJDLlM+3ywuLbY/v4B
AAD//wMAP61+EEwCAAA=
headers:
cache-control: ['private, max-age=0']
content-encoding: [gzip]
content-length: ['356']
content-type: [application/json]
date: ['Fri, 02 Jan 2015 17:03:44 GMT']
server: [am/2]
set-cookie: [_session_auth_key="iuo9QNN6oaPVa3gj9XyKTHZtsxE="]
vary: [Origin]
status: {code: 200, message: OK}
version: 1
29 changes: 29 additions & 0 deletions tests/fixtures/sc-following.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
interactions:
- request:
body: null
headers:
Accept: ['*/*']
Accept-Encoding: ['gzip, deflate']
Authorization: [!!python/unicode 'OAuth 1-35204-61921957-55796ebef403996']
Connection: [keep-alive]
User-Agent: [python-requests/2.4.3 CPython/2.7.8 Linux/3.16.0-28-generic]
method: GET
uri: https://api.soundcloud.com:443/me/followings.json?limit=60&client_id=93e33e327fd8a9b77becd179652272e2
response:
body:
string: !!binary |
H4sIAAAAAAAEA4uOBQApu0wNAgAAAA==
headers:
access-control-allow-headers: ['Accept, Authorization, Content-Type, Origin']
access-control-allow-methods: ['GET, PUT, POST, DELETE']
access-control-allow-origin: ['*']
access-control-expose-headers: [Date]
cache-control: ['private, max-age=0, must-revalidate']
content-encoding: [gzip]
content-length: ['22']
content-type: [application/json; charset=utf-8]
date: ['Fri, 02 Jan 2015 17:03:52 GMT']
etag: ['"d751713988987e9331980363e24189ce"']
server: [am/2]
status: {code: 200, message: OK}
version: 1
29 changes: 29 additions & 0 deletions tests/fixtures/sc-groups.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
interactions:
- request:
body: null
headers:
Accept: ['*/*']
Accept-Encoding: ['gzip, deflate']
Authorization: [!!python/unicode 'OAuth 1-35204-61921957-55796ebef403996']
Connection: [keep-alive]
User-Agent: [python-requests/2.4.3 CPython/2.7.8 Linux/3.16.0-28-generic]
method: GET
uri: https://api.soundcloud.com:443/me/groups.json?client_id=93e33e327fd8a9b77becd179652272e2
response:
body:
string: !!binary |
H4sIAAAAAAAEA4uOBQApu0wNAgAAAA==
headers:
access-control-allow-headers: ['Accept, Authorization, Content-Type, Origin']
access-control-allow-methods: ['GET, PUT, POST, DELETE']
access-control-allow-origin: ['*']
access-control-expose-headers: [Date]
cache-control: ['private, max-age=0, must-revalidate']
content-encoding: [gzip]
content-length: ['22']
content-type: [application/json; charset=utf-8]
date: ['Fri, 02 Jan 2015 17:03:54 GMT']
etag: ['"d751713988987e9331980363e24189ce"']
server: [am/2]
status: {code: 200, message: OK}
version: 1
29 changes: 29 additions & 0 deletions tests/fixtures/sc-liked.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
interactions:
- request:
body: null
headers:
Accept: ['*/*']
Accept-Encoding: ['gzip, deflate']
Authorization: [!!python/unicode 'OAuth 1-35204-61921957-55796ebef403996']
Connection: [keep-alive]
User-Agent: [python-requests/2.4.3 CPython/2.7.8 Linux/3.16.0-28-generic]
method: GET
uri: https://api.soundcloud.com:443/e1/me/likes.json?limit=1000&client_id=93e33e327fd8a9b77becd179652272e2
response:
body:
string: !!binary |
H4sIAAAAAAAEA4uOBQApu0wNAgAAAA==
headers:
access-control-allow-headers: ['Accept, Authorization, Content-Type, Origin']
access-control-allow-methods: ['GET, PUT, POST, DELETE']
access-control-allow-origin: ['*']
access-control-expose-headers: [Date]
cache-control: ['private, max-age=0, must-revalidate']
content-encoding: [gzip]
content-length: ['22']
content-type: [application/json; charset=utf-8]
date: ['Fri, 02 Jan 2015 17:03:54 GMT']
etag: ['"d751713988987e9331980363e24189ce"']
server: [am/2]
status: {code: 200, message: OK}
version: 1
29 changes: 29 additions & 0 deletions tests/fixtures/sc-login-error.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
interactions:
- request:
body: null
headers:
Accept: ['*/*']
Accept-Encoding: ['gzip, deflate']
Authorization: [!!python/unicode 'OAuth 1-fake-token']
Connection: [keep-alive]
User-Agent: [python-requests/2.4.3 CPython/2.7.8 Linux/3.16.0-28-generic]
method: GET
uri: https://api.soundcloud.com:443/me.json?client_id=93e33e327fd8a9b77becd179652272e2
response:
body:
string: !!binary |
H4sIAAAAAAAAAFIAAAAA//8DAEXPbOkBAAAA
headers:
access-control-allow-headers: ['Accept, Authorization, Content-Type, Origin']
access-control-allow-methods: ['GET, PUT, POST, DELETE']
access-control-allow-origin: ['*']
access-control-expose-headers: [Date]
cache-control: [no-cache]
content-encoding: [gzip]
content-length: ['27']
content-type: [text/html; charset=utf-8]
date: ['Fri, 02 Jan 2015 16:59:28 GMT']
server: [am/2]
www-authenticate: ['OAuth realm="SoundCloud", error="invalid_token"']
status: {code: 401, message: Unauthorized}
version: 1
36 changes: 36 additions & 0 deletions tests/fixtures/sc-login.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
interactions:
- request:
body: null
headers:
Accept: ['*/*']
Accept-Encoding: ['gzip, deflate']
Authorization: [!!python/unicode 'OAuth 1-35204-61921957-55796ebef403996']
Connection: [keep-alive]
User-Agent: [python-requests/2.4.3 CPython/2.7.8 Linux/3.16.0-28-generic]
method: GET
uri: https://api.soundcloud.com:443/me.json?client_id=93e33e327fd8a9b77becd179652272e2
response:
body:
string: !!binary |
H4sIAAAAAAAEA21SW27jMAy8SqHfDWKr2W63PkAvUSwERqKzRPRwRamFUfTuSztO1knrH0NDcmb4
+FDkVPdLP93rp4fHjTpSlLeqjFlt1IA5gKd4FCikgdxYkMsSnH4RAn4X88DFhOSoJ5z47lu9a3Tb
6N2d1t3PXbd7uPvRyiciNZNk/C1l4K5pYKAtpxqd9am6rU2hmYS4OXtc2zI1+6VWSm/KvhiGNyiQ
VzWznt6yiLk4S1GAA3LjsIfqi1kqPOQDbod4EG0r3koeVRer9xvVU5ZOT2M4IXPra6CXxCVDCYFD
tpmGQimeSSyVC6EjtunAV5Rh5AEsXmHvuGcqMvyT6vI0hYq/gCnK7uTVg2fcqJLBHs3cgOpa2a6H
0ZPYv4LElXrOiNOc696TNT28pSxavErsk/fpXfbyBaMo7v8zct1f+mXVvfyRhQ8+gTOMNkXHxmNf
VKfb3614eq2pgOo+VBXvQUSdWdKXyNLLDYeciJyZ1N/gK+5P6SeTnACaeRBrk+fAeSI3sQB5NBiA
vDQWZeVhUiu54uc/Eg4T/0ADAAA=
headers:
access-control-allow-headers: ['Accept, Authorization, Content-Type, Origin']
access-control-allow-methods: ['GET, PUT, POST, DELETE']
access-control-allow-origin: ['*']
access-control-expose-headers: [Date]
cache-control: ['private, max-age=0, must-revalidate']
content-encoding: [gzip]
content-length: ['419']
content-type: [application/json; charset=utf-8]
date: ['Fri, 02 Jan 2015 16:59:22 GMT']
etag: ['"60fdab535961251305a18c8122b7f406"']
server: [am/2]
status: {code: 200, message: OK}
version: 1
Loading

0 comments on commit a2851ac

Please sign in to comment.