This project offers a framework and tools for automated API testing using Python, Requests, and Pytest, following Data-Driven Testing (DDT) best practices and employing the Service Object Model design pattern.
This suite of tests is focused on validating and testing CRUD (Create, Read, Update, Delete) operations related to user management within the Swagger Petstore API (Base URL: https://petstore.swagger.io). Specifically, the tests interact with the following endpoints:
- Create User (POST): Endpoint URL: https://petstore.swagger.io/v2/user
- Get User (GET): Endpoint URL: https://petstore.swagger.io/v2/user/{username}
- Update User (PUT): Endpoint URL: https://petstore.swagger.io/v2/user/{username}
- Delete User (DELETE): Endpoint URL: https://petstore.swagger.io/v2/user/{username}
These tests are designed to ensure the functionality and correctness of these user management endpoints provided by the Swagger Petstore API. They interact with the defined URLs in the Routes class to perform comprehensive testing of user-related functionalities.
- Python 3.10.11
- Requests 2.31.0
- Pytest 7.4.3
- Faker 20.1.0
- Openpyxl 3.1.2
- allure-pytest 2.13.2
- logging.conf: Configuration file for logging setup.
- requirements.txt: File listing required Python packages for the project.
- run.bat: Script file specifically designed for execution in Windows environments.
- Userdata.xlsx: Excel file containing user data used in testing.
- routes.py: Defines URLs for CRUD operations related to user management.
- user_endpoints.py: Encapsulates HTTP requests for user-related API endpoints.
- user.py: Class representing user data for API operations.
- ddt_user_test.py: Implements Data-Driven Testing (DDT) for users.
- user_test.py: Contains test methods to perform CRUD operations on user endpoints using generated/fake data.
- excel_helper.py: Handles Excel file operations.
-
Clone this repository:
git clone https://github.com/carlosvagnoni/python_requests_pytest.git cd python_requests_pytest
-
Install dependencies:
pip install -r requirements.txt
- Userdata.xlsx can be modified to add any necessary data. The file accepts an arbitrary amount of data, accommodating any quantity of entries.
Run all the tests:
pytest --alluredir=test_results/report_allure
Open report:
allure serve test_results/report_allure
NOTE:
- Set up the respective environment variables beforehand.
- On Windows environments, you can directly execute the
run.bat
file.
If you have any questions or suggestions, feel free to contact me through my social media accounts.
Thank you for your interest in this project!