def test_user_get_play_count(self): date = datetime(2015, 9, 3, 0, 0, 0) test_data = generate_data(date, 100, self.user.name) self.assertEqual(len(test_data), 100) self.logstore.insert(test_data) count = User.get_play_count(self.user.id, self.logstore) self.assertEqual(count, 100)
def test_user_get_play_count(self): date = datetime(2015, 9, 3, 0, 0, 0) test_data = generate_data(date, 100, self.user.name) self.assertEqual(len(test_data), 100) self.logstore.insert(test_data) count = User.get_play_count(self.user.id, self.logstore) self.assertEqual(count, 100)
def user_info(request, data): """ Gives information about the user specified in the parameters. """ try: output_format = data.get('format', 'xml') api_key = data['api_key'] 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, timescale_connection._ts)) 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(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, _influx)) 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.logstore) self.assertEqual(count, 100)