예제 #1
0
def test_client_get_challenge_leaderboard(
    client: SyncClient, challenge_id: str
):
    challenge_leaderboard = client.get_challenge_leaderboard(challenge_id)
    assert isinstance(challenge_leaderboard, ChallengeLeaderboard)
    assert isinstance(challenge_leaderboard.users[0], ChallengeRankedCodinGamer)
    if challenge_leaderboard.has_leagues:
        assert isinstance(challenge_leaderboard.leagues[0], League)
예제 #2
0
def test_client_get_puzzle_leaderboard_error(client: SyncClient):
    with pytest.raises(ValueError):
        client.get_puzzle_leaderboard("codingame-optim", group="nonexistent")
    with pytest.raises(exceptions.LoginRequired):
        client.get_puzzle_leaderboard("codingame-optim", group="country")
    with pytest.raises(exceptions.PuzzleNotFound):
        client.get_puzzle_leaderboard("nonexistent")
예제 #3
0
def test_client_get_global_leaderboard_error(client: SyncClient):
    with pytest.raises(ValueError):
        client.get_global_leaderboard(type="NONEXISTENT")
    with pytest.raises(ValueError):
        client.get_global_leaderboard(group="nonexistent")
    with pytest.raises(exceptions.LoginRequired):
        client.get_global_leaderboard(group="country")
예제 #4
0
def test_client_get_puzzle_leaderboard(client: SyncClient, puzzle_id: str):
    puzzle_leaderboard = client.get_puzzle_leaderboard(puzzle_id)
    assert isinstance(puzzle_leaderboard, PuzzleLeaderboard)
    assert isinstance(puzzle_leaderboard.users[0], PuzzleRankedCodinGamer)
    if puzzle_leaderboard.has_leagues:
        assert isinstance(puzzle_leaderboard.leagues[0], League)

        # test League.__eq__
        assert puzzle_leaderboard.leagues[0] == League(
            client._state,
            {
                "divisionCount": 6,
                "divisionIndex": 0,
                "divisionAgentsCount": 100,
            },
        )
예제 #5
0
def test_client_get_challenge_leaderboard_error(client: SyncClient):
    with pytest.raises(ValueError):
        client.get_challenge_leaderboard(
            "spring-challenge-2021", group="nonexistent"
        )
    with pytest.raises(exceptions.LoginRequired):
        client.get_challenge_leaderboard(
            "spring-challenge-2021", group="country"
        )
    with pytest.raises(exceptions.ChallengeNotFound):
        client.get_challenge_leaderboard("nonexistent")
예제 #6
0
def test_client_login(client: SyncClient):
    client.login(
        remember_me_cookie=os.environ.get("TEST_LOGIN_REMEMBER_ME_COOKIE"),
    )
    assert client.logged_in is True
    assert client.codingamer is not None
예제 #7
0
def test_client_request_error(client: SyncClient, service: str, func: str):
    with pytest.raises(ValueError):
        client.request(service, func)
예제 #8
0
def test_client_request(client: SyncClient):
    session = client.request("session", "findSession")
    assert isinstance(session, dict)
예제 #9
0
def test_client_get_clash_of_code(client: SyncClient):
    clash_of_code = client.get_clash_of_code(
        os.environ.get("TEST_CLASHOFCODE_PUBLIC_HANDLE")
    )
    assert isinstance(clash_of_code, ClashOfCode)
예제 #10
0
def test_client_get_global_leaderboard(client: SyncClient):
    global_leaderboard = client.get_global_leaderboard()
    assert isinstance(global_leaderboard, GlobalLeaderboard)
    assert isinstance(global_leaderboard.users[0], GlobalRankedCodinGamer)
예제 #11
0
def test_client_notifications_error(client: SyncClient):
    with pytest.raises(exceptions.LoginRequired):
        next(client.get_unseen_notifications())
예제 #12
0
def test_client_notifications(auth_client: SyncClient):
    for notification in auth_client.get_unseen_notifications():
        assert isinstance(notification, Notification)
예제 #13
0
def test_client_language_ids(client: SyncClient):
    language_ids = client.get_language_ids()
    assert isinstance(language_ids, list)
    assert all(isinstance(language_id, str) for language_id in language_ids)
예제 #14
0
def test_client_get_pending_clash_of_code(client: SyncClient):
    clash_of_code = client.get_pending_clash_of_code()
    assert isinstance(clash_of_code, ClashOfCode) or clash_of_code is None
예제 #15
0
def test_client_get_clash_of_code_error(client: SyncClient):
    with pytest.raises(ValueError):
        client.get_clash_of_code("0")

    with pytest.raises(exceptions.ClashOfCodeNotFound):
        client.get_clash_of_code("0" * 7 + "a" * 32)
예제 #16
0
def test_client_login_error(client: SyncClient, email: str, password: str):
    with pytest.raises(exceptions.LoginError):
        client.login(email, password)
예제 #17
0
def test_client_get_codingamer(client: SyncClient, codingamer_query):
    codingamer = client.get_codingamer(codingamer_query)
    assert isinstance(codingamer, CodinGamer)
예제 #18
0
def test_client_get_codingamer_error(client: SyncClient, codingamer_query):
    with pytest.raises(exceptions.CodinGamerNotFound):
        client.get_codingamer(codingamer_query)