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 hashes)

Uploaded source

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page