hiredscorelabs / cornell Goto Github PK
View Code? Open in Web Editor NEWCornell - record & replay mock server
Home Page: https://hiredscorelabs.github.io/cornell/
License: MIT License
Cornell - record & replay mock server
Home Page: https://hiredscorelabs.github.io/cornell/
License: MIT License
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.
instead of
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)
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)
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
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']
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
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.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.