def test_gettable_resource(self, app):
        falcon_plugin = FalconPlugin(app)

        class HelloResource:
            def on_get(self, req, resp):
                """A greeting endpoint.
                ---
                description: get a greeting
                summary: greeting
                responses:
                    200:
                        description: said hi
                """
                return "dummy"

        expected = {
            "summary": "greeting",
            "description": "get a greeting",
            "responses": {
                "200": {
                    "description": "said hi"
                }
            },
        }
        hello_resource = HelloResource()
        app.add_route("/hi", hello_resource)
        spec = build_spec(falcon_plugin)
        falcon_plugin.auto_build_spec(spec)

        assert spec._paths["/hi"]["get"] == expected
    def test_posttable_resource(self, app):
        falcon_plugin = FalconPlugin(app)

        class HelloResource:
            def on_post(self, req, resp):
                """A greeting endpoint.
                ---
                description: get a greeting
                responses:
                    201:
                        description: posted something
                """
                return "hi"

        expected = {
            "description": "get a greeting",
            "responses": {
                "201": {
                    "description": "posted something"
                }
            },
        }
        hello_resource = HelloResource()
        app.add_route("/hi", hello_resource)
        spec = build_spec(falcon_plugin)
        falcon_plugin.auto_build_spec(spec)

        assert spec._paths["/hi"]["post"] == expected
    def test_path_with_suffix(self, app):
        falcon_plugin = FalconPlugin(app)

        class HelloResource:
            def on_get_hello(self):
                """A greeting endpoint.
                ---
                description: get a greeting
                responses:
                    200:
                        description: said hi
                """
                return "dummy"

            def on_get(self):
                """An invalid method.
                ---
                description: this should not pass
                responses:
                    200:
                        description: said hi
                """
                return "invalid"

            def on_post(self):
                """Some post method to save stuff
                ---
                summary: it does save stuff
                description: this is saving stuff somewhere
                responses:
                    200:
                        description: Everything went well
                """
                return "Ok, the stuff is being saved"

        expected = {
            "description": "get a greeting",
            "responses": {
                "200": {
                    "description": "said hi"
                }
            },
        }

        hello_resource_with_suffix = HelloResource()
        app.add_route("/hi", hello_resource_with_suffix, suffix="hello")
        app.add_route("/something", hello_resource_with_suffix)

        spec = build_spec(falcon_plugin)
        falcon_plugin.auto_build_spec(spec)

        assert spec._paths["/hi"]["get"] == expected
        print(" ")
        print(spec.to_yaml())
    def test_path_with_suffix_multiple_route(self, app):
        falcon_plugin = FalconPlugin(app)

        class HelloResource:
            def on_get_hello(self):
                """A greeting endpoint.
                ---
                description: get a greeting
                responses:
                    200:
                        description: said hi
                """
                return "dummy"

            def on_get(self):
                """An invalid method.
                ---
                description: this should not pass
                responses:
                    200:
                        description: said hi
                """
                return "invalid"

        expected_hello = {
            "description": "get a greeting",
            "responses": {
                "200": {
                    "description": "said hi"
                }
            },
        }

        expected = {
            "description": "this should not pass",
            "responses": {
                "200": {
                    "description": "said hi"
                }
            },
        }

        hello_resource_with_suffix = HelloResource()
        app.add_route("/", hello_resource_with_suffix)
        app.add_route("/hello", hello_resource_with_suffix, suffix="hello")

        spec = build_spec(falcon_plugin)
        falcon_plugin.auto_build_spec(spec)

        assert spec._paths["/"]["get"] == expected
        assert spec._paths["/hello"]["get"] == expected_hello
    def test_resource_with_metadata(self, app):
        falcon_plugin = FalconPlugin(app)

        class HelloResource:
            """Greeting API.
            ---
            x-extension: global metadata
            """

        hello_resource = HelloResource()
        app.add_route("/hi", hello_resource)
        spec = build_spec(falcon_plugin)
        falcon_plugin.auto_build_spec(spec)

        assert spec._paths["/hi"]["x-extension"] == "global metadata"
Пример #6
0
def create_app(config_filename=None):
    if config_filename is None:
        conf = default_config.copy()
    else:
        conf = read_conf(config_filename)
    app = falcon.API()
    rethink_factory = RethinkDBFactory(**conf["rethinkdb"])

    user_resource = Users(rethink_factory)
    card_resource = Cards(rethink_factory)

    app.add_route("/users", user_resource)
    app.add_route("/cards", card_resource)

    # Create an APISpec
    spec = APISpec(
        title='Swagger Prelaunch Spec',
        version='1.0.0',
        openapi_version='2.0',
        plugins=[
            FalconPlugin(app),
            MarshmallowPlugin(),
        ],
    )

    # Register entities and paths
    spec.components.schema('User', schema=User.schema())
    spec.components.schema('Card', schema=Card.schema())

    spec.path(resource=user_resource)
    spec.path(resource=card_resource)

    return app, spec
Пример #7
0
def create_app(db):
    """

    Args:
        db:

    Returns:

    """
    app = falcon.API(middleware=[AuthMiddleware()])

    # Set up documentation object
    spec = APISpec(
        title="Kestrel",
        version="1.0.0",
        openapi_version="3.0.2",
        plugins=[FalconPlugin(app), MarshmallowPlugin()],
    )
    spec.components.security_scheme("BearerAuth", {
        "type": "http",
        "scheme": "bearer"
    })

    # Build routes
    build_routes(db, app, spec)

    return app
Пример #8
0
def create_spec(app):
    spec = APISpec(
        title='Submit my Planning Application',
        version='1.0.0',
        openapi_version='3.0',
        plugins=[FalconPlugin(app), SchematicsPlugin()],
    )

    return spec
Пример #9
0
def spec(app):
    # Set up documentation object
    spec = APISpec(
        title="Test",
        version="1.0.0",
        openapi_version="3.0.2",
        plugins=[FalconPlugin(app), MarshmallowPlugin()],
    )
    return spec
Пример #10
0
 def _spec(app):
     return APISpec(
         title='Swagger Petstore',
         version='1.0.0',
         description=
         'This is a sample Petstore server.  You can find out more '
         'about Swagger at <a href=\"http://swagger.wordnik.com\">http://swagger.wordnik.com</a> '
         'or on irc.freenode.net, #swagger.  For this sample, you can use the api '
         'key \"special-key\" to test the authorization filters',
         plugins=[FalconPlugin(app)],
     )
Пример #11
0
 def _spec(app):
     return APISpec(
         title="Swagger Petstore",
         version="1.0.0",
         description=
         "This is a sample Petstore server.  You can find out more "
         'about Swagger at <a href="http://swagger.wordnik.com">http://swagger.wordnik.com</a> '
         "or on irc.freenode.net, #swagger.  For this sample, you can use the api "
         'key "special-key" to test the authorization filters',
         plugins=[FalconPlugin(app)],
     )
Пример #12
0
 def _spec(app):
     return APISpec(
         title="Swagger Petstore",
         version="1.0.0",
         openapi_version="3.0.2",
         description="This is a sample Petstore server.  You can find out "
         'more about Swagger at <a href="https://swagger.io"> '
         "http://swagger.wordnik.com</a> or on irc.freenode.net, #swagger."
         'For this sample, you can use the api key "special-key" to test '
         "the authorization filters",
         plugins=[FalconPlugin(app)],
     )
    def test_resource_without_endpoint(self, app):
        falcon_plugin = FalconPlugin(app)

        class HelloResource:
            def on_get(self, req, resp):
                """A greeting endpoint.
                ---
                description: get a greeting
                responses:
                    200:
                        description: said hi
                """
                return "dummy"

        hello_resource = HelloResource()
        spec = build_spec(falcon_plugin)
        falcon_plugin.auto_build_spec(spec)

        with pytest.raises(APISpecError):
            spec.path("/hi")

        with pytest.raises(APISpecError):
            spec.path("")
Пример #14
0
    def __init__(self):
        from graphx.configurations.app.settings import Props
        from graphx.configurations.app.main import app
        from graphx.configurations.app.main import container
        # todo: should be moved to env vars
        self.spec = APISpec(title='graphx',
                            version='1.0.0',
                            openapi_version='2.0',
                            plugins=[
                                FalconPlugin(app),
                                MarshmallowPlugin(),
                            ])
        injector = container.get(Props.DI_PROVIDER).get_injector()

        self.spec.components.schema('Node', schema=injector.get(Node))
        self.spec.path(resource=injector.get(NodeCollection))

        self.spec.components.schema('Edge', schema=injector.get(Edge))
        self.spec.path(resource=injector.get(EdgeCollection))
Пример #15
0
    def __init__(self):
        from meerkat.configurations.app.settings import Props
        from meerkat.configurations.app.main import app
        from meerkat.configurations.app.main import container
        # todo: should be moved to env vars
        self.spec = APISpec(title='meerkat',
                            version='1.0.0',
                            openapi_version='2.0',
                            plugins=[
                                FalconPlugin(app),
                                MarshmallowPlugin(),
                            ])
        injector = container.get(Props.DI_PROVIDER).get_injector()

        self.spec.components.schema('Health',
                                    schema=injector.get(HealthSchema))
        self.spec.path(resource=injector.get(HealthCheck))

        self.spec.components.schema('Post', schema=injector.get(PostSchema))

        self.spec.path(resource=injector.get(PostCollection))
        self.spec.path(resource=injector.get(Post))
Пример #16
0
    salles_api = fh_salles()
    api.add_route("/{!s}/connect".format(API_VERSION), connect_api)
    api.add_route("/{!s}/hospitals".format(API_VERSION), hospital_api)
    api.add_route("/{!s}/salles".format(API_VERSION), salles_api)
    api.add_sink(handle_404, '')

    # Ajout du swagger de l'API
    api.add_static_route(SWAGGERUI_URL, str(STATIC_PATH))
except Exception as e:
    rootLogger.error(str(e))
    sys.exit(1)

spec = APISpec(
    title='Swagger FH_assistant',
    version='1.0.0',
    openapi_version='2.0',
    plugins=[FalconPlugin(api), MarshmallowPlugin()],
)

spec.components.schema('Response', schema=ResponseSchema)
spec.path(resource=connect_api)
spec.path(resource=hospital_api)
spec.path(resource=salles_api)
f = codecs.open(str(STATIC_PATH) + "/v1/swagger.yaml", "w", "utf-8")
f.write(spec.to_yaml())
f.close()

if __name__ == '__main__':
    httpd = simple_server.make_server('127.0.0.1', 8100, api)
    httpd.serve_forever()
Пример #17
0
        description = ('wrong password')
        raise falcon.HTTPUnauthorized('Authentication required',description)
    params['usuario']=str(user,'utf-8')


cors = CORS(allow_all_origins=True)

app=falcon.API(middleware=[PeeweeConnectionMW(),cors.middleware])
    #consider also falcon_cors.CORS with allow_credentials_all_origins etc
spec = APISpec(
    title='API Anonimizada',
    version='0.9.1',
    openapi_version='3.0.0',  #2.0 usa consumes, 3.0 usa requestBody pero no sake muy bien en falcon_swagger_ui
    info=dict(description="Modelo de API para datos anonimizados espacial y temporalmente"),
    plugins=[
        FalconPlugin(app),
    ],
)
spec.components.security_scheme("claveSimple",{"type": "http", "scheme": "basic"})
spec.tag({"name":"admin","description":"necesitan privilegios"})
spec.tag({"name":"csv","description":"fichero en CSV"})
spec.tag({"name":"open","description":"no necesita auth"}) 

### batch tasks, should be suitable for parallelism

def makeBatch(data,t,salt):
    datalot=[]
    conflictset=set()
    idsKeyDict=t.idsKeys
    for linetime,lineid,line in data:
        #print(line,idsKeyDict)