Skip to content

Commit

Permalink
added test for error for make_requests
Browse files Browse the repository at this point in the history
  • Loading branch information
googio committed Nov 19, 2023
1 parent 02fb989 commit a85be1a
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions tests/test_serply_error.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import pytest
import os
import logging
import asyncio
from aiohttp.client_exceptions import ClientResponseError
from serply import Serply

API_KEY = os.getenv("API_KEY", None)
Expand All @@ -12,3 +14,39 @@ def test_generate_unsported_endpoint_job_url():
with pytest.raises(ValueError) as e:
serply.__generate_url__(keyword="nurse practitioner", endpoint="asdf")
logging.error(e)


def test_request_post_serp_with_website_url_not_exists():
data = {"query": "q=iphone", "domain": "apple.com", "website": "apple.com"}
url = "https://api.serply.io/v1/asdfasdf/"
results = serply.__make_request__(url=url, method="post", json=data)
assert results
assert "error" in results


# test post versions
def test_request_post_serp_with_website_url_not_exists_async():
data = {"query": "q=iphone", "domain": "apple.com", "website": "apple.com"}
url = "https://api.serply.io/v1/asdfasdf/"
with pytest.raises(ClientResponseError) as e:
results = asyncio.run(
serply.__make_request_async__(url=url, method="post", json=data)
)
assert "result" in results
assert "title" in results["result"]
assert "position" in results
assert results["position"] == 1


# test post versions
def test_request_get_serp_with_website_url_not_exists_async():
data = {"query": "q=iphone", "domain": "apple.com", "website": "apple.com"}
url = "https://api.serply.io/v1/asdfasdf/"
with pytest.raises(ClientResponseError) as e:
results = asyncio.run(
serply.__make_request_async__(url=url, method="get")
)
assert "result" in results
assert "title" in results["result"]
assert "position" in results
assert results["position"] == 1

0 comments on commit a85be1a

Please sign in to comment.