Ejemplo n.º 1
0
    def test_url(self, requests_mock, form):
        url = "http://test/form"

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

        assert resolve_form(url) == form
Ejemplo n.º 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
Ejemplo n.º 3
0
    def test_file(self, monkeypatch, tmpdir, form):
        path = os.path.join(str(tmpdir), "form.txt")
        with open(path, "w") as f:
            json.dump(form, f)

        assert resolve_form("./form.txt", base_dir=str(tmpdir)) == form
Ejemplo n.º 4
0
 def test_list(self, form, items):
     assert resolve_form(items) == form
Ejemplo n.º 5
0
 def test_dict(self, form):
     assert resolve_form(form) == form
Ejemplo n.º 6
0
 def test_type_errors(self, data):
     with pytest.raises(PluginParamError):
         resolve_form(data)