-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
6 additions
and
36 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,6 +53,7 @@ test = [ | |
"pytest-asyncio", | ||
"pytest-cov", | ||
"pytest-mock", | ||
"pytest-xprocess", | ||
"httpx", | ||
"requests", | ||
] | ||
|
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 |
---|---|---|
@@ -1,38 +1,14 @@ | ||
import asyncio | ||
from pathlib import Path | ||
from textwrap import dedent | ||
|
||
import pytest | ||
from click.testing import CliRunner | ||
from fastapi.testclient import TestClient | ||
|
||
from flowchem.server.create_server import create_server_from_file | ||
|
||
|
||
@pytest.fixture(scope="function") | ||
def app(): | ||
runner = CliRunner() | ||
with runner.isolated_filesystem(): | ||
with open("test_configuration.toml", "w") as f: | ||
f.write( | ||
dedent( | ||
"""[device.test-device]\n | ||
type = "FakeDevice"\n""" | ||
) | ||
) | ||
server = asyncio.run(create_server_from_file(Path("test_configuration.toml"))) | ||
yield server["api_server"].app | ||
import requests | ||
|
||
|
||
def test_read_main(flowchem_test_instance): | ||
client = TestClient(app) | ||
response = client.get("/") | ||
response = requests.get(r"http://127.0.0.1:8000/") | ||
assert response.status_code == 200 | ||
assert "Flowchem" in response.text | ||
|
||
response = client.get("/test-device/test-component/test") | ||
response = requests.get(r"http://127.0.0.1:8000/test-device/test-component/test") | ||
assert response.status_code == 200 | ||
assert response.text == "true" | ||
|
||
response = client.get("/test-device2") | ||
response = requests.get(r"http://127.0.0.1:8000/test-device2") | ||
assert response.status_code == 404 |