Beispiel #1
0
async def test_saved_rate_max() -> None:
    """Test get method."""
    key = generate_key()
    with aioresponses() as m:
        m.get(
            f"https://api.hypixel.net/test?key={str(key)}",
            status=200,
            headers={
                "RateLimit-Limit": "120",
                "RateLimit-Remaining": "5",
                "RateLimit-Reset": "8",
            },
            payload={
                "success": True,
                "Test_value": "Random string"
            },
        )
        client = asyncpixel.Hypixel(api_key=str(key))
        await client._get("test")
        m.get(
            f"https://api.hypixel.net/test?key={str(key)}",
            status=200,
            headers={
                "RateLimit-Limit": "200",
                "RateLimit-Remaining": "4",
                "RateLimit-Reset": "8",
            },
            payload={
                "success": True,
                "Test_value": "Random string"
            },
        )
        await client._get("test")
        assert client.total_requests == 120
        await client.close()
Beispiel #2
0
 def __init__(self, bot):
     self.bot = bot
     self.hypixel = asyncpixel.Hypixel(pickle.load(open("credentials.pkl", 'rb'))['hypixel'])
     self.currentBazaar = None
     self.currentAh = None
     self.Bazaar_Loop.start()
     self.Auction_loop.start()
     self.bz_id_item = bz_ids.id_name
     self.bz_item_id = bz_ids.name_id
Beispiel #3
0
async def test_no_hader() -> None:
    """Test get method."""
    key = generate_key()
    with aioresponses() as m:
        m.get(
            f"https://api.hypixel.net/test?key={str(key)}",
            status=200,
            payload={
                "success": True,
                "Test_value": "Random string"
            },
        )
        client = asyncpixel.Hypixel(api_key=str(key))
        await client._get("test")
        await client.close()
Beispiel #4
0
async def test_safe_ratelimit() -> None:
    """Test get method."""
    key = generate_key()
    with aioresponses() as m:
        m.get(
            f"https://api.hypixel.net/test?key={str(key)}",
            status=200,
            headers={
                "RateLimit-Limit": "120",
                "RateLimit-Remaining": "0",
                "RateLimit-Reset": "8",
            },
            payload={
                "success": True,
                "Test_value": "Random string"
            },
        )
        client = asyncpixel.Hypixel(api_key=str(key))
        await client._get("test")
        with pytest.raises(asyncpixel.exceptions.RateLimitError):
            await client._get("test")
        await client.close()