This repository was archived by the owner on Dec 18, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_textoria.py
More file actions
62 lines (42 loc) · 1.66 KB
/
test_textoria.py
File metadata and controls
62 lines (42 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import pytest
from aioresponses import aioresponses
from textoria import Textoria
@pytest.fixture
def api_url():
return "http://localhost:8000"
@pytest.fixture
def textoria_client(api_url):
return Textoria(api_url)
@pytest.mark.asyncio
async def test_get_all_keys(textoria_client, api_url):
mocked_data = {"key1": "value1", "key2": "value2"}
with aioresponses() as m:
m.get(f"{api_url}/get_all_keys", payload=mocked_data)
response = await textoria_client.get_all_keys()
assert response == mocked_data
@pytest.mark.asyncio
async def test_create_key(textoria_client, api_url):
new_key = "new_key"
new_value = "new_value"
mocked_data = {new_key: new_value}
with aioresponses() as m:
m.post(f"{api_url}/create_key?new_key={new_key}&new_value={new_value}", payload=mocked_data)
response = await textoria_client.create_key(new_key, new_value)
assert response == mocked_data
@pytest.mark.asyncio
async def test_update_key(textoria_client, api_url):
key = "key1"
new_value = "updated_value"
mocked_data = {key: new_value}
with aioresponses() as m:
m.put(f"{api_url}/update_key?key={key}&new_value={new_value}", payload=mocked_data)
response = await textoria_client.update_key(key, new_value)
assert response == mocked_data
@pytest.mark.asyncio
async def test_delete_key(textoria_client, api_url):
key = "key1"
mocked_data = {"detail": f"Key '{key}' deleted."}
with aioresponses() as m:
m.delete(f"{api_url}/delete_key?key={key}", payload=mocked_data)
response = await textoria_client.delete_key(key)
assert response == mocked_data