Ejemplo n.º 1
0
def test_api_to_schema_class_not_instance():
    class TestApi(Api):
        class Meta:
            name = "my.test_api"

    with pytest.raises(InvalidApiForSchemaCreation):
        api_to_schema(TestApi)
Ejemplo n.º 2
0
def test_api_to_schema_rpc():
    class TestApi(Api):
        def my_proc(self, field: bool = True) -> str:
            pass

        class Meta:
            name = "my.test_api"

    schema = api_to_schema(TestApi())
    assert schema["rpcs"]["my_proc"] == {
        "parameters": {
            "$schema": "http://json-schema.org/draft-04/schema#",
            "type": "object",
            "additionalProperties": False,
            "properties": {
                "field": {
                    "type": "boolean",
                    "default": True
                }
            },
            "title": "RPC my.test_api.my_proc() parameters",
        },
        "response": {
            "$schema": "http://json-schema.org/draft-04/schema#",
            "title": "RPC my.test_api.my_proc() response",
            "type": "string",
        },
    }
Ejemplo n.º 3
0
def test_api_to_schema_event_private():
    """Properties starting with an underscore should be ignored"""
    class TestApi(Api):
        _my_event = Event(["field"])

        class Meta:
            name = "my.test_api"

    schema = api_to_schema(TestApi())
    assert not schema["events"]
Ejemplo n.º 4
0
def test_api_to_schema_rpc_private():
    """Methods starting with an underscore should be ignored"""
    class TestApi(Api):
        def _my_proc(self, field: bool = True) -> str:
            pass

        class Meta:
            name = "my.test_api"

    schema = api_to_schema(TestApi())
    assert not schema["rpcs"]
Ejemplo n.º 5
0
def test_api_to_schema_event_short_form():
    class TestApi(Api):
        my_event = Event(["field"])

        class Meta:
            name = "my.test_api"

    schema = api_to_schema(TestApi())
    assert schema["events"]["my_event"] == {
        "parameters": {
            "$schema": "http://json-schema.org/draft-04/schema#",
            "type": "object",
            "additionalProperties": False,
            "properties": {
                "field": {}
            },
            "required": ["field"],
            "title": "Event my.test_api.my_event parameters",
        }
    }