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
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
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
def test_list(self, form, items): assert resolve_form(items) == form
def test_dict(self, form): assert resolve_form(form) == form
def test_type_errors(self, data): with pytest.raises(PluginParamError): resolve_form(data)