Giter Site home page Giter Site logo

hiredscorelabs / cornell Goto Github PK

View Code? Open in Web Editor NEW
141.0 141.0 10.0 3.4 MB

Cornell - record & replay mock server

Home Page: https://hiredscorelabs.github.io/cornell/

License: MIT License

Makefile 1.61% Python 98.20% Dockerfile 0.19%
mock python testing

cornell's People

Contributors

avnercohen avatar davidmeu avatar fabienarcellier avatar lcshiung avatar nchazin avatar yael-malwa avatar yaelmi3 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cornell's Issues

Keep the Content-type when the query is not a redirection

The header Content-Type is dropped when it's not a redirection. It seems tobe the opposite behavior of the commented out issue. I suppose on this one it's an error of code.

As there is no content-type, Postman is reading it as full text.

image

instead of

image

On the code, it check if resp.status_code is not a Temporary Redirect and Permanent Redirect. I think the condition would be to check if resp.status_code is a Temporary Redirect.

def _processes_headers(resp):
    if resp.status_code not in (HTTPStatus.TEMPORARY_REDIRECT, HTTPStatus.PERMANENT_REDIRECT):
        # https://github.com/psf/requests/issues/3490
        for header in ('Content-Length', 'Content-Type', 'Transfer-Encoding'):
            resp.headers.pop(header, None)

Index.yaml file is empty when cornell is stopped by SIGTERM

I run cornell as a background process in automatic testing to record the context of some test. In that case, the file index.yaml is not dumped properly at the end of the process and is empty. It makes replay not usable without removing the index files. (I am not sure of its real usage)

@contextmanager
def record_cassette(api: str, cassette_path: str, port=9000):
    cornell = local['cornell']
    log = os.path.join(cassette_path, 'cassette.log')
    if os.path.isfile(log):
        os.remove(log)

    with io.open(log, 'a') as fp:
        run = (cornell['-ff', api, '--record', '-fp', '-cd', cassette_path, '-p', port] & BG(stdout=fp, stderr=fp))
        try:
            time.sleep(2)
            yield f'http://localhost:{port}'

        finally:
            run.proc.terminate()

I will open a PR to fix this issue

app.logger.info("Starting Cornell", app_name=app.name, port=port, record=record, record_once=record_once,
                    fixed_path=fixed_path, forward_uri=forward_uri, cassettes_dir=str(cassettes_dir))
atexit.register(on_cornell_exit, app=app)
signal.signal(signal.SIGTERM, lambda: on_cornell_exit(app))
app.run(port=port, threaded=False)

build a docker image for cornell

In our development, we got stuck using cornell because one of our libraries didn't support Flask 2.0.0.

One solution would be to run cornell on an independent execution space. A docker image on dockerhub would solve this problem. I am preparing a PR to package a Dockerfile at the root of the repo.

I publish a repository in my own namespace. I have configured a rebuild every 24 hours. I will remove it as soon as you publish your own dockerhub repository.

docker run hiredscorelabs/cornell

I can't record and replay a route that use the method DELETE

Hello,

I am trying to record the result of an API call that requires DELETE method. The script get a 405 error (method not allowed)
Have you blocked this behavior on purpose ? Can I propose a PR to add the support of this method ?

In cornell/cornell_server.py :

SUPPORTED_METHODS = ['GET', 'POST', 'PUT']

TypeError: get_custom_vcr() got multiple values for argument 'base_uri'

Hello,
it seems that running this example in the docs throws a TypeError: get_custom_vcr() got multiple values for argument 'base_uri

The problematic code is directly from the doc:

#!/usr/bin/env python

import click
import json
from vcr.util import read_body
from cornell.cornell_server import CornellCmdOptions, start_cornell
from cornell.cornell_helpers import json_in_headers
from cornell.custom_matchers import requests_match_conditions


# Custom Matcher
@requests_match_conditions(json_in_headers, lambda request: request.body)
def vcr_json_custom_body_matcher(received_request, cassette_request):
    received_request_dict = json.loads(read_body(received_request))
    cassette_request_dict = json.loads(read_body(cassette_request))
    if received_request_dict == cassette_request_dict or "special_params" not in received_request_dict:
        return True
    return is_specially_matched(received_request_dict, cassette_request_dict)


@click.command(cls=CornellCmdOptions)
def start_mock_service(**kwargs):
    start_cornell(additional_vcr_matchers=[vcr_json_custom_body_matcher], **kwargs)


if __name__ == "__main__":
    start_mock_service()

Dockerfile to reproduce:

FROM python:3.9-alpine

RUN pip install cornell
COPY cornell/main.py .
EXPOSE 9000

ENTRYPOINT ["python", "main.py"]

It seems that changing the line 189 in cornell_server.py to app.config.vcr = get_custom_vcr(app.config.base_uri, DUMMY_URL, record_errors, *additional_vcr_matchers) fixes this, but it seems hacky. Overall I haven't been able to make the custom matchers work, anybody has a working example ? I'm looking to have a sidecar container that will record every request with same data parameters to an API, this seems like something cornell should do

Support for --host argument to replace default listening IP address of 127.0.0.1

Use Case

Some developers may be running their IDE from a different computer and remotely connecting to Cornell. Rather than defaulting to listening on 127.0.0.1, is it possible to support a --host argument, e.g.

--host=0.0.0.0

This will result in replacing the Flask running code:

app.run(port=port, threaded=False)

with:

app.run(host=0.0.0.0, port=port, threaded=False)

Happy to create a PR if you are agreeable.

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.