GithubHelp home page GithubHelp logo

skema-api-mock's Introduction

mock_api

mocks api function returning fake data with specified shape. Every url can have different shape, these are represented in skema format in a yaml file,

/posts/: |
    Response:
        ok: Bool
        data: [
            postName: Str
            date: Str
            id: Int
        ]
/post/: |
    Response:
        ok: Bool
        data:
            author:
                name: Str
                id: Int
            description: Str

The shape of the data can change based on url hostname or path. an example:

from mock_api import mock_function
from myapi import api_call

with mock_function('myapi.api_call', 'api_shape.yml', arg=0):
    data = api_call('/posts/')
    print(data) # {'ok': True, 'data': {'postName': 'sdfsdgx', 'date': 'sdfg4'}}

genrating the api shapes

You can generating the shapes calling many times the api

from mock_api import track_function
from myapi import api_call

with track_function('myapi.api_call', 'api_shape.yaml', ):
    api_call('/posts/')
    api_call('/post/34')
    api_call('/post/14')
    api_call('/data/')

# a file api_shape.yaml is created
assert os.path.exists('api_shape)

todo:

  • change shape based on POST, GET ...
  • change shape based on parameters
  • add url parameters, like posts/:id/
  • remove Response root key maybe (but i can't use root arrays, Root: [...])
  • add possible codes, like 200, 400, then change shape based on them

skema-api-mock's People

Contributors

bump-version avatar remorses avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.