How to use WsgiDAV - 10 common examples

To help you get started, we’ve selected a few WsgiDAV examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mar10 / wsgidav / tests / test_wsgidav_app.py View on Github external
def unicode_to_url(s):
            # TODO: Py3: Is this the correct way?
            return compat.quote(s.encode("utf8"))
github mar10 / wsgidav / tests / test_util.py View on Github external
def testCliLogging(self):
        """CLI initializes logging."""
        config = {"verbose": 3, "enable_loggers": ["test"]}
        init_logging(config)

        _baseLogger = logging.getLogger(BASE_LOGGER_NAME)
        _enabledLogger = get_module_logger("test")
        _disabledLogger = get_module_logger("test2")

        _baseLogger.debug("_baseLogger.debug")
        _baseLogger.info("_baseLogger.info")
        _baseLogger.warning("_baseLogger.warning")
        _baseLogger.error("_baseLogger.error")

        _enabledLogger.debug("_enabledLogger.debug")
        _enabledLogger.info("_enabledLogger.info")
        _enabledLogger.warning("_enabledLogger.warning")
        _enabledLogger.error("_enabledLogger.error")

        _disabledLogger.debug("_disabledLogger.debug")
        _disabledLogger.info("_disabledLogger.info")
        _disabledLogger.warning("_disabledLogger.warning")
        _disabledLogger.error("_disabledLogger.error")
github mar10 / wsgidav / tests / test_wsgidav_app.py View on Github external
def testGetPut(self):
        """Read and write file contents."""
        app = self.app

        # Prepare file content
        data1 = b"this is a file\nwith two lines"
        data2 = b"this is another file\nwith three lines\nsee?"
        # Big file with 10 MB
        lines = []
        line = "." * (1000 - 6 - len("\n"))
        for i in compat.xrange(10 * 1000):
            lines.append("%04i: %s\n" % (i, line))
        data3 = "".join(lines)
        data3 = compat.to_bytes(data3)

        # Remove old test files
        app.delete("/file1.txt", expect_errors=True)
        app.delete("/file2.txt", expect_errors=True)
        app.delete("/file3.txt", expect_errors=True)

        # Access unmapped resource (expect '404 Not Found')
        app.delete("/file1.txt", status=404)
        app.get("/file1.txt", status=404)

        # PUT a small file (expect '201 Created')
        app.put("/file1.txt", params=data1, status=201)

        res = app.get("/file1.txt", status=200)
        assert res.body == data1, "GET file content different from PUT"
github mar10 / wsgidav / tests / test_scripted.py View on Github external
def testGetPut(self):
        """Read and write file contents."""
        client = self.client
        # Prepare file content
        data1 = b"this is a file\nwith two lines"
        data2 = b"this is another file\nwith three lines\nsee?"
        # Big file with 10 MB
        lines = []
        line = "." * (1000 - 6 - len("\n"))
        for i in compat.xrange(10 * 1000):
            lines.append("%04i: %s\n" % (i, line))
        data3 = "".join(lines)
        data3 = compat.to_bytes(data3)

        # Cleanup
        client.delete("/test/")
        client.mkcol("/test/")
        client.check_response(201)

        # PUT files
        client.put("/test/file1.txt", data1)
        client.check_response(201)
        client.put("/test/file2.txt", data2)
        client.check_response(201)
        client.put("/test/bigfile.txt", data3)
        client.check_response(201)

        body = client.get("/test/file1.txt")
        client.check_response(200)
github mar10 / wsgidav / tests / util.py View on Github external
def write_test_file(name, size):
    path = os.path.join(gettempdir(), name)
    with open(path, "wb") as f:
        f.write(compat.to_bytes("*") * size)
    return path
github mar10 / wsgidav / tests / test_util.py View on Github external
def testBasics(self):
        """Test basic tool functions."""
        assert join_uri("/a/b", "c") == "/a/b/c"
        assert join_uri("/a/b/", "c") == "/a/b/c"
        assert join_uri("/a/b", "c", "d") == "/a/b/c/d"
        assert join_uri("a/b", "c", "d") == "a/b/c/d"
        assert join_uri("/", "c") == "/c"
        assert join_uri("", "c") == "/c"

        assert not is_child_uri("/a/b", "/a/")
        assert not is_child_uri("/a/b", "/a/b")
        assert not is_child_uri("/a/b", "/a/b/")
        assert not is_child_uri("/a/b", "/a/bc")
        assert not is_child_uri("/a/b", "/a/bc/")
        assert is_child_uri("/a/b", "/a/b/c")
        assert is_child_uri("/a/b", "/a/b/c")

        assert not is_equal_or_child_uri("/a/b", "/a/")
        assert is_equal_or_child_uri("/a/b", "/a/b")
        assert is_equal_or_child_uri("/a/b", "/a/b/")
        assert not is_equal_or_child_uri("/a/b", "/a/bc")
        assert not is_equal_or_child_uri("/a/b", "/a/bc/")
        assert is_equal_or_child_uri("/a/b", "/a/b/c")
github mar10 / wsgidav / tests / test_util.py View on Github external
def testBasics(self):
        """Test basic tool functions."""
        assert join_uri("/a/b", "c") == "/a/b/c"
        assert join_uri("/a/b/", "c") == "/a/b/c"
        assert join_uri("/a/b", "c", "d") == "/a/b/c/d"
        assert join_uri("a/b", "c", "d") == "a/b/c/d"
        assert join_uri("/", "c") == "/c"
        assert join_uri("", "c") == "/c"

        assert not is_child_uri("/a/b", "/a/")
        assert not is_child_uri("/a/b", "/a/b")
        assert not is_child_uri("/a/b", "/a/b/")
        assert not is_child_uri("/a/b", "/a/bc")
        assert not is_child_uri("/a/b", "/a/bc/")
        assert is_child_uri("/a/b", "/a/b/c")
        assert is_child_uri("/a/b", "/a/b/c")

        assert not is_equal_or_child_uri("/a/b", "/a/")
        assert is_equal_or_child_uri("/a/b", "/a/b")
        assert is_equal_or_child_uri("/a/b", "/a/b/")
        assert not is_equal_or_child_uri("/a/b", "/a/bc")
github mar10 / wsgidav / tests / test_util.py View on Github external
assert join_uri("/a/b", "c", "d") == "/a/b/c/d"
        assert join_uri("a/b", "c", "d") == "a/b/c/d"
        assert join_uri("/", "c") == "/c"
        assert join_uri("", "c") == "/c"

        assert not is_child_uri("/a/b", "/a/")
        assert not is_child_uri("/a/b", "/a/b")
        assert not is_child_uri("/a/b", "/a/b/")
        assert not is_child_uri("/a/b", "/a/bc")
        assert not is_child_uri("/a/b", "/a/bc/")
        assert is_child_uri("/a/b", "/a/b/c")
        assert is_child_uri("/a/b", "/a/b/c")

        assert not is_equal_or_child_uri("/a/b", "/a/")
        assert is_equal_or_child_uri("/a/b", "/a/b")
        assert is_equal_or_child_uri("/a/b", "/a/b/")
        assert not is_equal_or_child_uri("/a/b", "/a/bc")
        assert not is_equal_or_child_uri("/a/b", "/a/bc/")
        assert is_equal_or_child_uri("/a/b", "/a/b/c")
        assert is_equal_or_child_uri("/a/b", "/a/b/c")

        assert lstripstr("/dav/a/b", "/dav") == "/a/b"
        assert lstripstr("/dav/a/b", "/DAV") == "/dav/a/b"
        assert lstripstr("/dav/a/b", "/DAV", True) == "/a/b"

        assert pop_path("/a/b/c") == ("a", "/b/c")
        assert pop_path("/a/b/") == ("a", "/b/")
        assert pop_path("/a/") == ("a", "/")
        assert pop_path("/a") == ("a", "/")
        assert pop_path("/") == ("", "")
        assert pop_path("") == ("", "")
github mar10 / wsgidav / tests / test_util.py View on Github external
assert join_uri("/", "c") == "/c"
        assert join_uri("", "c") == "/c"

        assert not is_child_uri("/a/b", "/a/")
        assert not is_child_uri("/a/b", "/a/b")
        assert not is_child_uri("/a/b", "/a/b/")
        assert not is_child_uri("/a/b", "/a/bc")
        assert not is_child_uri("/a/b", "/a/bc/")
        assert is_child_uri("/a/b", "/a/b/c")
        assert is_child_uri("/a/b", "/a/b/c")

        assert not is_equal_or_child_uri("/a/b", "/a/")
        assert is_equal_or_child_uri("/a/b", "/a/b")
        assert is_equal_or_child_uri("/a/b", "/a/b/")
        assert not is_equal_or_child_uri("/a/b", "/a/bc")
        assert not is_equal_or_child_uri("/a/b", "/a/bc/")
        assert is_equal_or_child_uri("/a/b", "/a/b/c")
        assert is_equal_or_child_uri("/a/b", "/a/b/c")

        assert lstripstr("/dav/a/b", "/dav") == "/a/b"
        assert lstripstr("/dav/a/b", "/DAV") == "/dav/a/b"
        assert lstripstr("/dav/a/b", "/DAV", True) == "/a/b"

        assert pop_path("/a/b/c") == ("a", "/b/c")
        assert pop_path("/a/b/") == ("a", "/b/")
        assert pop_path("/a/") == ("a", "/")
        assert pop_path("/a") == ("a", "/")
        assert pop_path("/") == ("", "")
        assert pop_path("") == ("", "")

        self.assertEqual(shift_path("", "/a/b/c"), ("a", "/a", "/b/c"))
        self.assertEqual(shift_path("/a", "/b/c"), ("b", "/a/b", "/c"))
github mar10 / wsgidav / tests / test_wsgidav_app.py View on Github external
"lock_manager": True,  # True: use lock_manager.LockManager
        }

        if withAuthentication:
            config["http_authenticator"].update(
                {
                    "accept_basic": True,
                    "accept_digest": False,
                    "default_to_digest": False,
                }
            )
            config["simple_dc"]["user_mapping"] = {
                "/": {"tester": {"password": "secret", "description": "", "roles": []}}
            }

        return WsgiDAVApp(config)