Skip to content

Commit

Permalink
Rename exception (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
epenet authored Dec 29, 2022
1 parent 35f3658 commit 294d96c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
10 changes: 5 additions & 5 deletions src/sfrbox_api/bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import httpx
from defusedxml.ElementTree import fromstring as xml_element_from_string

from .exceptions import SfrBoxError
from .exceptions import SFRBoxError
from .models import DslInfo
from .models import FtthInfo
from .models import SystemInfo
Expand All @@ -28,19 +28,19 @@ async def _send_get(self, namespace: str, method: str, **kwargs: str) -> XmlElem
try:
element: XmlElement = xml_element_from_string(response.text)
except Exception as exc:
raise SfrBoxError(f"Failed to parse response: {response.text}") from exc
raise SFRBoxError(f"Failed to parse response: {response.text}") from exc
stat = element.get("stat", "")
if (
stat == "fail"
and (err := element.find("err")) is not None
and (msg := err.get("msg"))
):
raise SfrBoxError(f"Query failed: {msg}")
raise SFRBoxError(f"Query failed: {msg}")
if stat != "ok":
raise SfrBoxError(f"Response was not ok: {response.text}")
raise SFRBoxError(f"Response was not ok: {response.text}")
result = element.find(namespace)
if result is None:
raise SfrBoxError(
raise SFRBoxError(
f"Namespace {namespace} not found in response: {response.text}"
)
return result
Expand Down
2 changes: 1 addition & 1 deletion src/sfrbox_api/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""SFR Box exceptions."""


class SfrBoxError(Exception):
class SFRBoxError(Exception):
"""SFR Box base exception."""
10 changes: 5 additions & 5 deletions tests/test_bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import respx

from sfrbox_api.bridge import SFRBox
from sfrbox_api.exceptions import SfrBoxError
from sfrbox_api.exceptions import SFRBoxError
from sfrbox_api.models import DslInfo
from sfrbox_api.models import FtthInfo
from sfrbox_api.models import SystemInfo
Expand Down Expand Up @@ -120,7 +120,7 @@ async def test_exception_fail() -> None:
async with httpx.AsyncClient() as client:
box = SFRBox(ip="192.168.0.1", client=client)
with pytest.raises(
SfrBoxError, match=re.escape("Query failed: [message-erreur]")
SFRBoxError, match=re.escape("Query failed: [message-erreur]")
):
await box.wan_get_info()

Expand All @@ -134,7 +134,7 @@ async def test_exception_invalid_xml() -> None:
)
async with httpx.AsyncClient() as client:
box = SFRBox(ip="192.168.0.1", client=client)
with pytest.raises(SfrBoxError, match="Failed to parse response: Invalid XML"):
with pytest.raises(SFRBoxError, match="Failed to parse response: Invalid XML"):
await box.wan_get_info()


Expand All @@ -147,7 +147,7 @@ async def test_exception_incorrect_xml() -> None:
)
async with httpx.AsyncClient() as client:
box = SFRBox(ip="192.168.0.1", client=client)
with pytest.raises(SfrBoxError, match="Response was not ok: <incorrect_xml />"):
with pytest.raises(SFRBoxError, match="Response was not ok: <incorrect_xml />"):
await box.wan_get_info()


Expand All @@ -160,5 +160,5 @@ async def test_exception_incorrect_namespace() -> None:
)
async with httpx.AsyncClient() as client:
box = SFRBox(ip="192.168.0.1", client=client)
with pytest.raises(SfrBoxError, match="Namespace wan not found in response"):
with pytest.raises(SFRBoxError, match="Namespace wan not found in response"):
await box.wan_get_info()

0 comments on commit 294d96c

Please sign in to comment.