def invalid_argument_error_message(context, argument): """Check the error message.""" if "context" in argument or "project" in argument: message = f"argument <context|project>: {argument} name missing" else: message = "argument -d/--due: invalid date: " assert_in(f"next-action: error: {message}", context.next_action())
def multipart_post_request_with_empty_file(self) -> None: self.env["REQUEST_METHOD"] = "POST" self.setup_multipart_request("my-file", "test") args = parse_args(self.env, [("my-file", "file-or-str", Multiplicity.REQUIRED)]) assert_in("my-file", args) assert_equal("test", args["my-file"])
def wrong_method_escape_method(self) -> None: self.router.add_routes([("foo", "GET", fail_if_called)]) response = self.handle_wsgi("G<T", "/foo") html = b"".join(response).decode("utf-8") assert_in( "<p>Method 'G<T' not allowed. Please try GET.</p>", html, )
def read_value_as_file_with_umlauts(self) -> None: self.env["REQUEST_METHOD"] = "GET" self.add_path_argument("foo", "bär") args = parse_args(self.env, [("foo", "file", Multiplicity.REQUIRED)]) assert_in("foo", args) f = args["foo"] assert_equal("", f.filename) assert_equal("application/octet-stream", f.content_type) assert_equal("bär".encode("utf-8"), f.read())
def multipart_post_request_with_file_and_umlauts(self) -> None: self.env["REQUEST_METHOD"] = "POST" self.setup_multipart_file_request("föo", "my-filé.txt", "cöntent", "text/plain; charset=utf-8") args = parse_args(self.env, [("föo", "file", Multiplicity.REQUIRED)]) assert_in("föo", args) f = args["föo"] assert_equal("my-filé.txt", f.filename) assert_equal("text/plain", f.content_type) assert_equal("cöntent".encode("utf-8"), f.read())
def multipart_put_request_with_file(self) -> None: self.env["REQUEST_METHOD"] = "PUT" self.setup_multipart_file_request("my-file", "my-file.txt", "content", "text/plain") args = parse_args(self.env, [("my-file", "file", Multiplicity.REQUIRED)]) assert_in("my-file", args) f = args["my-file"] assert_equal("my-file.txt", f.filename) assert_equal("text/plain", f.content_type) assert_equal(b"content", f.read())
def assertIn(content, res): try: asserts.assert_in(content, res) except Exception as e: logger.error(e)
def invalid_config_file_error(context): """Check that Nect-action gives the correct error message.""" assert_in(f"next-action: error: {context.config_file.name} is invalid:", context.next_action())
def parse_config_file_error(context): """Check that Nect-action gives the correct error message.""" assert_in(f"next-action: error: can't parse {context.config_file.name}:", context.next_action())
def show_next_action_with_min_prio(context): """Check that the next actions have the minimum priority.""" for line in context.next_action().strip().split("\n"): assert_in("(A)", line)
def show_named_next_action(context, action): """Check that the named next action is shown.""" assert_in(action, context.next_action())
def show_blocked_task(context, task): """Check that the task is shown as blocked task.""" assert_in(task, context.next_action())
def encode_url(self) -> None: page = temporary_redirect_page('/foo/"bar"') assert_in('<a href="/foo/"bar"">/foo/"bar"</a>', page)
def unreadable_file_error_message(context): """Check the error message.""" assert_in("next-action: error: can't open file: ", context.next_action())
def c_or_p_in_and_ex_error_message(context, context_or_project): """Check the error message.""" argument_type = "@" if "context" in context_or_project else "+" assert_in( f"next-action: error: {argument_type}name is both included and excluded", context.next_action())
def show_next_action_due_tomorrow(context): """Check that the next action is due tomorrow.""" assert_in(tomorrow(), context.next_action())
def show_next_actions_grouped_by(context, groupby): """Show all next actions grouped by context, project, ...""" expected_header = context.files[-1].name if groupby == "source" \ else f"No {groupby.replace('due date', 'due date')}" assert_in(f"{expected_header}:\n- Task\n", context.next_action())
def invalid_priority_error_message(context): """Check the error message.""" assert_in("next-action: error: argument -p/--priority: invalid choice:", context.next_action())
def invalid_number_error_message(context): """Check the error message.""" assert_in("next-action: error: argument -n/--number: invalid number:", context.next_action())
def html(self) -> None: request = Request(self.environment) response = see_other(request, self.start_response, "foo/bar") html = b"".join(response).decode("utf-8") assert html.startswith("<!DOCTYPE html>") assert_in("http://www.example.com/foo/bar", html)
def encode_url(self) -> None: page = created_at_page('/foo/"bar"') assert_in('<a href="/foo/"bar"">/foo/"bar"</a>', page)
def check_config_argument(context, argument, value): """Check that Next-action includes the argument in the configuration file.""" assert_in(argument + ": " + value, context.next_action())
def encode_url(self) -> None: page = see_other_page('/foo/"bar"') assert_in('<a href="/foo/"bar"">/foo/"bar"</a>', page)
def check_reference(context): """Check the filename reference.""" assert_in("/", context.next_action())
def not_found_escape_path(self) -> None: response = self.handle_wsgi("GET", "/foo/<bar") html = b"".join(response).decode("utf-8") assert_in("<p>Path '/foo/<bar' not found.</p>", html)
def non_existing_config_file_error(context): """Check that Nect-action gives the correct error message.""" assert_in("next-action: error: can't open file:", context.next_action())
def check_config_option(context, option): """Check that Next-action includes the option in the configuration file.""" assert_in(option.replace("-", "_") + ": true", context.next_action())
def show_next_action_over_due(context): """Check that the next action was due yesterday.""" assert_in(yesterday(), context.next_action())
def check_config_filter(context, filter_type): """Check that Next-action includes the filter in the configuration file.""" filter_option = "'@home'" if filter_type == "context" else "+Project" assert_in("filters:\n- " + filter_option, context.next_action())
def check_line_number(context): """Check the line number reference.""" assert_in("1]", context.next_action())