Parrot

Web-service for testing http requests and webhooks.

Project info: Docker Image Version (tag latest semver) Python Version License

Build: autotests build

Code quality: codecov Language grade: Python Maintainability Rating Reliability Rating Security Rating




Links:

  1. Repository: https://github.com/Uma-Tech/parrot
  2. Documentation: https://uma-tech.github.io/parrot/
  3. Docker Hub: https://registry.hub.docker.com/r/umahighload/parrot-app
  4. Issue tracker: https://github.com/Uma-Tech/parrot/issues
  5. Changelog: https://github.com/Uma-Tech/parrot/blob/develop/CHANGELOG.md

Components

  1. Database postgres.
  2. Database redis (for background celery-tasks).
  3. 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

  1. System requires
  2. Local run

System requirements

Local run

Quickstart (with Docker)

  1. Clone the repo

    git clone git@github.com:Uma-Tech/parrot.git
    cd parrot
    
  2. Build or download the docker image
    for build

    make build
    

    for download

    docker pull umahighload/parrot-app:latest
    
  3. 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
    
  4. Start the app and its dependencies

    make runserver
    
  5. You will be able to access the service at http://127.0.0.1:8042/

Start the project for development without Docker

  1. Clone the repo and go to the project directory

    git clone git@github.com:Uma-Tech/parrot.git
    cd parrot
    
  2. Install dependencies

    poetry install
    
  3. 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
    
  4. 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

  5. Build static

    poetry run python manage.py collectstatic --no-input
    
  6. Apply database migrations

    poetry run python manage.py migrate
    
  7. Create a django superuser

    poetry run python manage.py createsuperuser
    
  8. Start the django app

    poetry run python manage.py runserver
    
  9. Start the celery worker
    Run in a separate terminal window

    poetry run celery -A parrot worker -l INFO -c 4
    

Usage

  1. First steps
  2. Request scripts

First steps

Create an http-stub

  1. Go to HTTP Stubs -> Stubs
  2. Click the Add button
  3. Fill in the required fields
  4. Click the Save button

Logs

  1. Send a http-request to the created http-stub
  2. Go to HTTP Stubs -> Logs
  3. Watch incoming requests :)

Use request scripts

For using it

  1. Create an http stub (first steps)
  2. 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

  • Fix lgtm alert #90
  • Improves deploy #85
  • Display headers in column #46
  • Formatting request body #52

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

  • Adds documentation #34
  • Updates lots of dependencies (issues)

0.1.1

This is the first public version of the project. Happy Birthday Parrot!

How to contribute

First steps

  1. Fork our repo, here's the guide on forking
  2. Clone your new repo (forked repo) to have a local copy of the code
  3. Apply the required changes!
  4. 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:

  1. Run pytest to make sure everything was working before
  2. Add any changes you want
  3. Add tests for the new changes
  4. Edit documentation if you have changed something significant
  5. Update CHANGELOG.md with a quick summary of your changes
  6. Run pytest again to make sure it is still working
  7. 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
  1. Update master and develop branches

    git checkout develop && git pull
    git checkout master && git pull
    
  2. Start a new release

    git flow release start <VERSION>
    

    <VERSION> - new release version

  3. Update CHANGELOG.md

  4. Update project version

    poetry version <VERSION>
    
  5. Commit project configuration with the new version

    git commit -m "bump version" pyproject.toml
    
  6. Finish building a release

    git flow release finish <VERSION>
    
  7. Push all the changes into the repository

    git push origin master develop --follow-tags
    
  8. Create a new release specifying pushed tag

Contributors