Skip to content

Commit

Permalink
Add tests for petri output and moved petri rendering into request (#246)
Browse files Browse the repository at this point in the history
  • Loading branch information
kharus authored Jan 10, 2025
1 parent 6735c6c commit 3c501c4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
2 changes: 1 addition & 1 deletion natural4-server/natural4_server/hello.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ async def petri_post_process(target_folder):
timestamp = (await dot_path.readlink()).stem

flowchart_tasks: asyncio.Task[None] = pipe(
get_flowchart_tasks(target_folder, timestamp), run_tasks, app.add_task
get_flowchart_tasks(target_folder, timestamp), run_tasks
)

return timestamp,flowchart_tasks
Expand Down
33 changes: 21 additions & 12 deletions natural4-server/tests/test_endpoint.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,27 @@
from sanic import Sanic
import pytest
from sanic_testing.reusable import ReusableClient
from time import sleep

@pytest.mark.asyncio
async def test_live(app: Sanic):
request, response = await app.asgi_client.get("/health/liveness")
def test_post(app: Sanic, post_data):
with open('tests/data/rodents.csv') as f:
input_data = f.read()
with ReusableClient(app) as client:
post_data['csvString'] = input_data
request, response_post = client.post('/post', data=post_data)
assert response_post.status == 200

assert response.status == 200
workdir_url = f'/workdir/{post_data['uuid']}/{post_data['spreadsheetId']}/{post_data['sheetId']}'

@pytest.mark.asyncio
async def test_post(app: Sanic, post_data):
with open('tests/data/rodents.csv') as f:
input_data = f.read()
request, response_json = client.get(f'{workdir_url}/aajson/LATEST.json')
assert response_json.status == 200

sleep(1)

request, response_json = client.get(f'{workdir_url}/petri/LATEST.png')
assert response_json.status == 200

post_data['csvString'] = input_data
request, response = await app.asgi_client.post('/post', data=post_data)
request, response_json = client.get(f'{workdir_url}/petri/LATEST.svg')
assert response_json.status == 200

assert response.status == 200
request, response_json = client.get(f'{workdir_url}/petri/LATEST-small.png')
assert response_json.status == 200

0 comments on commit 3c501c4

Please sign in to comment.