Skip to content

feat(report): wrap POST /report/import endpoint#184

Open
Valyrian-Code wants to merge 1 commit into
fossology:mainfrom
Valyrian-Code:feat/report-import-endpoint
Open

feat(report): wrap POST /report/import endpoint#184
Valyrian-Code wants to merge 1 commit into
fossology:mainfrom
Valyrian-Code:feat/report-import-endpoint

Conversation

@Valyrian-Code
Copy link
Copy Markdown
Contributor

@Valyrian-Code Valyrian-Code commented May 28, 2026

Adds Report.import_report() as a wrapper for POST /report/import, completing the report workflow alongside generate_report() and download_report().

The method imports external SPDX RDF reports via multipart upload and returns the scheduled reportImport job ID (int).

API Details

Validated against Fossology 4.4.0 / API 1.6.2.

  • Endpoint: POST /report/import
  • Query params: upload, reportFormat (spdxrdf currently required)
  • Multipart field: report
  • Optional params: addConcludedAsDecisions, groupName header

Success response:

{
  "code": 201,
  "message": <job_id_int>,
  "type": "INFO"
}

Tests

test_report.py now covers:

  • Successful round-trip flow:
    generate_report()download_report()import_report()
  • Unauthorized requests
  • 500 server errors
  • Malformed API responses

All 17 tests pass against the live Fossology container.

Refs #52.

cc @deveaud-m

Copilot AI review requested due to automatic review settings May 28, 2026 20:01
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds support for importing external SPDX reports into a Fossology upload and validates the new API behavior with tests.

Changes:

  • Introduce Fossology.import_report() that uploads a report file and schedules a reportImport job.
  • Add integration/unit tests covering success, authorization failure, server error, and unparseable API responses.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 6 comments.

File Description
fossology/report.py Adds import_report() API wrapper with response handling and errors.
tests/test_report.py Adds tests for report import scenarios (success + failure modes).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tests/test_report.py Outdated
Comment thread tests/test_report.py Outdated
Comment thread fossology/report.py
Comment thread fossology/report.py Outdated
Comment thread fossology/report.py Outdated
Comment thread fossology/report.py Outdated
@Valyrian-Code Valyrian-Code force-pushed the feat/report-import-endpoint branch from b9cf928 to 989ecab Compare May 28, 2026 20:08
@Valyrian-Code
Copy link
Copy Markdown
Contributor Author

Valyrian-Code commented May 28, 2026

All five review points addressed in 989ecab:

  1. Format alignment — added a comment in test_import_report clarifying that ReportFormat.SPDX2 produces SPDX 2.x RDF, matching the spdxrdf format accepted by import_report().

  2. Mocked 403 handlingtest_import_report_nogroup now uses @responses.activate with a mocked 403, removing environment-dependent authorization behavior.

  3. Docstring type fix — updated group to str | None to match the method signature.

  4. Consistent error identifiers — all import_report error paths now use the same {upload.uploadname} (id={upload.id}) format. Tests updated accordingly.

  5. Validation — all 17 tests in test_report.py pass locally against the live Fossology 4.4.0 container.

Add `Report.import_report()` to schedule a reportImport job for an
upload by uploading an external SPDX RDF report. Completes the report
triad with `generate_report` and `download_report`.

The endpoint is `POST /report/import?upload={id}&reportFormat={fmt}`
with the report file as a `report` multipart field. Response message
is the integer job id (returned directly, no string parsing).

Tests cover the live happy path (round-trip via generate → download →
import), the not-authorized path, the 500 error path, and a
defensively-parsed malformed-response path.

Refs fossology#52

Signed-off-by: RAJVEER42 <irajveer.bishnoi2310@gmail.com>
@Valyrian-Code Valyrian-Code force-pushed the feat/report-import-endpoint branch from 989ecab to 5e098fb Compare May 28, 2026 20:16
@Valyrian-Code
Copy link
Copy Markdown
Contributor Author

Valyrian-Code commented May 28, 2026

Trimmed the implementation after a second review pass.

The previous try/except (ValueError, KeyError, TypeError) block and its associated test only handled a contrived response shape (201 without a message field) that the server does not actually produce. Unlike generate_report(), there is no regex parsing here that requires defensive handling.

The implementation is now simply:

return int(response.json()["message"])

This removes unnecessary complexity and cuts 25 lines from the diff.

All 16 tests in test_report.py pass locally against the live Fossology 4.4.0 container.

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.

2 participants