<jupyter_start><jupyter_text>Core Wantlist Requests> Core.rq_wantlist is a collection of function wrappers around the Discogs API for interacting with the wantlist of a given user.<jupyter_code>#export
import requests
from typing import Union
from discogspy.core import *
#export


def get_user_wantlist(user: Union[UserWithoutAuthentication,
                                  UserWithUserTokenBasedAuthentication],
                      username: str,
                      page: Union[int, None] = None,
                      per_page: Union[int, None] = None,
                      ) -> requests.models.Response:
    """
    Get a list of releases from the wantlist for the given user. 
    
    Note: If the wantlist has been made private by its owner, 
          you must be authenticated as the owner to view it.
    
    No user Authentication needed. 
    
    Parameters:
    
    user: user object (required)
    
    username: string (required) 
        -> The username of the wantlist you are trying to fetch.
        
    page: number (optional) 
        -> The page you want to request.
        
    per_page: number (optional)
        -> The number of items per page.
    """
    
    url = f"{USERS_URL}/{username}/wants"
    headers = user.headers
    params = user.params
    
    if page:
        params["page"] = max(1, page)
    if per_page:
        params["per_page"] = max(1, per_page)
    
    return requests.get(url, headers=headers, params=params)
# Example for usage of get_user_wantlist
get_user_wantlist(user=example_user, 
                  username="discogspy", 
                  page=1, 
                  per_page=3)
#hide

@responses.activate
def test_get_user_wantlist___authentication_none():
    test_user = UserWithoutAuthentication()
    
    target_url = f"{USERS_URL}/user_name/wants?page=1&per_page=3"
    
    result_content = {"TestWantlist": "TestContent"}
    
    responses.add(responses.GET, target_url,
                  json=result_content, status=200)

    resp = get_user_wantlist(user=test_user, username="user_name", page=1, per_page=3)

    assert resp.json() == result_content
    assert len(responses.calls) == 1
    assert responses.calls[0].request.url == target_url

test_get_user_wantlist___authentication_none()

@responses.activate
def test_get_user_wantlist___authentication_user_token():
    test_user = UserWithUserTokenBasedAuthentication(user_token="<PASSWORD>",
                                                     user_agent="test_user_agent")

    target_url = f"{USERS_URL}/user_name/wants?token=test_user_token&page=1&per_page=3"
        
    result_content = {"TestWantlist": "TestContent"}
    
    responses.add(responses.GET, target_url,
                  json=result_content, status=200)

    resp = get_user_wantlist(user=test_user, username="user_name", page=1, per_page=3)

    assert resp.json() == result_content
    assert len(responses.calls) == 1
    assert responses.calls[0].request.url == target_url
    
test_get_user_wantlist___authentication_user_token()
#export


def add_release_to_wantlist(user: UserWithUserTokenBasedAuthentication,
                            username: str,
                            release_id: int,
                            notes: Union[str, None] = None,
                            rating: Union[int, None] = None
                            ) -> requests.models.Response:
    """
    Add a releases to the wantlist of the given user. 
    
    User Authentication needed. 
    
    Parameters:
    
    user: user object (required)
    
    username: string (required) 
        -> The username of the wantlist you are trying to fetch.
        
    release_id: number (required) 
        -> The ID of the release you are adding.
        
    notes: string (optional)
        -> User notes to associate with this release.
        
    rating: number (optional) 
        -> User’s rating of this release, from 0 (unrated) to 5 (best). Defaults to 0.      
    """
    
    url = f"{USERS_URL}/{username}/wants/{release_id}"
    headers = user.headers
    params = user.params
    
    data = {}    
    if rating:
        rating = min(max(0, rating), 5)
        data["rating"] = rating
    if notes:
        data["notes"] = notes
    
    return requests.put(url, headers=headers, params=params, json=data)
# Example for add_release_to_wantlist
add_release_to_wantlist(user=example_user, 
                        username="discogspy", 
                        release_id=1995816, 
                        notes="perfect album", 
                        rating=5)
#hide

@responses.activate
def test_add_release_to_wantlist___authentication_user_token():
    test_user = UserWithUserTokenBasedAuthentication(user_token="<PASSWORD>",
                                                     user_agent="test_user_agent")

    target_url = f"{USERS_URL}/user_name/wants/123456?token=test_user_token"
        
    result_content = {"TestWantlist": "TestContent"}
    
    responses.add(responses.PUT, target_url,
                  json=result_content, status=201)

    resp = add_release_to_wantlist(user=test_user, username="user_name", release_id=123456, 
                                   notes="test_note", rating=5)

    assert resp.json() == result_content
    assert len(responses.calls) == 1
    assert responses.calls[0].request.url == target_url
    
test_add_release_to_wantlist___authentication_user_token()
#export


def change_notes_of_a_release_from_wantlist(user: UserWithUserTokenBasedAuthentication,
                                            username: str,
                                            release_id: int,
                                            notes: str
                                            ) -> requests.models.Response:
    """
    Change the notes of a releases from the wantlist for the given user. 
    
    User Authentication needed. 
    
    Parameters:
    
    user: user object (required)
    
    username: string (required) 
        -> The username of the wantlist you are trying to fetch.
        
    release_id: number (required) 
        -> The ID of the release you are modifying.
        
    notes: string (required)
        -> Updated user notes to associate with this release.
    """
    
    url = f"{USERS_URL}/{username}/wants/{release_id}"
    headers = user.headers
    params = user.params
       
    data = {"notes": notes}
    
    return requests.post(url, headers=headers, params=params, json=data)
# Example for change_notes_of_a_release_from_wantlist
change_notes_of_a_release_from_wantlist(user=example_user, 
                                        username="discogspy", 
                                        release_id=1995816, 
                                        notes="one of the greatest albums of all time")
#hide

@responses.activate
def test_change_notes_of_a_release_from_wantlist___authentication_user_token():
    test_user = UserWithUserTokenBasedAuthentication(user_token="test_user_token",
                                                     user_agent="test_user_agent")

    target_url = f"{USERS_URL}/user_name/wants/123456?token=test_user_token"
        
    result_content = {"TestWantlist": "TestContent"}
    
    responses.add(responses.POST, target_url,
                  json=result_content, status=200)

    resp = change_notes_of_a_release_from_wantlist(user=test_user, username="user_name", 
                                                   release_id=123456, notes="test_note")

    assert resp.json() == result_content
    assert len(responses.calls) == 1
    assert responses.calls[0].request.url == target_url
    
test_change_notes_of_a_release_from_wantlist___authentication_user_token()
#export


def change_rating_of_a_release_from_wantlist(user: UserWithUserTokenBasedAuthentication,
                                             username: str,
                                             release_id: int,
                                             rating: int
                                             ) -> requests.models.Response:
    """
    Change the rating of a releases from the wantlist of the given user. 
    
    User Authentication needed. 
    
    Parameters:
    
    user: user object (required)
    
    username: string (required) 
        -> The username of the wantlist you are trying to fetch.
        
    release_id: number (required) 
        -> The ID of the release you are modifying.
        
    rating: number (optional) 
        -> Updated user rating of this release, from 0 (unrated) to 5 (best). Defaults to 0. 
    """
    
    url = f"{USERS_URL}/{username}/wants/{release_id}"
    headers = user.headers
    params = user.params
       
    rating = min(max(0, rating), 5)
    data = {"rating": rating}
    
    return requests.post(url, headers=headers, params=params, json=data)
# Example for change_rating_of_a_release_from_wantlist
change_rating_of_a_release_from_wantlist(user=example_user, 
                                         username="discogspy", 
                                         release_id=1995816, 
                                         rating=5)
#hide

@responses.activate
def test_change_rating_of_a_release_from_wantlist___authentication_user_token():
    test_user = UserWithUserTokenBasedAuthentication(user_token="test_<PASSWORD>_token",
                                                     user_agent="test_user_agent")

    target_url = f"{USERS_URL}/user_name/wants/123456?token=test_user_token"
        
    result_content = {"TestWantlist": "TestContent"}
    
    responses.add(responses.POST, target_url,
                  json=result_content, status=200)

    resp = change_rating_of_a_release_from_wantlist(user=test_user, username="user_name", 
                                                   release_id=123456, rating=5)

    assert resp.json() == result_content
    assert len(responses.calls) == 1
    assert responses.calls[0].request.url == target_url
    
test_change_rating_of_a_release_from_wantlist___authentication_user_token()
#export


def delete_release_from_wantlist(user: UserWithUserTokenBasedAuthentication,
                                 username: str,
                                 release_id: int
                                 ) -> requests.models.Response:
    """
    Delete a releases from the wantlist of the given user. 
    
    User Authentication needed. 
    
    Parameters:
    
    user: user object (required)
    
    username: string (required) 
        -> The username of the wantlist you are trying to fetch.
        
    release_id: number (required) 
        -> The ID of the release you are deleting.
    """
    
    url = f"{USERS_URL}/{username}/wants/{release_id}"
    headers = user.headers  
    params = user.params

    return requests.delete(url, headers=headers, params=params)
# Example for delete_release_from_wantlist
delete_release_from_wantlist(user=example_user, 
                             username="discogspy", 
                             release_id=1995816)
#hide

@responses.activate
def test_delete_release_from_wantlist___authentication_user_token():
    test_user = UserWithUserTokenBasedAuthentication(user_token="<PASSWORD>",
                                                     user_agent="test_user_agent")

    target_url = f"{USERS_URL}/user_name/wants/123456?token=test_user_token"
        
    result_content = {"TestWantlist": "TestContent"}
    
    responses.add(responses.DELETE, target_url,
                  json=result_content, status=204)

    resp = delete_release_from_wantlist(user=test_user, username="user_name", release_id=123456)

    assert resp.json() == result_content
    assert len(responses.calls) == 1
    assert responses.calls[0].request.url == target_url
    
test_delete_release_from_wantlist___authentication_user_token()
#hide

from nbdev.export import *
notebook2script()<jupyter_output>Converted 00_core.constants.ipynb.
Converted 01_core.discogs_user.ipynb.
Converted 02_core.rq_database.ipynb.
Converted 03_core.rq_marketplace.ipynb.
Converted 04_core.rq_inventory_export.ipynb.
Converted 05_core.rq_inventory_upload.ipynb.
Converted 06_core.rq_collection.ipynb.
Converted 07_core.rq_wantlist.ipynb.
Converted index.ipynb.
{'fraction_non_alphanumeric': 0.08140482398956975, 'fraction_numerical': 0.012141460234680573, 'mean_word_length': 2.20276617954071, 'pattern_counts': {'":': 8, '<': 8, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 44, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '605395', 'license': 'Apache-2.0', 'n_tokens_mistral': 3537, 'n_tokens_neox': 3359, 'n_words': 736, 'path': 'nbs/07_core.rq_wantlist.ipynb', 'repo_name': 'cpow-89/discogspy', 'size': '12281'}