示例#1
0
def test_member_watchlist():
    # set up
    LBXD_USERNAME, LBXD_PASSWORD = load_user_pass()
    lbxd = Letterboxd()
    test_user = lbxd.user(LBXD_USERNAME, LBXD_PASSWORD)
    # get the watchlist
    member_id = test_user.me["member"]["id"]
    logging.debug(f"member_id: {member_id}")
    assert isinstance(member_id, str)
    member = lbxd.member(member_id=member_id)
    logging.debug(f"member: {member}")
    assert isinstance(member, Member)
    # watchlist_request
    watchlist_request = {"perPage": 20}
    films_response = member.watchlist(watchlist_request=watchlist_request)
    logging.debug(f"films_response (watchlist): {films_response}")
    assert isinstance(films_response, dict)
    assert set(films_response_keys()).issubset(
        films_response.keys()), "All keys should be in the FilmsResponse"
    # Test the first movie in the watchlist
    if len(films_response["items"]) > 0:
        film_summary = films_response["items"][0]
        logging.debug(f"film_summary: {film_summary}")
        logging.debug(f"film_summary.keys(): {film_summary.keys()}")
        assert set(film_summary_keys()).issubset(
            film_summary.keys()), "All keys should be in the FilmSummary"
示例#2
0
def test_user_me():
    LBXD_USERNAME, LBXD_PASSWORD = load_user_pass()
    lbxd = Letterboxd()
    # login
    test_user = lbxd.user(LBXD_USERNAME, LBXD_PASSWORD)
    me_dict = test_user.me
    logging.debug(f"me_dict: {me_dict}")
    assert isinstance(me_dict, dict)
示例#3
0
def test_user_auth():
    LBXD_USERNAME, LBXD_PASSWORD = load_user_pass()
    lbxd = Letterboxd()
    # make login
    test_user = lbxd.user(LBXD_USERNAME, LBXD_PASSWORD)
    assert isinstance(test_user, User)
    test_token = test_user.token
    logging.debug(f"test_user.token: {test_token}")
    assert isinstance(test_token, str)
    assert lbxd.api.user.token is test_token
示例#4
0
def test_list_report():
    LBXD_USERNAME, LBXD_PASSWORD = load_user_pass()
    lbxd = letterboxd.new()
    lbxd.user(LBXD_USERNAME, LBXD_PASSWORD)
    list_id = "1UxUo"  # test_optical: "These are Twenty Films to Test With"
    report_list_request = {"reason": "Other", "message": "TEST — IGNORE"}

    list = lbxd.list(list_id=list_id)
    success = list.report(list_id=list_id,
                          report_list_request=report_list_request)
    logging.debug(f"success: {success}")
    assert success is True
示例#5
0
def test_film_report():
    LBXD_USERNAME, LBXD_PASSWORD = load_user_pass()
    lbxd = Letterboxd()
    # login, even though we don't use this value
    lbxd.user(LBXD_USERNAME, LBXD_PASSWORD)
    film_instance = lbxd.film(film_id="9mMS")  # Kirk Cameron’s Saving Christmas
    report_film_request = {"reason": "Other", "message": "TEST — IGNORE"}
    success = film_instance.report(
        film_id="9mMS", report_film_request=report_film_request
    )
    logging.debug(f"success: {success}")
    assert success is True
示例#6
0
def test_create_and_delete_list():
    """
    /lists [POST]
    """
    lbxd = letterboxd.new()
    # Login
    LBXD_USERNAME, LBXD_PASSWORD = load_user_pass()
    lbxd.user(LBXD_USERNAME, LBXD_PASSWORD)
    list_creation_request = {
        "published":
        True,
        "name":
        f"Top Two Movies in this Test List {datetime.datetime.now().isoformat()}",
        "ranked":
        True,
        "description":
        "This is the description that I'm testing with.",
        # "clonedFrom": ""
        "tags": ["API", "test"],
        "entries": [
            {
                "film": "2bbs",
                "rank": 2,
                "notes": "Here are the notes for Raiders",
                "containsSpoilers": True,
            },
            {
                "film": "23c8",
                "rank": 1,
                "notes": "This should be #1, KKBB",
                "containsSpoilers": False,
            },
        ],  # ListCreateEntry
        # "share": "Facebook"
    }
    list_create_response = lbxd.create_list(
        list_creation_request=list_creation_request)
    assert isinstance(list_create_response, dict)
    logging.debug("-------------------------\nlist_create_response:")
    logging.debug(pprint.pformat(list_create_response))
    logging.debug(f"list_create_response.keys() {list_create_response.keys()}")
    assert set(list_create_response_keys()).issubset(list_create_response.keys(
    )), "All keys should be in the lists_response."

    # Clean up and delete this list
    created_list_id = list_create_response["data"]["id"]
    logging.debug(f"created_list_id: {created_list_id}")
    list = lbxd.list(created_list_id)
    success = list.delete(created_list_id)
    assert success == True
示例#7
0
def test_film_patch_me():
    LBXD_USERNAME, LBXD_PASSWORD = load_user_pass()
    lbxd = Letterboxd()
    # login
    lbxd.user(LBXD_USERNAME, LBXD_PASSWORD)
    # Test the film with a movie this user hasn't seen, and isn't likely to ever see.
    film_instance = lbxd.film(film_id="1HIc")  # Shark Attack 3: Megalodon
    # Add it to my watchlist
    film_relationship_update_request = {"inWatchlist": True}
    film_relationship_update_response = film_instance.me_update(
        film_relationship_update_request=film_relationship_update_request
    )
    logging.debug(
        f"film_relationship_update_response: {film_relationship_update_response}"
    )
    assert isinstance(film_relationship_update_response, dict)
    assert set(film_relationship_update_response_keys()).issubset(
        film_relationship_update_response.keys()
    ), "All keys should be in FilmRelationshipUpdateResponse"
    assert isinstance(film_relationship_update_response["data"], dict)
    film_relationship = film_relationship_update_response["data"]
    assert set(film_relationship_keys()).issubset(
        film_relationship.keys()
    ), "All keys should be in FilmRelationship"
    assert isinstance(film_relationship_update_response["messages"], list)

    # Mark it watched, liked, and rate it
    film_relationship_update_request = {"watched": True, "liked": True, "rating": 2.5}
    film_relationship_update_response = film_instance.me_update(
        film_relationship_update_request=film_relationship_update_request
    )
    logging.debug(
        f"film_relationship_update_response: {film_relationship_update_response}"
    )
    assert isinstance(film_relationship_update_response, dict)

    # Remove activity and reset rating
    film_relationship_update_request = {
        "watched": False,
        "liked": False,
        "inWatchlist": False,
        "rating": "null",  # I had this as Null, but my params cleaner was stripping it out.
    }
    film_relationship_update_response = film_instance.me_update(
        film_relationship_update_request=film_relationship_update_request
    )
    logging.debug(
        f"film_relationship_update_response: {film_relationship_update_response}"
    )
    assert isinstance(film_relationship_update_response, dict)
示例#8
0
def test_list_me():
    lbxd = letterboxd.new()
    # Login
    LBXD_USERNAME, LBXD_PASSWORD = load_user_pass()
    lbxd.user(LBXD_USERNAME, LBXD_PASSWORD)

    list_id = "1UxUo"  # test_optical: "These are Twenty Films to Test With"
    list = lbxd.list(list_id=list_id)
    list_relationship = list.me()
    logging.debug(f"list_relationship: {list_relationship}")
    assert isinstance(list_relationship, dict)

    logging.debug(f"list_relationship.keys(): {list_relationship.keys()}")
    assert set(list_relationship_keys()).issubset(
        list_relationship.keys()), "All keys should be in ListRelationship."
示例#9
0
def test_list_update():
    """
    /list/{id} [PATCH]
    """
    lbxd = letterboxd.new()
    # Login
    LBXD_USERNAME, LBXD_PASSWORD = load_user_pass()
    lbxd.user(LBXD_USERNAME, LBXD_PASSWORD)
    list_id = "1UxUo"  # test_optical: "These are Twenty Films to Test With"
    rand_int_str = (
        f"{randint(0, 9)}{randint(0, 9)}{randint(0, 9)}{randint(0, 9)}{randint(0, 9)}"
    )
    list_update_request = {
        "published":
        True,
        "name":
        f"Twenty Films to Test With {rand_int_str}",
        "ranked":
        True,
        "description":
        f"API TEST - IGNORE\n\nHere's a description with some <strong>strong</strong> language, <em>emphasized</em>, <b>bold</b>, <i>italics</i>, a <a href=\"http://opticalpodcast.com\">link</a>, and here's a quote:\n\n<blockquote>We have nothing to fear but fear itself. And werewolves.\n\n—FDR, Werewolf Hunter</blockquote>\n\nUpdated {datetime.datetime.now().isoformat()}",
        "tags": ["api", "test", rand_int_str],
        "entries": [
            {
                "film": "1WRy",
                "rank": randint(1, 20),
                "notes": "Random rank the first",
                "containsSpoilers": False,
            },
            {
                "film": "2TRW",
                "rank": randint(1, 20),
                "notes": "Random rank the second",
                "containsSpoilers": True,
            },
        ],
    }

    list = lbxd.list(list_id=list_id)
    list_update_response = list.update(list_update_request=list_update_request)
    logging.debug(f"list_update_response: {list_update_response}")
    assert isinstance(list_update_response, dict)

    logging.debug(
        f"list_update_response.keys(): {list_update_response.keys()}")
    assert set(list_update_response_keys()).issubset(list_update_response.keys(
    )), "All keys should be in ListUpdateResponse"
示例#10
0
def test_films_services():
    """
    Test API call to /films/film-services
    """
    lbxd = Letterboxd()
    # login, so that we can see all of the services available to this member
    LBXD_USERNAME, LBXD_PASSWORD = load_user_pass()
    lbxd.user(LBXD_USERNAME, LBXD_PASSWORD)
    films = lbxd.films()
    film_services_response = films.services()
    logging.debug(f"film_services_response: {film_services_response}")
    assert isinstance(film_services_response, dict)
    assert set(film_services_response_keys()).issubset(
        film_services_response.keys()
    ), "All keys should be in FilmServicesResponse"
    assert isinstance(film_services_response["items"], list)
    service = film_services_response["items"][0]
    assert set(service_keys()).issubset(service.keys()), "All keys should be in Service"
示例#11
0
def test_list_create_comment():
    lbxd = letterboxd.new()
    # Login
    LBXD_USERNAME, LBXD_PASSWORD = load_user_pass()
    lbxd.user(LBXD_USERNAME, LBXD_PASSWORD)
    comment_creation_request = {
        "comment":
        "API TEST - IGNORE\n\nHere's a comment with some <strong>strong</strong> language, <em>emphasized</em>, <b>bold</b>, <i>italics</i>, a <a href=\"http://opticalpodcast.com\">link</a>, and here's a quote:\n\n<blockquote>We have nothing to fear but fear itself. And werewolves.\n\n—FDR, Werewolf Hunter</blockquote>"
    }
    list_id = "1UxUo"

    list = lbxd.list(list_id=list_id)
    list_comment = list.create_comment(
        comment_creation_request=comment_creation_request)
    logging.debug(f"list_comment: {list_comment}")
    assert isinstance(list_comment, dict)

    logging.debug(f"list_comment.keys(): {list_comment.keys()}")
    assert set(list_comment_keys()).issubset(
        list_comment.keys()), "All keys should be in ListComment"
示例#12
0
def test_film_me():
    LBXD_USERNAME, LBXD_PASSWORD = load_user_pass()
    lbxd = Letterboxd()
    # login
    lbxd.user(LBXD_USERNAME, LBXD_PASSWORD)
    film_instance = lbxd.film(film_id="2bbs")  # Raiders of the Lost Ark
    film_relationship = film_instance.me()
    logging.debug(f"film_relationship 1: {film_relationship}")
    assert isinstance(film_relationship, dict)
    assert set(film_relationship_keys()).issubset(
        film_relationship.keys()
    ), "All keys should be in FilmRelationship, against film with relationship"

    # test against film with no relationships
    film_instance = lbxd.film(film_id="Xwa")  # Shark Attack 2
    film_relationship = film_instance.me()
    logging.debug(f"film_relationship 2: {film_relationship}")
    assert set(film_relationship_keys()).issubset(
        film_relationship.keys()
    ), "All keys should be in FilmRelationship, against film with no relationship"
示例#13
0
def test_film_members():
    LBXD_USERNAME, LBXD_PASSWORD = load_user_pass()
    lbxd = Letterboxd()
    # login
    lbxd.user(LBXD_USERNAME, LBXD_PASSWORD)
    film_instance = lbxd.film(film_id="2bbs")  # Raiders of the Lost Ark
    member_film_relationships_request = {
        "perPage": 100,
        "sort": "Name",
        "member": "11Ht",
        "memberRelationship": "IsFollowedBy",
        "filmRelationship": "Liked",
    }
    member_film_relationships_response = film_instance.members(
        member_film_relationships_request=member_film_relationships_request
    )
    logging.debug(
        f"member_film_relationships_response: {member_film_relationships_response}"
    )
    logging.debug(
        f"member_film_relationships_response.keys(): {member_film_relationships_response.keys()}"
    )
    assert isinstance(member_film_relationships_response, dict)
    assert set(member_film_relationships_response_keys()).issubset(
        member_film_relationships_response.keys()
    ), "All keys should be in MemberFilmRelationshipsResponse"
    assert isinstance(member_film_relationships_response["items"], list)
    member_film_relationship = member_film_relationships_response["items"][0]
    logging.debug(f"member_film_relationship: {member_film_relationship}")
    assert isinstance(member_film_relationship["member"], dict)
    member_summary = member_film_relationship["member"]
    logging.debug(f"member_summary: {member_summary}")
    assert set(member_summary_keys()).issubset(
        member_summary.keys()
    ), "All keys should be in MemberSummary"
    assert isinstance(member_film_relationship["relationship"], dict)
    film_relationship = member_film_relationship["relationship"]
    logging.debug(f"film_relationship: {film_relationship}")
    assert set(film_relationship_keys()).issubset(
        film_relationship.keys()
    ), "All keys should be in FilmRelationship"
示例#14
0
def test_search():
    LBXD_USERNAME, LBXD_PASSWORD = load_user_pass()
    lbxd = Letterboxd()
    search_request = {
        "perPage": 5,
        "input": "smith",
        "searchMethod": "FullText",
        "include": "ContributorSearchItem",
        "contributionType": "Director",
    }
    search_response = lbxd.search(search_request=search_request)
    logging.debug(f"search_response: {search_response}")
    assert isinstance(search_response, dict)
    # TODO: test returned keys

    assert set(search_response_keys()).issubset(
        search_response.keys()), "All keys should be in SearchResponse"

    abstract_search_item = search_response["items"][0]
    assert set(abstract_search_item_keys()).issubset(abstract_search_item.keys(
    )), "All keys should be in the AbstractSearchItem"
示例#15
0
def test_list_me_update():
    lbxd = letterboxd.new()
    # Login
    LBXD_USERNAME, LBXD_PASSWORD = load_user_pass()
    lbxd.user(LBXD_USERNAME, LBXD_PASSWORD)
    list_id = "j4lQ"  # bobtiki: "Personal Top 100"
    list_relationship_update_request = {"liked": True, "subscribed": True}

    list = lbxd.list(list_id=list_id)
    list_relationship_update_response = list.me_update(
        list_relationship_update_request=list_relationship_update_request)
    logging.debug(
        f"list_relationship_update_response: {list_relationship_update_response}"
    )
    assert isinstance(list_relationship_update_response, dict)

    logging.debug(
        f"list_relationship_update_response.keys(): {list_relationship_update_response.keys()}"
    )
    assert set(list_relationship_update_response_keys()).issubset(
        list_relationship_update_response.keys(
        )), "All keys should be in ListRelationshipUpdateResponse"
示例#16
0
def test_film_collection():
    """
    Test API call to /film-collection/{id}
    """
    lbxd = letterboxd.new()
    # Log in as a user
    LBXD_USERNAME, LBXD_PASSWORD = load_user_pass()
    lbxd.user(LBXD_USERNAME, LBXD_PASSWORD)
    film_collection_id = "Nb"  # Indiana Jones
    film_collection_request = {
        "sort": "ReleaseDateEarliestFirst",
        "genre": "9k",
        "decade": 1980,
        "year": 1989,
        "service": "amazon",
        "where": ["Released"],
        "member": "3P",
        "memberRelationship": "Watched",
        "includeFriends": "Only",
        "tagCode": "stubs",
        "tagger": "11Ht",
        "includeTaggerFriends": "All",
    }
    film_collection = lbxd.film_collection(
        film_collection_id=film_collection_id,
        film_collection_request=film_collection_request,
    )
    film_summary = film_collection["films"][0]
    logging.debug(f"film_summary: {film_summary}")
    assert isinstance(film_summary, dict)
    assert set(film_summary_keys()).issubset(
        film_summary.keys()
    ), "All keys should be in FilmSummary"
    link = film_collection["links"][0]
    logging.debug(f"link: {link}")
    assert isinstance(link, dict)
    assert set(link_keys()).issubset(link.keys()), "All keys should be in Link"
示例#17
0
def test_lists():
    """
    /lists

    Assume use of environment variables for api key and secret
    """
    lbxd = letterboxd.new()
    # Login
    LBXD_USERNAME, LBXD_PASSWORD = load_user_pass()
    lbxd.user(LBXD_USERNAME, LBXD_PASSWORD)
    lists_request = {
        "perPage": 20,
        "sort": "ListName",
        "film": "2bbs",
        "clonedFrom": None,
        "tagCode": None,
        "tagger": None,
        # "includeTaggerFriends": "All",
        # "member": "u7kj",
        # "memberRelationship": "Owner",
        # "includeFriends": "All",
        "where": "Published",
        "filter": None,
    }
    lists = lbxd.lists(lists_request=lists_request)
    assert isinstance(lists, dict)
    # logging.debug("-------------------------\nlists:")
    # logging.debug(pprint.pformat(lists))
    assert set(lists_response_keys()).issubset(
        lists.keys()), "All keys should be in the lists_response."

    list_summary = lists["items"][0]
    assert isinstance(list_summary, dict)
    # logging.debug("-------------------------\nlist_summary:")
    # logging.debug(pprint.pformat(list_summary))
    assert set(list_summary_keys()).issubset(
        list_summary.keys()), "All keys should be in list_summary."
示例#18
0
def test_user_me_update():
    """

    :return:
    """
    # login
    LBXD_USERNAME, LBXD_PASSWORD = load_user_pass()
    lbxd = Letterboxd()
    test_user = lbxd.user(LBXD_USERNAME, LBXD_PASSWORD)
    # test
    member_settings_update_request = {
        "emailWhenFollowed": True,
        "emailComments": True,
        "emailNews": True,
        "emailRushes": True,
    }
    member_settings_update_response = test_user.me_update(
        member_settings_update_request=member_settings_update_request
    )
    logging.debug(f"member_settings_update_response: {member_settings_update_response}")
    assert isinstance(member_settings_update_response, dict)
    assert set(member_settings_update_response_keys()).issubset(
        member_settings_update_response.keys()
    ), "All keys should be in MemberSettingsUpdateResponse"