def unfollow_user(user_name: str): """ Unfollow the user ``user_name``. A user token (found on https://listenbrainz.org/profile/ ) must be provided in the Authorization header! :reqheader Authorization: Token <user token> :reqheader Content-Type: *application/json* :statuscode 200: Successfully unfollowed the user ``user_name``. :statuscode 401: invalid authorization. See error message for details. :resheader Content-Type: *application/json* """ current_user = validate_auth_header() user = db_user.get_by_mb_id(user_name) if not user: raise APINotFound("User %s not found" % user_name) try: db_user_relationship.delete(current_user["id"], user["id"], "follow") except Exception as e: current_app.logger.error( "Error while trying to delete a relationship: %s", str(e)) raise APIInternalServerError( "Something went wrong, please try again later") return jsonify({"status": "ok"})
def unfollow_user(user_name: str): user = _get_user(user_name) if not db_user_relationship.is_following_user(current_user.id, user.id): raise APIBadRequest(f"{current_user.musicbrainz_id} is not following user {user.musicbrainz_id}") try: db_user_relationship.delete(current_user.id, user.id, 'follow') except Exception: current_app.logger.critical("Error while trying to delete a relationship", exc_info=True) raise APIInternalServerError("Something went wrong, please try again later") return jsonify({"status": 200, "message": "Success!"})
def test_delete(self): db_user_relationship.insert(self.main_user['id'], self.followed_user_1['id'], 'follow') self.assertTrue( db_user_relationship.is_following_user(self.main_user['id'], self.followed_user_1['id'])) db_user_relationship.delete(self.main_user['id'], self.followed_user_1['id'], 'follow') self.assertFalse( db_user_relationship.is_following_user(self.main_user['id'], self.followed_user_1['id']))
def test_delete_raises_value_error_for_invalid_relationships(self): with self.assertRaises(ValueError): db_user_relationship.delete(self.main_user['id'], self.followed_user_1['id'], 'idkwhatrelationshipthisis')