Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ classifiers = [
]
requires-python = ">=3.9"
dependencies = [
"dataclasses-json == 0.6.7",
"httpx[http2] == 0.27.2",
"marshmallow == 3.23.0",
"pydantic == 2.9.2",
"python-dateutil == 2.9.0.post0",
"tenacity == 9.0.0",
"dataclasses-json >= 0.6.7,<0.7.0",
"httpx[http2] >= 0.27.2,<1.0.0",
"marshmallow >= 3.23.0,<4.0.0",
"pydantic >= 2.9.2,<3.0.0",
"python-dateutil >= 2.9.0.post0,<3.0.0",
"tenacity >= 9.0.0,<10.0.0",
]

[project.urls]
Expand Down
16 changes: 10 additions & 6 deletions tests/test_base_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# License for the specific language governing permissions and limitations
# under the License.
from http import HTTPStatus
import json

from centraldogma.exceptions import UnauthorizedException, NotFoundException
from centraldogma.base_client import BaseClient
Expand All @@ -26,7 +27,7 @@
"cookies": None,
"verify": None,
"cert": None,
"proxies": None,
"proxy": None,
"mounts": None,
"timeout": 5,
"retries": 10,
Expand All @@ -35,7 +36,6 @@
"max_redirects": 1,
"event_hooks": None,
"transport": None,
"app": None,
"trust_env": True,
}
client_with_configs = BaseClient(base_url, "token", **configs)
Expand Down Expand Up @@ -153,12 +153,14 @@ def test_patch(respx_mock):
route = respx_mock.patch(f"{base_url}/api/v1/path").mock(
return_value=Response(200, text="success")
)
resp = client.request("patch", "/path", json={"a": "b"}, handler=ok_handler)
given = {"a": "b"}
resp = client.request("patch", "/path", json=given, handler=ok_handler)

assert route.called
assert resp.request.headers["Authorization"] == "bearer token"
assert resp.request.headers["Content-Type"] == "application/json-patch+json"
assert resp.request._content == b'{"a": "b"}'
got = json.loads(resp.request.content)
assert got == given


def test_patch_exception_authorization(respx_mock):
Expand All @@ -171,12 +173,14 @@ def test_post(respx_mock):
route = respx_mock.post(f"{base_url}/api/v1/path").mock(
return_value=Response(200, text="success")
)
resp = client.request("post", "/path", json={"a": "b"}, handler=ok_handler)
given = {"a": "b"}
resp = client.request("post", "/path", json=given, handler=ok_handler)

assert route.called
assert resp.request.headers["Authorization"] == "bearer token"
assert resp.request.headers["Content-Type"] == "application/json"
assert resp.request._content == b'{"a": "b"}'
got = json.loads(resp.request.content)
assert got == given


def test_post_exception_authorization(respx_mock):
Expand Down
35 changes: 18 additions & 17 deletions tests/test_dogma.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# under the License.
from datetime import datetime
from http import HTTPStatus
import json

import pytest
from httpx import Response
Expand Down Expand Up @@ -117,7 +118,7 @@ def test_create_project(respx_mock):
assert route.called
request = respx_mock.calls.last.request
assert request.url == url
assert request._content == b'{"name": "newProject"}'
assert json.loads(request.content) == {"name": "newProject"}
assert project == Project.from_dict(mock_project)


Expand All @@ -137,7 +138,7 @@ def test_create_project_failed(respx_mock):
assert route.called
request = respx_mock.calls.last.request
assert request.url == url
assert request._content == b'{"name": "newProject"}'
assert json.loads(request.content) == {"name": "newProject"}


def test_remove_project(respx_mock):
Expand Down Expand Up @@ -169,9 +170,9 @@ def test_unremove_project(respx_mock):
assert route.called
request = respx_mock.calls.last.request
assert request.url == url
assert (
request._content == b'[{"op": "replace", "path": "/status", "value": "active"}]'
)
assert json.loads(request.content) == [
{"op": "replace", "path": "/status", "value": "active"}
]
assert project == Project.from_dict(mock_project)


Expand All @@ -186,9 +187,9 @@ def test_unremove_project_failed(respx_mock):
assert route.called
request = respx_mock.calls.last.request
assert request.url == url
assert (
request._content == b'[{"op": "replace", "path": "/status", "value": "active"}]'
)
assert json.loads(request.content) == [
{"op": "replace", "path": "/status", "value": "active"}
]


def test_purge_project(respx_mock):
Expand Down Expand Up @@ -250,7 +251,7 @@ def test_create_repository(respx_mock):
assert route.called
request = respx_mock.calls.last.request
assert request.url == url
assert request._content == b'{"name": "newRepo"}'
assert json.loads(request.content) == {"name": "newRepo"}
assert repo == Repository.from_dict(mock_repository)


Expand All @@ -269,7 +270,7 @@ def test_create_repository_failed(respx_mock):
assert route.called
request = respx_mock.calls.last.request
assert request.url == url
assert request._content == b'{"name": "newRepo"}'
assert json.loads(request.content) == {"name": "newRepo"}


def test_remove_repository(respx_mock):
Expand Down Expand Up @@ -301,9 +302,9 @@ def test_unremove_repository(respx_mock):
assert route.called
request = respx_mock.calls.last.request
assert request.url == url
assert (
request._content == b'[{"op": "replace", "path": "/status", "value": "active"}]'
)
assert json.loads(request.content) == [
{"op": "replace", "path": "/status", "value": "active"}
]
assert repo == Repository.from_dict(mock_repository)


Expand All @@ -316,9 +317,9 @@ def test_unremove_repository_failed(respx_mock):
assert route.called
request = respx_mock.calls.last.request
assert request.url == url
assert (
request._content == b'[{"op": "replace", "path": "/status", "value": "active"}]'
)
assert json.loads(request.content) == [
{"op": "replace", "path": "/status", "value": "active"}
]


def test_purge_repository(respx_mock):
Expand Down Expand Up @@ -503,7 +504,7 @@ def test_push(respx_mock):
'{"commitMessage": {"summary": "Upsert test.json", "detail": null, "markup": null}, '
'"changes": [{"path": "/test.json", "type": "UPSERT_JSON", "content": {"foo": "bar"}}]}'
)
assert request._content == bytes(str(payload), "utf-8")
assert json.loads(request.content) == json.loads(bytes(str(payload), "utf-8"))
assert ret.pushed_at == datetime.strptime(
mock_push_result["pushedAt"], DATE_FORMAT_ISO8601_MS
)
Expand Down
Loading
Loading