Repository navigation
test: add unit tests for api/utils.py (coverage 41% → 100%) - #105
Professor471 wants to merge 5 commits into
Conversation
|
No actionable comments were generated in the recent review.
|
| Layer / File(s) | Summary |
|---|---|
File URL parsing databusclient/api/utils.py, tests/test_api_utils.py |
The redundant inner docstring is removed. Tests cover parsed URL components, missing or extra components, HTTP and HTTPS, trailing slashes, and empty input. |
File metadata checks tests/test_api_utils.py |
Tests check SHA-256 digests and byte lengths for empty and nonempty files, and verify the missing-file error. |
JSON-LD fetch tests tests/test_api_utils.py |
A fake response supports tests for the Accept header, optional X-API-KEY header, returned response text, and HTTP error propagation. |
Priority:
Estimated code review effort: 2 (Simple) | ~10 minutes
Change: Other
Possibly related PRs
- dbpedia/databus-python-client#99: Changes
fetch_databus_jsonldheader handling, which is directly covered by the new fetch tests.
Suggested reviewers: dhanashreepetare
Merge Risk: 
Minimal · up to 0701e
-
The changes add utility tests and remove a redundant docstring. No merge-blocking risk is identified.
Pre-merge checks: 
4 · 
1
-
Failed checks: 1 warning Passed checks: 4 passed-
Full details: Description check
-
Explanation
The description explains the test scope, behavior coverage, duplicate docstring removal, reported results, related issues, change type, and checklist status. It also clarifies that commands ran in a virtual environment rather than through Poetry.
-
Full details: Docstring Coverage
-
Explanation
Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 1 functions across 2 files.
Resolution
Write docstrings for the functions missing them to satisfy the coverage threshold.
-
Finishing Touches
-
🧪 Generate unit tests (beta)
-
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Comment @coderabbitai help to get the list of available commands.
Pull Request
Description
Hi! This PR adds tests for the three small helpers in
databusclient/api/utils.py. They're used by download, deploy and delete, but had almost no tests watching them, so I gave them some company. Coverage for that file goes from 41% to 100%. Nothing in the actual behavior changes.The new file is
tests/test_api_utils.py, with 12 tests:get_databus_id_parts_from_file_url: a full URL, a short one (fills the gaps with None), http vs https, a trailing slash, an empty string, and a URL with too many partscompute_sha256_and_length: a normal file, an empty file, and a file that doesn't exist. I checked the expected hashes againstsha256sum, not against the function itself.fetch_databus_jsonld: the Accept header, the X-API-KEY header when a key is passed, and an error when the server fails.requests.getis faked, so the tests never actually call the server.I also removed a duplicate docstring in
get_databus_id_parts_from_file_url, in a separate commit. The second one was never used.One thing I noticed: if a URL has more than six parts, the extra ones are quietly dropped, with no error. My test just records how it works today. If you'd rather it raise an error or warn, I'm happy to open an issue.
ruff check .passes (0.5.7, same as poetry.lock) and pytest shows 210 passed, 3 skipped.Related Issues
None directly. Addresses the low test coverage mentioned in the README's Testing section.
Type of change
Checklist:
poetry run pytest- all tests passedpoetry run ruff check- no linting errors(Ran pytest and ruff 0.5.7 in a venv instead of Poetry; same versions as poetry.lock.)
Summary by CodeRabbit