Skip to content

Commit d4c5f07

Browse files
authored
Merge pull request #2 from marklogic/feature/eval-test
Added test for eval
2 parents 227b9e0 + daeef57 commit d4c5f07

File tree

6 files changed

+67
-22
lines changed

6 files changed

+67
-22
lines changed

poetry.lock

Lines changed: 23 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ license = "Apache 2.0"
1010
[tool.poetry.dependencies]
1111
python = "^3.9"
1212
requests = "^2.31.0"
13+
requests_toolbelt = "1.0.0"
14+
15+
[tool.poetry.group.test.dependencies]
1316
pytest = "^7.4.0"
1417

1518
[tool.poetry.group.dev.dependencies]

test-app/src/main/ml-config/security/users/python-test-user.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
"user-name": "python-test-user",
33
"password": "password",
44
"role": [
5-
"rest-reader",
6-
"rest-writer",
7-
"qconsole-user"
5+
"rest-evaluator",
6+
"rest-reader",
7+
"rest-writer",
8+
"qconsole-user"
89
]
9-
}
10-
10+
}

tests/conftest.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import pytest
2+
import requests
3+
from requests.auth import HTTPDigestAuth
4+
5+
6+
@pytest.fixture
7+
def test_session():
8+
session = requests.Session()
9+
session.auth = HTTPDigestAuth("python-test-user", "password")
10+
return session

tests/test_eval.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
from requests_toolbelt.multipart.decoder import MultipartDecoder
2+
3+
4+
def test_eval(test_session):
5+
"""
6+
This shows how a user would do an eval today. It's a good example of how a multipart/mixed
7+
response is a little annoying to deal with, as it requires using the requests_toolbelt
8+
library and a class called MultipartDecoder.
9+
10+
Client support for this might look like this:
11+
response = client.eval.xquery("<hello>world</hello>")
12+
13+
And then it's debatable whether we want to do anything beyond what MultipartDecoder
14+
is doing for handling the response.
15+
"""
16+
response = test_session.post(
17+
"http://localhost:8030/v1/eval",
18+
headers={"Content-type": "application/x-www-form-urlencoded"},
19+
data={"xquery": "<hello>world</hello>"},
20+
)
21+
22+
decoder = MultipartDecoder.from_response(response)
23+
content = decoder.parts[0].text
24+
assert "<hello>world</hello>" == content

tests/test_search.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,5 @@
1-
import requests
2-
from requests.auth import HTTPDigestAuth
3-
4-
5-
def test_search():
6-
response = requests.get(
7-
"http://localhost:8030/v1/search",
8-
auth=HTTPDigestAuth("python-test-user", "password")
9-
)
1+
def test_search(test_session):
2+
response = test_session.get("http://localhost:8030/v1/search")
103
assert 200 == response.status_code
114
assert "application/xml; charset=utf-8" == response.headers["Content-type"]
125
assert response.text.startswith("<search:response")

0 commit comments

Comments
 (0)