Parrot
Web-service for testing http requests and webhooks.
Build:
Links:
- Repository: https://github.com/Uma-Tech/parrot
- Documentation: https://uma-tech.github.io/parrot/
- Docker Hub: https://registry.hub.docker.com/r/umahighload/parrot-app
- Issue tracker: https://github.com/Uma-Tech/parrot/issues
- Changelog: https://github.com/Uma-Tech/parrot/blob/develop/CHANGELOG.md
Components
- Database postgres.
- Database redis (for background celery-tasks).
- Python-app based on Django Web Framework.
Contributing
We welcome all contributions!
See CONTRIBUTING.md if you want to contribute.
You can start with issues that need some help
right now.
Screenshots
Quick Start
System requirements
- docker (https://www.docker.com/)
- docker-compose (https://github.com/docker/compose)
- make
(https://www.gnu.org/software/make/)
(all commands can be viewed by calling
make
without parameters) - poetry (for development) (https://python-poetry.org/)
Local run
Quickstart (with Docker)
-
Clone the repo
git clone git@github.com:Uma-Tech/parrot.git cd parrot
-
Build or download the docker image
for buildmake build
for download
docker pull umahighload/parrot-app:latest
-
Apply migrations and create a superuser:
make shell # inside the container python manage.py migrate # apply migrations python manage.py createsuperuser # create a superuser exit ## leave from the container
-
Start the app and its dependencies
make runserver
-
You will be able to access the service at
http://127.0.0.1:8042/
Start the project for development without Docker
-
Clone the repo and go to the project directory
git clone git@github.com:Uma-Tech/parrot.git cd parrot
-
Install dependencies
poetry install
-
Start databases
You can start databases in any other way# start postgres docker run \ --name postgres \ -d \ --rm \ -e POSTGRES_PASSWORD=parrot \ -e POSTGRES_USER=parrot \ --network host \ -v parrot_db:/var/lib/postgresql/data \ postgres # start redis docker run \ --name redis \ -d \ --rm \ --network host \ redis
-
Setting required environment variables
export PARROT_DB_HOST=127.0.0.1 export PARROT_SECRET_KEY=NO_SECRET export PARROT_CELERY_BROKER_URL=redis://127.0.0.1
Alternatively, you can create a local
.env
file with the variables -
Build static
poetry run python manage.py collectstatic --no-input
-
Apply database migrations
poetry run python manage.py migrate
-
Create a django superuser
poetry run python manage.py createsuperuser
-
Start the django app
poetry run python manage.py runserver
-
Start the celery worker
Run in a separate terminal windowpoetry run celery -A parrot worker -l INFO -c 4
Usage
First steps
Create an http-stub
- Go to
HTTP Stubs
->Stubs
- Click the
Add
button - Fill in the required fields
- Click the
Save
button
Logs
- Send a http-request to the created http-stub
- Go to
HTTP Stubs
->Logs
- Watch incoming requests :)
Use request scripts
For using it
- Create an http stub (first steps)
- In the "request script" field, add a Python script
About scripts
Request scripts support a secure subset of Python version 3.8.
Additionally, json and requests modules are available to the script.
As well as a special variable that stores the request body request_body
.
Examples
Calling external services
# get request
requests.get('https://example.com/')
# post request
payload = {'key1': 'value1', 'key2': 'value2'}
requests.post('https://example.com/', data=payload)
# put request
payload = {'key1': 'new value'}
requests.put('https://example.com/', data=payload)
For more examples, see the official documentation https://requests.readthedocs.io/en/master/.
Parsing the request body in json format
For example, use the preset variable request_body
.
request_body
is a variable containing a body of the request received by Parrot.
parsed_data = json.loads(request_body)
requests.post(
'https://example.com/',
data={'user': parsed_data['request_user']}
)
Version history
We follow Semantic Versions.
1.1.0 - Disable logs by default
Important changes
- Disable the log for a specific stub #110
Updating dependencies
- django-simpleui from 2021.1.1 to 2021.3 #106
- django-extensions from 3.1.0 to 3.1.1 #101
- pytest-cov from 2.10.1 to 2.11.1 #96
- pytest from 6.2.1 to 6.2.2 #97
- uvicorn from 0.13.2 to 0.13.4 #105
- django from 3.1.4 to 3.1.7 #104
- flake8-annotations-coverage from 0.0.4 to 0.0.5 #94
- ipython from 7.19.0 to 7.21.0 #107
1.0.1 - Improving docs
Important changes
- Improving docs #91
Updating dependencies
- django-simpleui from 2020.9.26 to 2021.1.1 #80
- pytest from 6.1.2 to 6.2.1 #88
- uvicorn from 0.12.3 to 0.13.2 #89
1.0.0 - First stable release
New functionality
- Custom script for each request #70
Bug fixes
- Fix absolute request url in HttpStubAdmin with regex #78
Minor improvements
0.1.10
- Fixed issue with Vue breaking on log entries #79
0.1.9
- Fixed enormously long logs page loading time #75
- Added django-extensions and ipython for ease of development #74
0.1.8
- Fixed regex stubs with query args #69
0.1.7
- Fix build #66
0.1.6
- Changed max_length for LogEntry.path #65
- Move django secret key to env vars #61
- Added reading environment from the .env file #60
0.1.5
- Add PARROT_ALLOWED_HOSTS env var #63
0.1.4
- Remove inline logs from http-stub page #58
0.1.3
- Translate into English the popup text #50
- Limit the maximum number of query log entries #16
- Add a request url to the stub edit page #35
- Updates lots of dependencies (issues)
0.1.2
0.1.1
This is the first public version of the project. Happy Birthday Parrot!
How to contribute
First steps
- Fork our repo, here's the guide on forking
- Clone your new repo (forked repo) to have a local copy of the code
- Apply the required changes!
- Send a Pull Request to our original repo. Here's the helpful guide on how to do that
Dependencies
We use poetry to manage the dependencies.
To install them you would need to run install
command:
poetry install
To activate your virtualenv
run poetry shell
.
Two magic command
Run make autotests
or make lint
to run checks in docker/
Tests
We use pytest
and flake8
for quality control.
We also use wemake_python_styleguide
.
To run all tests:
pytest
To run linting:
flake8 .
Before submitting
Before submitting your code please do the following steps:
- Run
pytest
to make sure everything was working before - Add any changes you want
- Add tests for the new changes
- Edit documentation if you have changed something significant
- Update
CHANGELOG.md
with a quick summary of your changes - Run
pytest
again to make sure it is still working - Run
flake8
to ensure that style is correct
You can run everything at once with make autotests
,
run make help
for more details.
Notes for maintainers
This section is intended for maintainers only. If you are not a maintainer (or do not know what it means), just skip it. You are not going to miss anything useful.
Making new release
Releases are shipped using git-flow https://danielkummer.github.io/git-flow-cheatsheet/index.html
This command has to be run only once to set up git flow, keep default value for all parameters.
git flow init
-
Update master and develop branches
git checkout develop && git pull git checkout master && git pull
-
Start a new release
git flow release start <VERSION>
<VERSION>
- new release version -
Update CHANGELOG.md
-
Update project version
poetry version <VERSION>
-
Commit project configuration with the new version
git commit -m "bump version" pyproject.toml
-
Finish building a release
git flow release finish <VERSION>
-
Push all the changes into the repository
git push origin master develop --follow-tags
-
Create a new release specifying pushed tag