Пример #1
0
def test_saving(fix_requests, fix_input):
    from campbot import CampBot

    fix_input.set_response(lambda x: "y")

    area = CampBot().wiki.get_area(area_id=14273)
    area.save("Test")
Пример #2
0
def test_weird(fix_requests, fix_input):
    from campbot import CampBot, __main__
    import os

    fix_input.set_response(lambda x: "n")

    bot = CampBot()

    obj = bot.wiki.get_article(123)
    obj.document_id = 1
    assert obj["document_id"] == 1
    assert obj.search(["xxx"], "fr") == False
    assert obj.save("test", True) is None

    user = bot.wiki.get_profile(123)
    assert user.get_last_contribution(newest_date="1970-01-01") is None

    obj = bot.wiki.get_waypoint(123)
    assert obj.get_invalidity_reason() == "elevation is missing"
    obj.elevation = 12
    assert obj.get_invalidity_reason() is None
    obj.waypoint_type = "hut"
    obj.custodianship = None
    assert obj.get_invalidity_reason() == "custodianship is missing"

    obj = bot.wiki.get_wiki_object(123, "o")
    assert obj.is_personal() == True

    os.environ["CAMPBOT_LOGIN"] = "******"
    os.environ["CAMPBOT_PASSWORD"] = "******"
    args = get_main_args("clean")
    assert args["--login"] == "x"
    assert args["--password"] == "y"
    args["--login"] = False
    __main__.main(args)

    with open("contributors.txt", "w") as f:
        f.write("666|1\n")
        f.write("667|1\n")
        f.write("667|100\n")
        f.write("668|100\n")
        f.write("123|1\n")

    bot.get_new_contributors()
Пример #3
0
def test_wiki(fix_requests, fix_input):
    from campbot import CampBot

    fix_input.set_response(lambda x: "y")

    route = CampBot().wiki.get_route(route_id=293549)
    route.is_personal()
    route.get_title("fr")

    xreport = CampBot().wiki.get_xreport(xreport_id=293549)
    xreport.is_personal()

    image = CampBot().wiki.get_image(image_id=1005116)
    image.is_personal()

    waypoint = CampBot().wiki.get_waypoint(waypoint_id=952999)
    waypoint.get_invalidity_reason()

    article = CampBot().wiki.get_article(article_id=1003911)
    article.is_personal()

    area = CampBot().wiki.get_area(area_id=14273)
    area.save("Test")

    CampBot().wiki.get_profile(profile_id=293549)
    CampBot().wiki.get_book(book_id=293549)
    CampBot().wiki.get_map(map_id=293549)

    list(CampBot().wiki.get_routes({}))
    list(CampBot().wiki.get_waypoints({}))
    list(CampBot().wiki.get_outings({}))
    list(CampBot().wiki.get_xreports({}))

    for _ in CampBot().wiki.get_route_ids():
        break

    for _ in CampBot().wiki.get_xreport_ids():
        break

    for _ in CampBot().wiki.get_document_ids(document_type="r"):
        break

    for _ in CampBot().wiki.get_documents(document_type="r"):
        break

    assert CampBot().wiki.ui_url == "https://www.camptocamp.org"

    version = CampBot().wiki.get_wiki_object_version(293549, "r", "fr",
                                                     1738922)
    assert version.get_diff_url("fr") is not None
    assert version.get_locale_length("fr") != 0

    CampBot().wiki.get_wiki_object_version(None, "", "", None)

    version = CampBot().wiki.get_wiki_object_version(293549, "r", "fr",
                                                     1738922)
    version.previous_version_id = None
    assert version.get_diff_url("fr") is not None

    route = CampBot().wiki.get_wiki_object(item_id=293549, document_type="r")
    assert route.get_url() == "https://www.camptocamp.org/routes/293549"
    assert (route.get_history_url("fr") ==
            "https://www.camptocamp.org/routes/history/293549/fr")

    CampBot().wiki.get_contributions(oldest_date="2017-12-12",
                                     newest_date="2017-12-13")

    with pytest.raises(Exception):
        CampBot().wiki.get_user(forum_name="unknown")

    user = CampBot().wiki.get_user(forum_name="CharlesB")
    user.is_personal()
    user.save("test", ask_before_saving=False)

    contrib = user.get_last_contribution()
    contrib.get_full_document()
    contrib.user.get_wiki_user()
    contrib.user.is_newbie()
    contrib.user.get_contributions_url()