Skip to content
This repository has been archived by the owner on Jun 15, 2022. It is now read-only.

Commit

Permalink
Cleanup bug #119 reproduction script
Browse files Browse the repository at this point in the history
  • Loading branch information
jodal committed May 25, 2015
1 parent 79aac50 commit fb699f6
Showing 1 changed file with 55 additions and 29 deletions.
84 changes: 55 additions & 29 deletions tests/regression/bug_119.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,28 @@
import spotify


if len(sys.argv) != 3:
sys.exit('Usage: %s USERNAME PASSWORD' % sys.argv[0])
logger = logging.getLogger(__name__)


ALBUMS = [
'spotify:album:02Zb13fM8k04tRwTfMUhe9', # OK
'spotify:album:3ph1ceuYuayuzoIJzPQji2', # Fails
'spotify:album:4IBQvwIbtDluogvDe2qpaB', # Fails
'spotify:album:5VppVyy751PTQWrfJbrJ4H', # Fails
'spotify:album:2cRMVS71c49Pf5SnIlJX3U', # OK
'spotify:album:6mulYcpWRDAiv7KIouWvyP', # OK
'spotify:album:02jqf49ws9bcTvXLPGtjbT', # Fails
'spotify:album:17orrZznh0gmxYtpNP47nK', # Fails
'spotify:album:5lnQLEUiVDkLbFJHXHQu9m', # Fails
'spotify:album:3ph1ceuYuayuzoIJzPQji2', # Fails
]

username, password = sys.argv[1], sys.argv[2]

def init():
session = spotify.Session()
loop = spotify.EventLoop(session)
loop.start()
return session


def login(session, username, password):
Expand All @@ -30,35 +48,43 @@ def logged_in_listener(session, error_type):
time.sleep(0.1)


logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
def logout(session):
logged_out_event = threading.Event()

session = spotify.Session()
loop = spotify.EventLoop(session)
loop.start()
def logged_out_listener(session):
logged_out_event.set()

login(session, username, password)
session.on(spotify.SessionEvent.LOGGED_OUT, logged_out_listener)
session.logout()

albums = [
'spotify:album:02Zb13fM8k04tRwTfMUhe9', # OK
'spotify:album:3ph1ceuYuayuzoIJzPQji2', # Fails
'spotify:album:4IBQvwIbtDluogvDe2qpaB', # Fails
'spotify:album:5VppVyy751PTQWrfJbrJ4H', # Fails
'spotify:album:2cRMVS71c49Pf5SnIlJX3U', # OK
'spotify:album:6mulYcpWRDAiv7KIouWvyP', # OK
'spotify:album:02jqf49ws9bcTvXLPGtjbT', # Fails
'spotify:album:17orrZznh0gmxYtpNP47nK', # Fails
'spotify:album:5lnQLEUiVDkLbFJHXHQu9m', # Fails
'spotify:album:3ph1ceuYuayuzoIJzPQji2', # Fails
]
if not logged_out_event.wait(10):
raise RuntimeError('Logout timed out')


def get_albums(session):
logger.info('Getting albums')
for uri in ALBUMS:
logger.info('Loading %s...', uri)
try:
album = session.get_album(uri)
# album.browse() # Add this line, and everything works
logger.info(album.load(3).name)
except spotify.Timeout:
logger.warning('Timeout')


if __name__ == '__main__':
if len(sys.argv) != 3:
sys.exit('Usage: %s USERNAME PASSWORD' % sys.argv[0])

logging.basicConfig(level=logging.INFO)

logger.info('Getting albums')
username, password = sys.argv[1], sys.argv[2]
session = init()
login(session, username, password)

for uri in albums:
logger.info('Loading %s...', uri)
try:
album = session.get_album(uri)
# album.browse() # Add this line, and everything works
logger.info(album.load(30).name)
except spotify.Timeout:
logger.warning('Timeout')
get_albums(session)
logout(session)
except KeyboardInterrupt:
logout(session)

0 comments on commit fb699f6

Please sign in to comment.