File: test_ratelimit.py

package info (click to toggle)
python-yalexs 9.2.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,120 kB
  • sloc: python: 7,916; makefile: 3; sh: 2
file content (20 lines) | stat: -rw-r--r-- 576 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import time

import pytest

from yalexs.exceptions import RateLimited
from yalexs.manager.ratelimit import RATE_LIMIT_WAKEUP_INTERVAL, _RateLimitChecker


@pytest.mark.asyncio
async def test_init_rate_limit():
    _RateLimitChecker._client_wakeups.clear()

    await _RateLimitChecker.check_rate_limit("test")
    await _RateLimitChecker.register_wakeup("test")
    with pytest.raises(RateLimited) as exc:
        await _RateLimitChecker.check_rate_limit("test")

    assert exc.value.next_allowed == pytest.approx(
        time.monotonic() + RATE_LIMIT_WAKEUP_INTERVAL
    )