Skip to content

feat(license): wrap POST /license/import-csv endpoint#185

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

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

Conversation

@Valyrian-Code
Copy link
Copy Markdown
Contributor

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

Refs #52.

Wraps the POST /license/import-csv endpoint as LicenseEndpoint.import_licenses_csv().

Performs a multipart upload of a CSV file with optional delimiter (default ",") and enclosure (default "\""), returning the server's multi-line summary message indicating inserted and already-existing rows.

The implementation matches the live contract verified against Fossology 4.4.0:

  • Endpoint path is /license/import-csv (the OpenAPI spec was renamed from the original /license/import in feat(API): import csv-license file fossology#2292; the current spec lives alongside /license/export-csv, /license/import-json, /license/export-json)

  • Required field: file_input; optional delimiter, enclosure

  • 200 success → Info schema with multi-line message

  • 400 → validation error

Tests cover the live happy path by round-tripping a small CSV against the container (the server is idempotent on duplicate shortnames, so repeated test runs do not pollute state), as well as a mocked 400 Bad Request error path.

Copilot AI review requested due to automatic review settings May 31, 2026 16:32
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 a new import_licenses_csv method to the Fossology license API wrapper, enabling bulk import of licenses from a CSV file via POST /license/import-csv, along with tests for success and error scenarios.

Changes:

  • New import_licenses_csv method on the license client with delimiter/enclosure options.
  • Integration-style test for successful CSV import.
  • Mocked test for error handling on import failure.

Reviewed changes

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

File Description
fossology/license.py Implements the CSV license import API method.
tests/test_license.py Adds success and error tests for the new method.

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

Comment thread fossology/license.py
Comment thread fossology/license.py
Comment thread tests/test_license.py
Add `LicenseEndpoint.import_licenses_csv()` to import a CSV file of
license rows via the Fossology REST API. Multipart form-data with
required `file_input` plus optional `delimiter` and `enclosure`.

Returns the server's multi-line summary message (inserted /
already-existing rows).

Tests cover the live happy path (round-trip a small CSV against the
container; the server is idempotent for duplicate shortnames) and a
mocked 400 error path.

Refs fossology#52

Signed-off-by: RAJVEER42 <irajveer.bishnoi2310@gmail.com>
@Valyrian-Code Valyrian-Code force-pushed the feat/license-import-endpoint branch from e0862cf to 230fbe4 Compare May 31, 2026 16:36
@Valyrian-Code
Copy link
Copy Markdown
Contributor Author

Valyrian-Code commented May 31, 2026

Reviewed each suggestion against the rest of the codebase and applied only the one that is consistent with the existing project style.

Applied — payload-asserting mocked test (230fbe4)

Added test_import_licenses_csv_request_payload using @responses.activate. The test verifies that the multipart request contains:

  • The correct file_input field name
  • The configured delimiter value
  • The configured enclosure value
  • The expected CSV content

This addressed a genuine coverage gap.

Not applied — str | Path parameter type

Checked existing file-upload APIs for consistency. upload_file (uploads.py:136) uses file: str | None, and pathlib.Path appears only once within the fossology/ package (foss_cli.py:404), not in any library-facing API.

Keeping csv_file: str preserves the established convention used throughout the library.

Not applied — FileNotFoundError documentation and HTTP error wrapping

Verified that the sibling add_license implementation follows the same error-handling pattern: it checks expected status codes (201, 409) and raises FossologyApiError for other responses. import_licenses_csv follows that same approach.

Additionally, none of the existing file-based methods (upload_file, add_license) explicitly document FileNotFoundError. Introducing that documentation for a single method would be inconsistent with the current API surface.

If the project wants to adopt either of these patterns, it would be better handled as a separate, repository-wide change affecting the existing methods as well.

All 16 tests in test_license.py pass locally against a live Fossology 4.4.0 container.

@Valyrian-Code
Copy link
Copy Markdown
Contributor Author

Valyrian-Code commented May 31, 2026

cc @deveaud-m

Could you please review this when you have a moment?
Thank you.

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