From e356dc2be593ffa534bd3bb088fcc1828eb08146 Mon Sep 17 00:00:00 2001 From: "coderabbitai[bot]" <136622811+coderabbitai[bot]@users.noreply.github.com> Date: Tue, 24 Feb 2026 12:20:42 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=9D=20Add=20docstrings=20to=20`v2.0`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Docstrings generation was requested by @AgustinPelaez. * https://github.com/ubidots/ubidots-python/pull/26#issuecomment-3948449398 The following files were modified: * `setup.py` * `tests/test_client.py` * `tests/test_http.py` * `ubidots/_endpoints.py` * `ubidots/_http.py` * `ubidots/client.py` * `ubidots/exceptions.py` --- setup.py | 9 +++ tests/test_client.py | 6 ++ tests/test_http.py | 16 +++++ ubidots/_endpoints.py | 85 ++++++++++++++++++++++ ubidots/_http.py | 83 ++++++++++++++++++++++ ubidots/client.py | 159 ++++++++++++++++++++++++++++++++++++++++++ ubidots/exceptions.py | 34 +++++++++ 7 files changed, 392 insertions(+) diff --git a/setup.py b/setup.py index 4953de6..af581ad 100644 --- a/setup.py +++ b/setup.py @@ -2,6 +2,15 @@ def read_file(name): + """ + Read and return the entire contents of a text file. + + Parameters: + name (str): Path to the file to read. + + Returns: + contents (str): The file contents as a string. + """ with open(name, "r") as f: return f.read() diff --git a/tests/test_client.py b/tests/test_client.py index dbb7743..9c476cd 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -7,6 +7,12 @@ @pytest.fixture def api(): + """ + Pytest fixture that provides a Ubidots client with its HttpClient replaced by a mock. + + Returns: + Ubidots: A Ubidots instance whose internal HTTP client (`_http`) is the mocked HttpClient for use in tests. + """ with patch("ubidots.client.HttpClient") as MockHttp: client = Ubidots("test-token") client._http = MockHttp.return_value diff --git a/tests/test_http.py b/tests/test_http.py index d1e93a3..376b37b 100644 --- a/tests/test_http.py +++ b/tests/test_http.py @@ -14,6 +14,12 @@ @pytest.fixture def http(): + """ + Provide a configured HttpClient instance for tests. + + Returns: + HttpClient: an HttpClient initialized with the token "test-token". + """ return HttpClient("test-token") @@ -31,6 +37,16 @@ def test_custom_timeout(self): class TestRaiseForStatus: def _response(self, status_code, text="error detail"): + """ + Create a MagicMock representing an HTTP response with the given status and text. + + Parameters: + status_code (int): HTTP status code to set on the mock response. + text (str): Response body text to set on the mock response. + + Returns: + MagicMock: A mock response with `ok` set to True for status codes < 400, and `status_code` and `text` attributes set accordingly. + """ resp = MagicMock() resp.ok = status_code < 400 resp.status_code = status_code diff --git a/ubidots/_endpoints.py b/ubidots/_endpoints.py index 2306979..6c92195 100644 --- a/ubidots/_endpoints.py +++ b/ubidots/_endpoints.py @@ -8,27 +8,83 @@ class Endpoints: """URL builders for Ubidots v1.6 and v2.0 APIs.""" def __init__(self, base_url=DEFAULT_BASE_URL): + """ + Initialize the Endpoints instance with a sanitized base URL. + + Parameters: + base_url (str): Base URL used for building API endpoints; any trailing '/' is removed before storage. + """ self.base_url = base_url.rstrip("/") def _v2(self, path): + """ + Builds a full Ubidots v2.0 API URL for the given path. + + Parameters: + path (str): Path relative to the v2 API prefix (e.g. '/devices' or '/devices/{id}'); may include a leading slash. + + Returns: + url (str): Full URL for the v2.0 endpoint. + """ return f"{self.base_url}{V2_PREFIX}{path}" def _v1(self, path): + """ + Build the full v1.6 API URL for the given path. + + Parameters: + path (str): Path to append to the v1.6 API prefix (e.g., '/devices' or '/devices/