Exemple #1
0
def test_cache_timing():
    api.cache.clear()

    # Not cached, needs to be retrieved with API rate limit.
    time = datetime.utcnow()
    api.request_beatmapset(1)
    api.request_user(2)
    delta_time = datetime.utcnow() - time

    assert delta_time.total_seconds() > 1

    # Cached, can simply be read from a dictionary, should be pretty much instant.
    time = datetime.utcnow()
    api.request_beatmapset(1)
    api.request_user(2)
    delta_time = datetime.utcnow() - time

    assert delta_time.total_seconds() < 0.01
Exemple #2
0
def test_cache():
    api.cache.clear()
    assert not api.cache

    beatmapset_response = api.request_beatmapset(1)
    user_response = api.request_user(2)
    assert beatmapset_response
    assert user_response

    assert api.cache
    assert api.cache["/get_beatmaps?s=1"]
    assert api.cache["/get_user?u=2"]
Exemple #3
0
    def __init__(self,
                 _id: int = None,
                 name: str = None,
                 allow_api: bool = True):
        if _id is None and name is None:
            raise ValueError(
                "Cannot create a User object with neither id nor name provided."
            )

        if not allow_api:
            if _id is None: _id = 1
            if name is None: name = "name"

        self.id = int(_id) if _id is not None else None
        self.name = str(name) if name is not None else None

        if name is None or _id is None:
            if name is None: user_json = api.request_user(_id)
            if _id is None: user_json = api.request_user(name)
            # Otherwise user doesn't exist, either restricted or renamed a long time ago.
            if user_json is not None:
                self.id = int(user_json["user_id"])
                self.name = str(user_json["username"])
Exemple #4
0
def test_request_user_escaped_name():
    user_response = api.request_user("-Mo- &amp; Ephemeral")

    assert user_response is None
Exemple #5
0
def test_request_user():
    user_response = api.request_user(2)

    assert user_response["username"] == "peppy"