def test_user_id_articles_public_promise_get_all_sync(self): page = 0 async def get_all_sync_p(json, obj): nonlocal page page += 1 return False alis.api_p("/users/user_id/articles/public", { "user_id": "fukurou", "limit": 10 }, {"getAllSync": get_all_sync_p}) assert True
def test_search_articles_tag(self): page = 0 async def get_all_p(json, obj): nonlocal page page += 1 if page == 3: return True else: return False alis.api_p("/search/articles", {"tag": "紅組"}, {"getAll": get_all_p}) assert True
def test_get_all_promise(self): page = 0 async def get_all_p(json, obj): nonlocal page # print(f"{obj.itemCount} articles fetched from {obj.startNth}th to {obj.endNth}th.") page += 1 # for item in json["Items"]: # print(item) if page == 3: return True else: return False json = alis.api_p("/articles/popular", {"limit": 10}, { "method": "GET", "getAll": get_all_p }) assert json.get("Items")
def test_wrong_password_promise(self): with pytest.raises(ValueError, match='password'): alis.api_p("/me/info", {}, { "username": "******", "password": "******" })
def test_wrong_api_promise(self): with pytest.raises(KeyError, match="api call"): alis.api_p("/wrong/api")
def test_promise(self): json = alis.api_p("/articles/recent") assert json.get("Items")
def test_user_id_articles_public_promise(self): json = alis.api_p("/users/user_id/articles/public", {"user_id": "fukurou"}, {}) assert json.get('Items')
def test_no_username_error_promise(self): with pytest.raises(ValueError, match="username"): alis.api_p("/me/info", {}, {})
def test_id_token_error_promise(self): with pytest.raises(KeyError): alis.api_p("/me/info", {}, { "username": '******', "id_token": "test" })