Esempio n. 1
0
    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"

        # PUT overwrites a small file (expect '204 No Content')
        app.put("/file1.txt", params=data2, status=204)

        res = app.get("/file1.txt", status=200)
        assert res.body == data2, "GET file content different from PUT"

        # PUT writes a big file (expect '201 Created')
        app.put("/file2.txt", params=data3, status=201)

        res = app.get("/file2.txt", status=200)
        assert res.body == data3, "GET file content different from PUT"

        # Request must not contain a body (expect '415 Media Type Not
        # Supported')
        app.request(
            "/file1.txt",
            method="GET",
            headers={"Content-Length": compat.to_native(len(data1))},
            body=data1,
            status=415,
        )

        # Delete existing resource (expect '204 No Content')
        app.delete("/file1.txt", status=204)
        # Get deleted resource (expect '404 Not Found')
        app.get("/file1.txt", status=404)

        # PUT a small file (expect '201 Created')
        app.put("/file1.txt", params=data1, status=201)
Esempio n. 2
0
    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"

        # PUT overwrites a small file (expect '204 No Content')
        app.put("/file1.txt", params=data2, status=204)

        res = app.get("/file1.txt", status=200)
        assert res.body == data2, "GET file content different from PUT"

        # PUT writes a big file (expect '201 Created')
        app.put("/file2.txt", params=data3, status=201)

        res = app.get("/file2.txt", status=200)
        assert res.body == data3, "GET file content different from PUT"

        # Request must not contain a body (expect '415 Media Type Not
        # Supported')
        app.request(
            "/file1.txt",
            method="GET",
            headers={"Content-Length": compat.to_native(len(data1))},
            body=data1,
            status=415,
        )

        # Delete existing resource (expect '204 No Content')
        app.delete("/file1.txt", status=204)
        # Get deleted resource (expect '404 Not Found')
        app.get("/file1.txt", status=404)

        # PUT a small file (expect '201 Created')
        app.put("/file1.txt", params=data1, status=201)
Esempio n. 3
0
    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.checkResponse(201)

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

        body = client.get("/test/file1.txt")
        client.checkResponse(200)
        assert body == data1, "Put/Get produced different bytes"

        # PUT with overwrite must return 204 No Content, instead of 201 Created
        client.put("/test/file2.txt", data2)
        client.checkResponse(204)

        client.mkcol("/test/folder")
        client.checkResponse(201)

        locks = client.set_lock("/test/lock-0",
                                owner="test-bench",
                                locktype="write",
                                lockscope="exclusive",
                                depth="infinity")
        client.checkResponse(201)  # created
        assert len(locks) == 1, "LOCK failed"
        token = locks[0]
        client.refresh_lock("/test/lock-0", token)
        client.checkResponse(200)  # ok
        client.unlock("/test/lock-0", token)
        client.checkResponse(204)  # no content
        client.unlock("/test/lock-0", token)
        # 409 Conflict, because resource was not locked
        # (http://www.webdav.org/specs/rfc4918.html#METHOD_UNLOCK)
        client.checkResponse(409)

        client.proppatch("/test/file1.txt",
                         set_props=[("{testns:}testname", "testval"),
                                    ],
                         remove_props=None)
        client.checkResponse()

        client.copy("/test/file1.txt",
                    "/test/file2.txt",
                    depth='infinity', overwrite=True)
        client.checkResponse()

        client.move("/test/file2.txt",
                    "/test/file2_moved.txt",
                    depth='infinity', overwrite=True)
        client.checkResponse()

        client.propfind("/",
                        properties="allprop",
                        namespace='DAV:',
                        depth=None,
                        headers=None)
        client.checkResponse()
Esempio n. 4
0
    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)
        assert body == data1, "Put/Get produced different bytes"

        # PUT with overwrite must return 204 No Content, instead of 201 Created
        client.put("/test/file2.txt", data2)
        client.check_response(204)

        client.mkcol("/test/folder")
        client.check_response(201)

        # if a LOCK request is sent to an unmapped URL, we must create a
        # lock-null resource and return '201 Created', instead of '404 Not found'
        locks = client.set_lock(
            "/test/lock-0",
            owner="test-bench",
            lock_type="write",
            lock_scope="exclusive",
            depth="infinity",
        )
        client.check_response(201)  # created
        assert len(locks) == 1, "LOCK failed"

        token = locks[0]
        client.refresh_lock("/test/lock-0", token)
        client.check_response(200)  # ok

        client.unlock("/test/lock-0", token)
        client.check_response(204)  # no content

        client.unlock("/test/lock-0", token)
        # 409 Conflict, because resource was not locked
        # (http://www.webdav.org/specs/rfc4918.html#METHOD_UNLOCK)
        client.check_response(409)

        # issue #71: unlock non existing resource
        client.unlock("/test/lock-not-existing", token)
        client.check_response(404)

        client.proppatch(
            "/test/file1.txt",
            set_props=[("{testns:}testname", "testval")],
            remove_props=None,
        )
        client.check_response()

        client.copy(
            "/test/file1.txt", "/test/file2.txt", depth="infinity", overwrite=True
        )
        client.check_response()

        client.move(
            "/test/file2.txt", "/test/file2_moved.txt", depth="infinity", overwrite=True
        )
        client.check_response()

        client.propfind(
            "/", properties="allprop", namespace="DAV:", depth=None, headers=None
        )
        client.check_response()
Esempio n. 5
0
def _bench_script(opts):
    # print("Scriptes benchmarks")
    # print("_bench_script(), {}...".format(opts))

    from tests import davclient

    server_url = opts.get("external_server") or "http://localhost:8080/"
    client = davclient.DAVClient(server_url)
    client.set_basic_auth("tester", "secret")

    # Prepare file content
    data_1k = b"." * 1000

    # Prepare 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))
    data_10m = "".join(lines)
    data_10m = compat.to_bytes(data_10m)

    with Timing("Setup fixture"):
        _setup_fixture(opts, client)

    # PUT files
    with Timing("1000 x PUT 1 kB", 1000, "{:>6.1f} req/sec", 1,
                "{:>7,.3f} MB/sec"):
        for _ in compat.xrange(1000):
            client.put("/test/file1.txt", data_1k)
        client.check_response()

    with Timing("10 x PUT 10 MB", 10, "{:>6.1f} req/sec", 100,
                "{:>7,.3f} MB/sec"):
        for _ in compat.xrange(10):
            client.put("/test/bigfile.txt", data_10m)
        client.check_response()

    with Timing("1000 x GET 1 kB", 1000, "{:>6.1f} req/sec", 1,
                "{:>7,.3f} MB/sec"):
        for _ in compat.xrange(1000):
            body = client.get("/test/file1.txt")
        client.check_response()

    with Timing("10 x GET 10 MB", 10, "{:>6.1f} req/sec", 100,
                "{:>7,.3f} MB/sec"):
        for _ in compat.xrange(10):
            body = client.get("/test/bigfile.txt")  # noqa F841
        client.check_response()

    with Timing("10 x COPY 10 MB", 10, "{:>6.1f} req/sec", 100,
                "{:>7,.3f} MB/sec"):
        for _ in compat.xrange(10):
            client.copy(
                "/test/bigfile.txt",
                "/test/bigfile-copy.txt",
                depth="infinity",
                overwrite=True,
            )
        client.check_response()

    with Timing("100 x MOVE 10 MB", 100, "{:>6.1f} req/sec"):
        name_from = "/test/bigfile-copy.txt"
        for i in compat.xrange(100):
            name_to = "/test/bigfile-copy-{}.txt".format(i)
            client.move(name_from, name_to, depth="infinity", overwrite=True)
            name_from = name_to
        client.check_response()

    with Timing("100 x LOCK/UNLOCK", 200, "{:>6.1f} req/sec"):
        for _ in compat.xrange(100):
            locks = client.set_lock(
                "/test/lock-0",
                owner="test-bench",
                locktype="write",
                lockscope="exclusive",
                depth="infinity",
            )
            token = locks[0]
            client.unlock("/test/lock-0", token)
        client.check_response()

    with Timing("1000 x PROPPATCH", 1000, "{:>6.1f} req/sec"):
        for _ in compat.xrange(1000):
            client.proppatch(
                "/test/file1.txt",
                set_props=[("{testns:}testname", "testval")],
                remove_props=None,
            )
        client.check_response()

    with Timing("500 x PROPFIND", 500, "{:>6.1f} req/sec"):
        for _ in compat.xrange(500):
            client.propfind("/",
                            properties="allprop",
                            namespace="DAV:",
                            depth=None,
                            headers=None)
        client.check_response()