-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add: unittesting for the inscriptis web service.
- Loading branch information
1 parent
1fe8da7
commit 16ba471
Showing
3 changed files
with
52 additions
and
3 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
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,47 @@ | ||
import pytest | ||
from fastapi.testclient import TestClient | ||
from inscriptis.service.web import app | ||
from inscriptis.metadata import __version__ | ||
|
||
# Replace "your_module" with the actual module name where your FastAPI app is defined. | ||
|
||
|
||
@pytest.fixture | ||
def client(): | ||
return TestClient(app) | ||
|
||
|
||
def test_index(client): | ||
response = client.get("/") | ||
assert response.status_code == 200 | ||
assert response.text == "Inscriptis text to HTML Web service." | ||
|
||
|
||
def test_get_text_call_with_content_type(client): | ||
html_content = "<html><body>Österliche Freuden!</body></html>" | ||
response = client.post( | ||
"/get_text", | ||
content=html_content, | ||
headers={"Content-type": "text/html; charset=UTF-8"}, | ||
) | ||
assert response.status_code == 200 | ||
assert response.text == "Österliche Freuden!" | ||
|
||
|
||
def test_get_text_call_without_content_type(client): | ||
html_content = "<html><body>Hello World!</body></html>" | ||
response = client.post( | ||
"/get_text", | ||
content=html_content, | ||
headers={"Content-type": "text/html"}, | ||
) | ||
assert response.status_code == 200 | ||
assert response.text == "Hello World!" | ||
|
||
|
||
def test_get_version_call(client): | ||
response = client.get("/version") | ||
assert response.status_code == 200 | ||
assert ( | ||
response.text == __version__ | ||
) # Assuming your ParserConfig has a version attribute |
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