This is a mock backend server for a frontend developer hiring task. It provides API endpoints demonstrating role-based access control (admin vs regular user) using a simple in-memory database.
Features:
- Role-based access control (admin/user)
- Swagger documentation
- Mock authentication using static tokens
- CRUD operations for users and houses
- In-memory "database" (no persistence)
- Python 3.8+
- Dependencies from
requirements.txt
# Clone repository
git clone https://github.com/your-repo/hiring-task-backend.git
cd hiring-task-backend
# Set up virtual environment (recommended)
python3 -m venv venv
source venv/bin/activate # Windows: venv\Scripts\activate
# Install dependencies
pip install -r requirements.txt# Start development server
python app.py
# Server runs on:
# http://localhost:5000
# Swagger UI: http://localhost:5000/api/docsUse these mock tokens in request headers:
# Admin token
Authorization: mocked_admin_token
# Regular user token
Authorization: mocked_user_tokenLogin (get token):
curl -X POST -H "Content-Type: application/json" \
-d '{"role": "admin"}' \
http://localhost:5000/api/logincurl -X POST -H "Content-Type: application/json"
-d '{"role": "admin"}'
https://architecture-453906.ew.r.appspot.com/api/login
Create User (Admin only):
curl -X POST -H "Authorization: mocked_admin_token" \
-H "Content-Type: application/json" \
-d '{"username": "newuser", "role": "user"}' \
http://localhost:5000/api/userCreate House (Any user) :
curl -X POST -H "Authorization: mocked_user_token" \
-H "Content-Type: application/json" \
-d '{"address": "456 Oak St", "num_rooms": 4, "price": 300000}' \
http://localhost:5000/api/houseYou can run the tests with
python -m unittest test_app.py