Skip to main content

Send push notification from command line for single or multiple targets

Project description

PyMocky

Python package codecov

Mock server to return static response.

Install

python3 -m pip install pymocky

Check with command:

pymocky -h

How to use

pymocky -p extras/sample/

Test with command (need curl):

curl http://localhost:9000/login

To change from default scenario to other use (server need be running):

pymocky --update-scenario "login-error"

Test again with command (need curl):

curl http://localhost:9000/login

Example of YAML file

mappings:
- id: hello_world
   scenario: login-success
   request:
      url: .*pymocky_hello_world.*
      method: post
      query_string: .*param1=value&param2=value2
      form_fields:
      username: .*demo
      password: .*12345
      headers:
         "Content-Type": "application/json"
      body: .*Hello World.*
   response:
      headers:
         "Content-Type": "application/json"
      body_raw: Hello world from pymocky!
      body_file: files/dummy.xml
      body_json:
         success: false
         data:
         errors: []
      body_image: images/image1.png
      body_python: files/dummy.py
      sys_path: ["auto"]

You can use “body_raw”, “body_file”, “body_json”, “body_image” or “body_python” as response type.

When you use “body_python” you can add array “sys_path” and pymocky will add these paths to “sys.path” list. The list of “sys.path” is reloaded to original (when pymocky start is stored a copy of this list) everytime that YAML files are parsed again. When you use “auto” in the array, the path will be the directory of python file to be execute.

body_raw: Raw text as response
body_file: File content with mimetype discovery by extension
body_json: Json as YAML object or string
body_image: Image file with mimetype discovery by extension
body_python: Python file to be executed

Change scenario

To change from default scenario to other use (server need be running):

pymocky --update-scenario "login-error"

Testing

You need install test dependencies with the command:

python3 -m pip install -r requirements_tests.txt

To execute all tests use the command:

python3 -m pytest tests

To coverage test use the command:

python3 -m pytest --cov=. --cov-report=xml --cov-report=html tests

To install locally during development:

python3 setup.py install

or:

python3 -m pip install -e .

Packaging

To package and upload for distribution on PyPi server use:

python3 setup.py upload

Contributing

  • Fork the project and clone locally.

  • Create a new branch for what you’re going to work on.

  • Push to your origin repository.

  • Create a new pull request in GitHub.

Buy me a coffee

Buy Me a Coffee at ko-fi.com

License

MIT

Copyright (c) 2020-2026, Paulo Coutinho

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pymocky-1.3.0.tar.gz (4.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pymocky-1.3.0-py2.py3-none-any.whl (4.5 kB view details)

Uploaded Python 2Python 3

File details

Details for the file pymocky-1.3.0.tar.gz.

File metadata

  • Download URL: pymocky-1.3.0.tar.gz
  • Upload date:
  • Size: 4.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for pymocky-1.3.0.tar.gz
Algorithm Hash digest
SHA256 031412539d315df1b472e3c08cebf0ba683f73cdd25523235ff564b857e3fed4
MD5 f461837006d0121ba4d0cbf72c74e22e
BLAKE2b-256 7f816a1973d0d846e3e8308bc1e16c86349b4b94af7c2ec7b455ec0612a240b0

See more details on using hashes here.

File details

Details for the file pymocky-1.3.0-py2.py3-none-any.whl.

File metadata

  • Download URL: pymocky-1.3.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 4.5 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for pymocky-1.3.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 b49827facbca14bdefc8790cdc9021a15274b92925238c9fca77a13fde6fe371
MD5 443d60a676a81f276b0d61cda7663de9
BLAKE2b-256 805fda57ba7cd62a6c8cf1d33f41d3d73058b487ecc61384d82f0d06c25ddd5a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page