Skip to content

Commit

Permalink
fix pytest
Browse files Browse the repository at this point in the history
  • Loading branch information
dcambie committed Jul 13, 2023
1 parent 6c45fb0 commit 44d09f4
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 36 deletions.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ test = [
"pytest-asyncio",
"pytest-cov",
"pytest-mock",
"pytest-xprocess",
"httpx",
"requests",
]
Expand Down
9 changes: 1 addition & 8 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,7 @@
@pytest.fixture(scope="module")
def flowchem_test_instance(xprocess):
config_file = Path(__file__).parent.resolve() / "test_config.toml"
main = (
Path(__file__).parent.resolve()
/ ".."
/ ".."
/ "src"
/ "flowchem"
/ "__main__.py"
)
main = Path(__file__).parent.resolve() / ".." / "src" / "flowchem" / "__main__.py"

class Starter(ProcessStarter):
# Process startup ends with this text in stdout
Expand Down
32 changes: 4 additions & 28 deletions tests/server/test_server.py
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

0 comments on commit 44d09f4

Please sign in to comment.