def setUp(self): os.environ[CONFIGMAP_FILE_ENVIRONMENT] = os.path.join( self.BASE_DIR, "config-tests.yml") ms = Microservice(service="my-ms", path=__file__) self.app = ms.create_app() with self.app.app_context(): self.request = ms.requests
def setUp(self): os.environ[CONFIGMAP_FILE_ENVIRONMENT] = os.path.join( self.BASE_DIR, "config-tests-requests.yml") ms = Microservice(path=__file__) ms.reload_conf() self.app = ms.create_app() self.request = ms.requests
def __init__(self): """ Initialize the flask endpoint and launch the function that will throw the threads that will update the metrics. """ self.lock = {} self.app = Microservice().create_app() self.logger = self.app.logger self.read_config() self.serve_endpoints()
def create_app(): """Initialize the Flask app, register blueprints and intialize all libraries like Swagger, database, the trace system... return the app and the database objects. :return: """ {% if cookiecutter.create_model_class == 'y' -%} ms = MyMicroservice(service="ms", path=__file__) {% else %} ms = Microservice(service="ms", path=__file__) {% endif %} return ms.create_app()
from flask import jsonify from pyms.flask.app import Microservice ms = Microservice(path=__file__) app = ms.create_app() @app.route("/") def example(): return jsonify({"main": "hello world"}) if __name__ == '__main__': app.run()
from flask import current_app, jsonify, request from pyms.flask.app import Microservice ms = Microservice() app = ms.create_app() @app.route("/") def index(): app.logger.info("There are my headers: \n{}".format(request.headers)) return jsonify( {"main": "hello world {}".format(current_app.config["APP_NAME"])}) if __name__ == "__main__": app.run()
from pyms.flask.app import Microservice ms = Microservice(service="my-ms", path=__file__) app = ms.create_app() if __name__ == '__main__': app.run()
def setUp(self): os.environ[CONFIGMAP_FILE_ENVIRONMENT] = os.path.join( self.BASE_DIR, "config-tests-metrics.yml") ms = Microservice(service="my-ms", path=__file__) self.app = ms.create_app() self.client = self.app.test_client()
from flask import jsonify from pyms.flask.app import Microservice ms = Microservice(service="my-minimal-microservice", path=__file__) app = ms.create_app() @app.route("/") def example(): return jsonify({"main": "hello world"}) if __name__ == '__main__': app.run()
def test_singleton_inherit_conf(self): ms1 = Microservice(path=__file__) ms2 = MyMicroservice() self.assertEqual(ms1.config.subservice1, ms2.config.subservice1)
def test_singleton_child_class(self): ms1 = Microservice(path=__file__) ms2 = MyMicroservice() self.assertNotEqual(ms1, ms2)
def test_singleton(self): ms1 = Microservice(path=__file__) ms2 = Microservice(path=__file__) self.assertEqual(ms1, ms2)
def setUp(self): os.environ[CONFIGMAP_FILE_ENVIRONMENT] = os.path.join(self.BASE_DIR, "config-tests-service-discovery.yml") ms = Microservice(path=__file__) ms.reload_conf() self.ms = ms
def setUp(self): os.environ[CONFIGMAP_FILE_ENVIRONMENT] = os.path.join( os.path.dirname(os.path.abspath(__file__)), "config-tests.yml") ms = Microservice(service="my-ms", path=__file__) self.app = ms.create_app() self.client = self.app.test_client()