Skip to main content

A library in python for simulated API server

Project description

Python Package GitHub contributors PyPI - Downloads PyPI - Downloads PyPI version fury.io PyPI pyversions GitHub tag PyPI - Format PyPI - Implementation Libraries.io dependency status for GitHub repo

kitty Mock Lib Python

A Python library for simulate an API with http and websocket request. In this 0.1.1.4 version of kitty-Mock-Lib-Python, allows you to simulate an API, being able to create routes in your own way, getting the history, details of it and other things you can do.

Installation

The latest stable version is available on PyPI. Either add kittymocklib_py to your requirements.txt file or install with pip:

pip install kittymocklib-py

Description

This project aims to help other types of projects that need a python API simulation and with this lib, you can simulate both http and websocket.

Starting

To run the project, you will need to install the following programs:

Steps

Step 0:

In this lib we use a docker image from kitty Mock, so for you to use it you will have to create a docker-compose.yml file in order to take advantage of this lib:

version: "3"
services:
  kittymock1:
    image: ntopus/kitty-mock:0.4.5
    ports:
      - "6999:6999"
      - "7000-7020:7000-7020"
    environment:
      SERVER_PORT: 6999
      MOCKER_PORTS_RANGE: 7000-7020

In order to run the docker, first you have to build and then upload the container.

docker-compose build 

Later:

docker-compose up

Or can run this way:

docker-compose up --build
          or
docker-compose up --build -d

examples of how to use:

How to use

First steps

Http route
  • Create the mocker

    from kittymocklib_py.mocker import Mocker
    
    def create_mocker():
        mocker = Mocker("http://localhost", 6999)
        print(f'My port: {mocker.mocker_port}')
    
  • Create http mock route

    from kittymocklib_py.mocker import Mocker
    
    def create_http_mock_route():
        mocker = Mocker("http://localhost", 6999)
        route = mocker.create_http_route("/hello", "GET", 200, "hello my friend")
    
  • Request http mock route

    from kittymocklib_py.mocker import Mocker
    
    def create_http_mock_route():
        mocker = Mocker("http://localhost", 6999)
        route = mocker.create_http_route("/hello", "GET", 200, "hello my friend")
        route_response = route.request()
    
  • Delete mocker server

    from kittymocklib_py.mocker import Mocker
    
    def create_http_mock_route():
        mocker = Mocker("http://localhost", 6999)
        response = mocker.delete()
    
  • Delete http mock route

    from kittymocklib_py.mocker import Mocker
    
    def create_http_mock_route():
        mocker = Mocker("http://localhost", 6999)
        route = mocker.create_http_route("/hello", "GET", 200, "hello my friend")
        route_response = route.delete()
    
  • Get history http mock route

    from kittymocklib_py.mocker import Mocker
    
    def create_http_mock_route():
        mocker = Mocker("http://localhost", 6999)
        route = mocker.create_http_route("/hello", "GET", 200, "hello my friend")
        route_response = route.get_history()
    
  • Clear history http mock route

    from kittymocklib_py.mocker import Mocker
    
    def create_http_mock_route():
        mocker = Mocker("http://localhost", 6999)
        route = mocker.create_http_route("/hello", "GET", 200, "hello my friend")
        route_response = route.clear_history()
    
  • Details http mock route

    from kittymocklib_py.mocker import Mocker
    
    def create_http_mock_route():
        mocker = Mocker("http://localhost", 6999)
        route = mocker.create_http_route("/hello", "GET", 200, "hello my friend")
        route_response = route.details()
    
WebSocket

Unavailable in this version

Test

In this lib, functional tests were used, with it we can run it like this:

python -m unittest discover tests -v

Additional

In this lib we use loggings, to be able to know everything that is going on behind the scenes, as well as to know if there was any error or bug somewhere in the code, it will demonstrate for you

Configuration

To execute the project, it is necessary to use VsCode or an IDE of your preference, so that it identifies the dependencies necessary for execution in the repository. Once the project is imported, it will be possible to test its functionality in real time.

Contributions

Contributions are always welcome! I hope I have helped someone in need.

🔓 License

MIT © Evandro Silva

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

kittymocklib_py-0.1.1.4.tar.gz (3.5 kB view details)

Uploaded Source

File details

Details for the file kittymocklib_py-0.1.1.4.tar.gz.

File metadata

  • Download URL: kittymocklib_py-0.1.1.4.tar.gz
  • Upload date:
  • Size: 3.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.9.6

File hashes

Hashes for kittymocklib_py-0.1.1.4.tar.gz
Algorithm Hash digest
SHA256 3c9a230ba2ff8c8569221d01bf53d7701f8f7a89df436bf56fc00110f6c7f262
MD5 6a89ed878428a5c9868a8636f9863990
BLAKE2b-256 9a37a836a89f13e45ee9d4fd70166edd491b9f71260d2a8bc67180ba930df418

See more details on using hashes here.

Supported by

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