This repository has been archived by the owner on Oct 19, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 138
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: jcloud integration tests for basic app
- Loading branch information
Showing
2 changed files
with
44 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import json | ||
|
||
import pytest | ||
import requests | ||
import websockets | ||
|
||
from ..helper import deploy_jcloud_app | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_basic_app(): | ||
async with deploy_jcloud_app() as app_id: | ||
_test_http_route(app_id) | ||
await _test_ws_route(app_id) | ||
|
||
|
||
def _test_http_route(app_id): | ||
headers = { | ||
"accept": "application/json", | ||
"Content-Type": "application/json", | ||
} | ||
data = {"interval": 1, "envs": {}} | ||
|
||
response = requests.post( | ||
f"https://{app_id}.wolf.jina.ai/sync_http", headers=headers, json=data | ||
) | ||
|
||
response_data = response.json() | ||
|
||
assert response.status_code == 200 | ||
assert response_data["result"] == "Hello, world!" | ||
|
||
|
||
async def _test_ws_route(app_id): | ||
async with websockets.connect(f"wss://{app_id}.wolf.jina.ai/sync_ws") as websocket: | ||
await websocket.send(json.dumps({"interval": 1})) | ||
|
||
received_messages = [] | ||
for _ in range(5): | ||
message = await websocket.recv() | ||
received_messages.append(message) | ||
|
||
assert received_messages == ["0", "1", "2", "3", "4"] |