def get_likes(): """Gets verified user's liked songs""" id_token = flask.request.headers['Authorization'].split(' ').pop() if not firebase.logged_in(id_token): return flask.abort(401, 'User not logged in!') likes = bigquery.get_likes(id_token) return flask.jsonify(likes)
def delete_like(): """Deletes song from verified user's list of liked songs.""" id_token = flask.request.headers['Authorization'].split(' ').pop() if not firebase.logged_in(id_token): return flask.abort(401, 'User not logged in!') like = json.loads(flask.request.args.get('data')) unlike = firebase.unlike_song(like) return flask.jsonify(unlike)
def post_like(): """Adds song to verified user's list of liked songs.""" id_token = flask.request.headers['Authorization'].split(' ').pop() if not firebase.logged_in(id_token): return flask.abort(401, 'User not logged in!') song = flask.request.get_json() like = firebase.like_song(id_token, song) return flask.jsonify(like)
def get_recommendation(): """Recommends a song via Genius API to the verified user""" id_token = flask.request.headers['Authorization'].split(' ').pop() if not firebase.logged_in(id_token): return flask.abort(401, 'User not logged in!') time_of_day = flask.request.args.get('time_of_day') likes = bigquery.get_likes(id_token) song = bigquery.get_song(time_of_day, likes) return flask.jsonify(song)
def test_not_logged_in(self, mock_verify_id_token): """Test checking if a user is _not_ logged in""" mock_verify_id_token.side_effect = \ auth.InvalidIdTokenError('InvalidIdTokenError') logged_in = firebase.logged_in(self.id_token) self.assertFalse(logged_in)
def test_logged_in(self, mock_verify_id_token): """Test checking if a user is logged in""" mock_verify_id_token.return_value = self.jwt logged_in = firebase.logged_in(self.id_token) self.assertTrue(logged_in)