Clone the repository to your local machine:
git clone <repository_url>
cd test_python
### Step 2: Create and Activate a Virtual Environment
python -m venv venv
source venv/bin/activate # On Windows use `venv\Scripts\activate`
### Step 3: Install Dependencies
pip install -r requirements.txt
### Step 4: Apply Migrations
python manage.py makemigrations
python manage.py migrate
### Step 5: Run the Development Server
python manage.py runserver
### Step 6: API Endpoints
# Books
GET /api/books/: Retrieve a list of all books.
GET /api/books/<id>/: Retrieve details of a specific book.
POST /api/books/: Create a new book.
PUT /api/books/<id>/: Update an existing book.
DELETE /api/books/<id>/: Delete a book.
# Authors
GET /api/authors/: Retrieve a list of all authors.
GET /api/authors/<id>/: Retrieve details of a specific author.
POST /api/authors/: Create a new author.
PUT /api/authors/<id>/: Update an existing author.
DELETE /api/authors/<id>/: Delete an author.
### Step 7: Running the Tests
python manage.py test
# You can also test the API endpoints using cURL commands. Here are some examples:
curl -X GET http://127.0.0.1:8000/api/books/
curl -X GET http://127.0.0.1:8000/api/books/1/
curl -X POST http://127.0.0.1:8000/api/books/ \
-H "Content-Type: application/json" \
-d '{"name": "New Author", "birth_date": "1990-03-17", "biography": "The Best of Python"}'
curl -X POST http://127.0.0.1:8000/api/books/ \
-H "Content-Type: application/json" \
-d '{"title": "New Book", "synopsis": "This is a new book", "publication_date": "2023-01-01", "authors": [1]}'
curl -X PUT http://127.0.0.1:8000/api/books/1/ \
-H "Content-Type: application/json" \
-d '{"title": "Updated Book", "synopsis": "This is an updated book", "publication_date": "2023-01-01", "authors": [1]}'
curl -X DELETE http://127.0.0.1:8000/api/books/1/