feat: add import-institutions admin subcommand
What is this MR?
This MR introduces a new CLI capability to bulk import institutions from a CSV file into the system. It extends the existing admin command set by adding a dedicated subcommand for batch processing institutional data.
What does this MR do?
-
Adds a new CLI command:
corpus-client admin import-institutions <csv_path> -
Enables bulk creation of institutions by reading structured CSV input
-
Validates file existence before processing
-
Parses CSV rows using DictReader
-
Normalizes and transforms data to match backend API expectations:
- Converts numeric fields (e.g., college_code, revised_intake) to integers
- Maps district names to standardized enum values
- Normalizes categorical fields (e.g., college_type, management_type, medium, mode)
- Detects CBCS in course names, extracts it into a flag, and cleans the name
- Converts empty or placeholder values (-) to None
-
Sends one API request per row to
/api/v1/institutions -
Displays progress via spinner/progress indicator
-
Outputs a summary of successful and failed imports
-
Introduces
_admin_request_silenthelper for improved error handling during batch operations
Acceptance Criteria
- CLI command
corpus-client admin import-institutions <csv_path>is available and functional - Command exits with status code
1and shows an error message if the file does not exist - CSV rows are correctly parsed and transformed into API-compatible payloads
- Field normalization works correctly:
- Numeric fields are properly converted
- Enum and categorical values are standardized
- CBCS detection and transformation is accurate
- Empty or placeholder values are converted to
None
- Each valid row triggers an API request to create an institution
- Progress indicator is shown during execution
- Final output includes success and failure counts
- Failures in individual rows do not interrupt the entire import process
-
_admin_request_silentraises exceptions to allow controlled error handling
Test Coverage
- Added
tests/test_import_institutions.py - Covers:
- Successful import of multiple CSV rows
- Data normalization logic
- CBCS handling behavior
- Handling of missing or empty fields
- Missing file scenario
- Note: Incomplete rows are processed with
Nonevalues (not skipped), as validated by tests
Closes
- Closes #41 (closed)