This project is a command-line Warehouse Management System implemented in Python. It allows users to manage warehouse entries stored in a CSV file (warehouse.csv) in the current working directory.
- Create: Add new items to the warehouse with comprehensive validation.
- Update: Modify any field of an existing item with field-specific validation.
- Delete: Remove items from the warehouse by ID.
- Enhanced Validation:
- Item names with sanitization and special character validation
- Quantity validation (positive integers, configurable maximum)
- Date validation (YYYY-MM-DD format, minimum date enforcement)
- Time validation (24-hour HH:MM format)
- Operation type validation and normalization
- Operator name validation (letters, spaces, hyphens, apostrophes only)
- Security Features: CSV injection prevention and Unicode normalization
- Duplicate Detection: Warning system for duplicate item names
- Auto-ID Generation: Unique, sequential ID assignment
- Error Handling: Comprehensive error messages for all validation failures
The warehouse.csv file contains the following columns:
- ID: Numeric, unique, autogenerated.
- Item Name: Text, required.
- Quantity: Positive integer, required.
- Date:
YYYY-MM-DD, required, autogenerated if not provided. - Time:
HH:MM(24-hour), required, autogenerated if not provided. - Operation: Text, required.
- Operated By: Text, required.
Run the program from the command line:
python solution.py <command> [arguments]Add a new item (all fields are required):
python solution.py create <item_name> <quantity> <operation> <operated_by> <date> <time>- All parameters are mandatory - no auto-generation of date/time
- Item names are sanitized and validated for security
- Quantities must be positive integers (1-999999)
- Operations are normalized to uppercase
- Operated by field accepts only valid name formats
Update a field of an item:
python solution.py update <id> <item_name|quantity|operation|operated_by|date|time> <value>Delete an item by ID:
python solution.py delete <id>- ID: Auto-generated, unique, sequential numeric values
- Item Name:
- Cannot be empty or whitespace-only
- Cannot contain only special characters (-, _, .)
- Sanitized for CSV injection prevention
- Unicode normalized for consistency
- Duplicate name warnings provided
- Quantity:
- Must be positive integer (no decimals)
- Range: 1 to 999,999
- Cannot be zero or negative
- Date:
- Must be in YYYY-MM-DD format
- Must be a valid calendar date
- Cannot be earlier than 2020-01-01
- Handles leap years correctly
- Time:
- Must be in HH:MM format (24-hour)
- Valid hours: 00-23, Valid minutes: 00-59
- Operation:
- Cannot be empty
- Automatically converted to uppercase
- Sanitized for security
- Operated By:
- Cannot be empty
- Only letters, spaces, hyphens, and apostrophes allowed
- Sanitized for security
- Invalid command:
ERROR: Invalid command provided. Use <create>, <update>, or <delete>.
- Missing fields:
ERROR: Provide all required fields. Use <item_name>, <quantity> <operation> <operated_by> <date> <time>. - Empty item name:
ERROR: Item name cannot be empty. - Invalid item name:
ERROR: Item name cannot contain only special characters. - Invalid quantity:
ERROR: Quantity must be a positive number. - Decimal quantity:
ERROR: Quantity must be a non decimal number. - Quantity too large:
ERROR: Quantity cannot exceed 999999. - Invalid date:
ERROR: Date is not valid. Use the format YYYY-MM-DD. - Date too early:
ERROR: Date cannot be earlier than 2020-01-01. - Invalid time:
ERROR: Time is not valid. Use the format HH:MM (24 hour clock). - Invalid operation: Field-specific validation messages
- Invalid operator name:
ERROR: Operated by can only contain letters, spaces, hyphens, and apostrophes.
- Missing fields:
ERROR: Provide all required fields. Use <id> <item_name|quantity|operation|operated_by|date|time> <value> - Invalid ID:
ERROR: Invalid ID provided - Field-specific validation errors (same as create command)
- Invalid ID:
ERROR: Invalid ID provided
- Duplicate names:
WARNING: An item with name '<name>' already exists (ID: <id>).
- Create:
Item successfully created: ID: <id> Item name: <item_name> Quantity: <quantity> Operation: <operation> Operated by: <operated_by> Date: <date> Time: <time> - Update:
Item with the ID <id> has been updated successfully: ID: <id> Item name: <item_name> Quantity: <quantity> Operation: <operation> Operated by: <operated_by> Date: <date> Time: <time> - Delete:
The following entry has been deleted successfully: ID: <id> Item name: <item_name> Quantity: <quantity> Operation: <operation> Operated by: <operated_by> Date: <date> Time: <time>
The project includes comprehensive test coverage with pytest. Run the test suite with:
pytest test.pyThe test suite includes 40+ test cases covering:
Create Operation Tests:
- Successful creation with all valid inputs
- Missing field validation (arguments and empty values)
- Item name validation (empty, whitespace, special characters only)
- Quantity validation (non-numeric, decimals, negative, zero, maximum limits)
- Date validation (invalid formats, leap years, month/day limits, minimum date)
- Time validation (invalid hours/minutes, format validation)
- ID auto-generation and uniqueness
Update Operation Tests:
- Successful updates for all fields (item_name, quantity, operation, operated_by, date, time)
- Missing argument validation
- Invalid field name validation
- Invalid ID handling (non-existent, empty, non-numeric)
- Field-specific validation (same as create tests)
Delete Operation Tests:
- Successful deletion with proper output
- Invalid ID handling (non-existent, empty, missing arguments)
- Proper CSV file updates after deletion
General Command Tests:
- Invalid command handling
- Missing command handling
- Proper error message formatting
Edge Case Tests:
- Boundary value testing (min/max quantities, edge dates)
- Special character handling and sanitization
- Unicode normalization testing
- CSV injection prevention
- Tests use automatic cleanup fixtures to ensure test isolation
- Each test runs with a fresh
warehouse.csvfile - Subprocess execution for realistic CLI testing
- Parameterized tests for efficient validation testing
Install dependencies with:
pip install -r requirements.txtDependencies include:
pytest>=8.4.1- Testing frameworkpython-dateutil>=2.9.0- Enhanced date handling- Additional validation libraries for robust input sanitization
Python Version: 3.x (tested with Python 3.13)
The system includes configurable parameters in solution.py:
CONFIG = {
'max_quantity': 999999, # Maximum allowed quantity
'min_quantity': 1, # Minimum allowed quantity
'duplicate_name_warning': True, # Enable duplicate name warnings
'min_date': '2020-01-01', # Earliest allowed date
}- CSV Injection Prevention: Automatically sanitizes input to prevent formula injection
- Unicode Normalization: Ensures consistent character encoding
- Input Validation: Strict validation prevents malformed data entry
- Safe File Operations: Atomic CSV operations prevent data corruption
- The CSV file (
warehouse.csv) is created automatically if it does not exist - All operations maintain data integrity through comprehensive validation
- The system is designed for command-line operation with clear error reporting
- IDs are automatically generated and guaranteed to be unique and sequential
- All operations provide detailed success/failure feedback