This is a simple Flask web application with unit tests. The application provides a basic REST API for managing a list of items. It serves as a starting point for learning how to create a Flask application and write tests for it.
The project is organized as follows:
app/: Contains the Flask application and routes.tests/: Houses unit tests for the application.run.py: A script to run the Flask application.
To get the Flask app up and running on your local machine, follow these steps:
-
Clone the Repository:
git clone <repository_url> cd flask_sample_app
-
Set Up a Virtual Environment:
It's recommended to create a virtual environment to isolate project dependencies.
python -m venv venv source venv/bin/activate # On Windows, use venv\Scripts\activate
-
Install Dependencies:
Install the necessary dependencies using
pip:pip install -r requirements.txt
-
Run the Application:
Start the Flask application:
python run.py
The app will be available at http://localhost:5000.
-
Run Tests:
To run the unit tests, execute the following command:
python -m unittest discover tests
This command will discover and run all tests in the
testsdirectory.
The application provides the following routes:
GET /: Returns a simple greeting message.GET /items: Returns a list of items.GET /items/{item_id}: Returns the details of a specific item.POST /items: Adds a new item to the list.
Unit tests are provided in the tests directory. They cover the basic functionality of the application, including route handling and response validation. You can use these tests as a reference to write your own tests or to verify the correctness of the application.
This project is licensed under the MIT License - see the LICENSE file for details.
Feel free to contribute to this project by opening issues or submitting pull requests. We welcome any improvements, bug fixes, or additional features.
- Pan Luo
- This project was created as a sample Flask application for educational purposes.
- Special thanks to the Flask community for providing a fantastic web framework.
Enjoy experimenting with the Flask sample app! If you have any questions or need further assistance, please don't hesitate to reach out.