Skip to content

Commit

Permalink
Merge pull request zhulik#11 from zhulik/add-system-connections
Browse files Browse the repository at this point in the history
Add the rest/system/connnections endpoint
  • Loading branch information
zhulik authored Jun 6, 2021
2 parents cb2bf14 + 20cd20d commit d46959f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
4 changes: 4 additions & 0 deletions aiosyncthing/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ async def resume(self, device_id=None):
except NotFoundError as error:
raise UnknownDeviceError from error

async def connections(self):
"""Get server connections."""
return await self._api.request("rest/system/connections")


def device_params(device_id):
"""Build params hash from the device_id."""
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

setup(
name="aiosyncthing",
version="0.6.2",
version="0.6.3",
author="Gleb Sinyavskiy",
author_email="zhulik.gleb@gmail.com",
description="Asynchronous Python client for the Syncthing REST API",
Expand Down
18 changes: 18 additions & 0 deletions tests/test_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,3 +196,21 @@ async def test_resume_unknown_device(system, aioresponses):
aioresponses.post("http://127.0.0.1:8384/rest/system/resume?device=device_id", status=404)
with pytest.raises(UnknownDeviceError):
await system.resume("device_id")


@pytest.mark.asyncio
async def test_connections_happy(system, aioresponses):
"""Test happy path."""
aioresponses.get(
"http://127.0.0.1:8384/rest/system/connections",
payload={"total": {"inBytesTotal": 9202826, "outBytesTotal": 16220852785}},
)
expect(await system.connections()).to(equal({"total": {"inBytesTotal": 9202826, "outBytesTotal": 16220852785}}))


@pytest.mark.asyncio
async def test_connections_error(system, aioresponses):
"""Test error path."""
aioresponses.get("http://127.0.0.1:8384/rest/system/connections", status=500)
with pytest.raises(SyncthingError):
await system.connections()

0 comments on commit d46959f

Please sign in to comment.