Skip to content

test: add unit tests for api/utils.py (coverage 41% → 100%) - #105

Open
Professor471 wants to merge 5 commits into
dbpedia:mainfrom
Professor471:test-api-utils
Open

Professor471 wants to merge 5 commits into
dbpedia:mainfrom
Professor471:test-api-utils

Conversation

@Professor471

@Professor471 Professor471 commented Oct 28, 2026 •

Copy link
Copy Markdown

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 parts
  • compute_sha256_and_length: a normal file, an empty file, and a file that doesn't exist. I checked the expected hashes against sha256sum, 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.get is 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

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • This change requires a documentation update
  • Housekeeping

Checklist:

  • My code follows the ruff code style of this project.
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation (if applicable)
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
    • poetry run pytest - all tests passed
    • poetry 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

  • Tests
    • Added coverage for Databus URL parsing, file metadata calculations, and JSON-LD fetching, including common input variations and error cases.

@coderabbitai

coderabbitai Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: d5ae427f-2100-4e01-978d-15269ab38556
Commits

Reviewing files that changed from the base of the PR and between 0dc1982 and 0701e66.

Files selected for processing: 2
  • databusclient/api/utils.py
  • tests/test_api_utils.py

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

Walkthrough

The pull request removes a redundant docstring from the file-URL parsing function and adds tests for URL parsing, file hashes and lengths, and JSON-LD fetching.

Changes: Databus API utilities

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: Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Other

Possibly related PRs

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: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning 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. Documentat… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description check Passed 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 v…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Title check Passed The title clearly and concisely describes the main change: adding unit tests for api/utils.py and increasing coverage.
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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@Professor471 Professor471 changed the title Test: add unit tests for api/utils.py (coverage 41% → 100%) test: add unit tests for api/utils.py (coverage 41% → 100%) Oct 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant