SIMNet/tests/test_base_client.py
洛水居室 b74b9aef33
Refactor BaseClient class and add cookie property accessor
Added a `cookies` property accessor to the `BaseClient` class, which retrieves cookies from the `httpx` AsyncClient object and returns a `simnet.client.cookies.Cookies` object (which is a custom implementation of the `httpx.Cookies` class). Additionally, the initialization function was refactored to better support using cookies. Now, if `account_id` is not passed in, it will be retrieved from the cookies.
2023-05-09 15:19:36 +08:00

18 lines
597 B
Python

import pytest
from simnet.client.base import BaseClient
from simnet.client.cookies import Cookies
@pytest.mark.asyncio
class TestBaseClient:
@staticmethod
async def test_cookies():
async with BaseClient(cookies={"uid": "114514"}) as client:
assert isinstance(client.cookies, Cookies)
client.cookies = {"account_id": "114514"}
assert isinstance(client.cookies, Cookies)
assert client.cookies.get("account_id") == "114514"
client.cookies.set("stuid", "114514")
assert client.cookies.get("stuid") == "114514"