Exemple #1
0
    def test_url(self, requests_mock, schema):
        url = "http://test/schema"

        requests_mock.get(
            url,
            json=schema,
            headers={"content-type": "application/json; charset=utf-8"},
        )

        assert resolve_schema(url) == schema
Exemple #2
0
def _initialize_command(method):
    # type: (MethodType) -> Command
    """Initialize a Command

    This takes care of ensuring a Command object is in the correct form. Things like:

    - Assigning the name from the method name
    - Pulling the description from the method docstring, if necessary
    - Resolving display modifiers (schema, form, template)

    Args:
        method: The method with the Command to initialize

    Returns:
        The initialized Command

    """
    cmd = getattr(method, "_command", Command())

    cmd.name = _method_name(method)
    cmd.description = cmd.description or _method_docstring(method)

    try:
        base_dir = os.path.dirname(inspect.getfile(method))

        cmd.schema = resolve_schema(cmd.schema, base_dir=base_dir)
        cmd.form = resolve_form(cmd.form, base_dir=base_dir)
        cmd.template = resolve_template(cmd.template, base_dir=base_dir)
    except PluginParamError as ex:
        six.raise_from(
            PluginParamError("Error initializing command '%s': %s" %
                             (cmd.name, ex)),
            ex,
        )

    return cmd
Exemple #3
0
 def test_type_errors(self, data):
     with pytest.raises(PluginParamError):
         resolve_schema(data)
Exemple #4
0
    def test_file(self, monkeypatch, tmpdir, schema):
        path = os.path.join(str(tmpdir), "schema.txt")
        with open(path, "w") as f:
            json.dump(schema, f)

        assert resolve_schema("./schema.txt", base_dir=str(tmpdir)) == schema
Exemple #5
0
 def test_dict(self, schema):
     assert resolve_schema(schema) == schema