- Add tests/ directory with pytest configuration - Add conftest.py with database fixtures (test_db, sample data) - Add test_core.py: 21 tests for core operations (tablet, user, loan CRUD) - Add test_edge_cases.py: 14 tests for edge cases (duplicates, invalid IDs, etc.) - Add test_minimal_app.py: 11 tests for actual application functions - Update pyproject.toml with pytest and coverage configuration - Total: 46 tests covering core functionality and edge cases Tests cover: - Tablet CRUD operations - User CRUD operations - Loan/return workflows - Duplicate prevention (serial numbers, identifications) - Invalid ID handling - Already loaned device prevention - Non-existent loan handling - Multiple loans per user (one-to-many relationship) - Non-loanable device CRUD operations To run: python3 -m pytest tests/ -v |
||
|---|---|---|
| templates | ||
| tests | ||
| .gitignore | ||
| app.py | ||
| basic_server.py | ||
| check_flask.py | ||
| CONTRIBUTING.md | ||
| debug_server.py | ||
| gestiontablets.sh | ||
| index.html | ||
| main.py | ||
| minimal_app.py | ||
| pyproject.toml | ||
| README.md | ||
| REQUIREMENTS.md | ||
| requirements.txt | ||
| RUNNING.md | ||
| setup.py | ||
| simple_app.py | ||
| TECHNICAL_SPECIFICATIONS.md | ||
| test_app.py | ||
| working_server.py | ||
Tablet Lending and Return Management System
A simple SQLite-based system for managing tablet lending and returns.
Features
- Tablet Management: Add, track, and manage tablets in inventory
- User Management: Register users who can borrow tablets
- Loan Tracking: Track which tablets are loaned to which users
- Return Management: Record when tablets are returned
- History Tracking: Complete history of all loans and returns
- User Loans View: See all tablets loaned to each user (demonstrates one-to-many relationship)
- Non-Loanable Devices: Track inventory devices that cannot be loaned (e.g., projectors, monitors)
- Project Notes: Markdown editor for development documentation
Files
minimal_app.py- Interactive command-line application (includes non-loanable device management)test_app.py- Test script that demonstrates functionalitytablets.db- SQLite database (created automatically, includes non_loanable_devices table)simple_app.py- Web-based version (requires Flask, includes non-loanable device management)app.py- Alternative web version (requires Flask, includes non-loanable device management)
Quick Start
1. Run the test to see it in action
python3 test_app.py
This will:
- Create the database
- Add sample tablets and users
- Demonstrate loan and return operations
- Show the complete workflow
2. Run the interactive application
python3 minimal_app.py
This provides a menu-driven interface for:
- Adding tablets
- Adding users
- Loaning tablets
- Returning tablets
- Viewing inventory and loan status
3. Database Structure
The system uses three main tables with a many-to-many relationship between users and tablets:
tablets
id: Primary keybrand: Tablet brandmodel: Tablet modelserial_number: Unique serial numberstatus: 'available' or 'loaned'
users
id: Primary keyname: User's nameidentification: Unique identification
loans (junction table)
id: Primary keytablet_id: Foreign key to tabletsuser_id: Foreign key to usersloan_date: When the tablet was loanedreturn_date: When the tablet was returned (NULL if still active)status: 'active' or 'returned'
Note
: The loans table enables a many-to-many relationship. One user can loan multiple tablets (one-to-many from user to loans), and each tablet can be loaned to different users over time. The
statusfield on tablets ensures a device can only be loaned to one user at a time.
Requirements
- Python 3.x (built-in sqlite3 module)
- No additional dependencies needed for the command-line version
- Flask required for web versions (optional)
Usage Examples
Adding a tablet
python3 -c "
import sqlite3
conn = sqlite3.connect('tablets.db')
cursor = conn.cursor()
cursor.execute('INSERT INTO tablets (brand, model, serial_number, status) VALUES (?, ?, ?, ?)',
('Microsoft', 'Surface Pro', 'SN004', 'available'))
conn.commit()
conn.close()
print('Tablet added!')
"
Adding a user
python3 -c "
import sqlite3
conn = sqlite3.connect('tablets.db')
cursor = conn.cursor()
cursor.execute('INSERT INTO users (name, identification) VALUES (?, ?)',
('Alice Brown', 'ID004'))
conn.commit()
conn.close()
print('User added!')
"
Querying available tablets
python3 -c "
import sqlite3
conn = sqlite3.connect('tablets.db')
cursor = conn.cursor()
cursor.execute('SELECT brand, model, serial_number FROM tablets WHERE status = ?', ('available',))
for row in cursor.fetchall():
print(f'{row[0]} {row[1]} ({row[2]})')
conn.close()
"
Web Version (Optional)
If you want to use the web interface:
- Install Flask:
pip install flask
- Run the web application:
python3 app.py
- Open your browser to: http://localhost:5000
Web Features
- Home: View available tablets and active loans
- Loan Tablet: Loan a tablet to a user (with search for large datasets)
- User Loans: View all tablets loaned to each user - demonstrates the one-to-many relationship (one user, multiple tablets)
- Loan History: Complete history of all loan and return transactions
- Non-Loanable Devices: Manage inventory of devices that cannot be loaned (add, edit, delete, view)
- Project Management: Markdown editor for development notes (saved to
notes_development/project_notes.md)
Database Backup
To backup your data:
cp tablets.db tablets_backup_$(date +%Y%m%d).db
Version Control
This project uses Git for version control with the following structure:
master- Production-ready releasesdevelop- Integration branch for featuresfeature/*- Individual feature brancheshotfix/*- Urgent bug fixes
See CONTRIBUTING.md for detailed workflow and commit conventions.
License
This is a simple educational project. Feel free to use and modify it as needed.