def user_info(request, data): """ Gives information about the user specified in the parameters. """ try: api_key = data['api_key'] output_format = data.get('format', 'xml') sk = data.get('sk') username = data.get('user') if not (sk or username): raise KeyError if not Token.is_valid_api_key(api_key): raise InvalidAPIUsage( CompatError.INVALID_API_KEY, output_format=output_format) # Invalid API key user = User.load_by_sessionkey(sk, api_key) if not user: raise InvalidAPIUsage( CompatError.INVALID_SESSION_KEY, output_format=output_format) # Invalid Session key query_user = User.load_by_name(username) if ( username and username != user.name) else user if not query_user: raise InvalidAPIUsage( CompatError.INVALID_RESOURCE, output_format=output_format) # Invalid resource specified except KeyError: raise InvalidAPIUsage( CompatError.INVALID_PARAMETERS, output_format=output_format) # Missing required params doc, tag, text = Doc().tagtext() with tag('lfm', status='ok'): with tag('user'): with tag('name'): text(query_user.name) with tag('realname'): text(query_user.name) with tag('url'): text('http://listenbrainz.org/user/' + query_user.name) with tag('playcount'): text(User.get_play_count(query_user.id)) with tag('registered', unixtime=str(query_user.created.strftime("%s"))): text(str(query_user.created)) return format_response( '<?xml version="1.0" encoding="utf-8"?>\n' + yattag.indent(doc.getvalue()), data.get('format', "xml"))
def user_info(request, data): """ Gives information about the user specified in the parameters. """ try: api_key = data['api_key'] output_format = data.get('format', 'xml') sk = data.get('sk') username = data.get('user') if not (sk or username): raise KeyError if not Token.is_valid_api_key(api_key): raise InvalidAPIUsage(10, output_format=output_format) # Invalid API key user = User.load_by_sessionkey(sk, api_key) if not user: raise InvalidAPIUsage(9, output_format=output_format) # Invalid Session key query_user = User.load_by_name(username) if (username and username != user.name) else user if not query_user: raise InvalidAPIUsage(7, output_format=output_format) # Invalid resource specified except KeyError: raise InvalidAPIUsage(6, output_format=output_format) # Missing required params doc, tag, text = Doc().tagtext() with tag('lfm', status='ok'): with tag('user'): with tag('name'): text(query_user.name) with tag('realname'): text(query_user.name) with tag('url'): text('http://listenbrainz.org/user/' + query_user.name) with tag('playcount'): text(User.get_play_count(query_user.id)) with tag('registered', unixtime=str(query_user.created.strftime("%s"))): text(str(query_user.created)) return format_response('<?xml version="1.0" encoding="utf-8"?>\n' + yattag.indent(doc.getvalue()), data.get('format', "xml"))
def test_user_get_play_count(self): count = User.get_play_count(self.user.id) self.assertEqual(count, 100)
def test_user_get_play_count(self): count = User.get_play_count(self.user.id) self.assertEqual(count, 100)