Skip to content

Commit 4628985

Browse files
author
FaydSpeare
committed
preparing tests
1 parent 3e97f16 commit 4628985

File tree

3 files changed

+32
-9
lines changed

3 files changed

+32
-9
lines changed

README.md

+9-8
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ Get started with the [TikTok API Guide](https://github.com/ensembledata/tiktok-s
4444
#### Instagram Guide
4545
Get started with the [Instagram API Guide](https://github.com/ensembledata/instagram-scraper). Find out which endpoints are available, and how you can use them with examples using the ensembledata python package.
4646

47-
48-
 
47+
<br>
48+
<br>
4949

5050
### Missing Endpoints / Parameters
5151

@@ -66,14 +66,15 @@ client = EDClient("API-TOKEN")
6666
result = client.instagram.user_info(username="...", extra_params={"baz": "..."})
6767
```
6868

69-
&nbsp;
69+
<br>
70+
<br>
7071

7172
### Handling Errors
7273

7374
In the [API docs](https://ensembledata.com/apis/docs), each endpoint lists a handful of possible errors the API may respond with. You can handle these errors by catching the `EDError` exception.
7475

7576
```python
76-
from ensembledata.api import EDClient, EDError
77+
from ensembledata.api import EDClient, EDError, errors
7778

7879

7980
client = EDClient("API-TOKEN")
@@ -82,11 +83,11 @@ try:
8283
except EDError as e:
8384

8485
# Rate limit exceeded...
85-
if e.status_code == 429:
86+
if e.status_code == errors.STATUS_429_RATE_LIMIT_EXCEEDED:
8687
print(e.detail)
8788

8889
# Subscription expired...
89-
if e.status_code == 493:
90+
if e.status_code == errors.STATUS_493_SUBSCRIPTION_EXPIRED:
9091
print(e.detail)
9192

9293
except Exception as e:
@@ -97,8 +98,8 @@ except Exception as e:
9798

9899
```
99100

100-
&nbsp;
101-
101+
<br>
102+
<br>
102103

103104
### Async
104105

requirements.txt

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
ruff==0.5.6
2-
mypy==1.11.1
2+
mypy==1.11.1
3+
pytest==7.4.4
4+
pytest-asyncio=0.21.2

tests/test_clients.py

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import pytest
2+
3+
from ensembledata.api import EDClient, EDAsyncClient, EDError, errors
4+
5+
def test_client():
6+
client = EDClient("xxx")
7+
with pytest.raises(EDError) as e:
8+
client.customer.get_usage("2024-01-01")
9+
10+
assert e.value.status_code == errors.STATUS_491_INVALID_TOKEN
11+
12+
13+
@pytest.mark.asyncio
14+
async def test_async_client():
15+
client = EDAsyncClient("xxx")
16+
17+
with pytest.raises(EDError) as e:
18+
await client.customer.get_usage("2024-01-01")
19+
20+
assert e.value.status_code == errors.STATUS_491_INVALID_TOKEN

0 commit comments

Comments
 (0)