예제 #1
0
    def test_IfMatchHeader(self):

        server = Session("www.example.com")
        request = Put(server, "/")
        request.setData(None, None, etag="\"12345\"")
        hdrs = request.generateRequestHeader()
        self.assertFalse("If-None-Match:" in hdrs)
        self.assertTrue("If-Match: \"12345\"" in hdrs)
예제 #2
0
    def test_IfNoneMatchHeader(self):

        server = Session("www.example.com")
        request = Put(server, "/")
        request.setData(None, None, new_item=True)
        hdrs = request.generateRequestHeader()
        self.assertTrue("If-None-Match: *" in hdrs)
        self.assertFalse("If-Match:" in hdrs)
예제 #3
0
    def test_IfNoneMatchHeader(self):

        server = Session("www.example.com")
        request = Put(server, "/")
        request.setData(None, None, new_item=True)
        hdrs = request.generateRequestHeader()
        self.assertTrue("If-None-Match: *" in hdrs)
        self.assertFalse("If-Match:" in hdrs)
예제 #4
0
    def test_NoSpecialHeaders(self):

        server = Session("www.example.com")
        request = Put(server, "/")
        request.setData(None, None)
        hdrs = request.generateRequestHeader()
        self.assertFalse("If-None-Match:" in hdrs)
        self.assertFalse("If-Match:" in hdrs)
예제 #5
0
    def test_IfMatchHeader(self):

        server = Session("www.example.com")
        request = Put(server, "/")
        request.setData(None, None, etag="\"12345\"")
        hdrs = request.generateRequestHeader()
        self.assertFalse("If-None-Match:" in hdrs)
        self.assertTrue("If-Match: \"12345\"" in hdrs)
예제 #6
0
    def test_NoSpecialHeaders(self):

        server = Session("www.example.com")
        request = Put(server, "/")
        request.setData(None, None)
        hdrs = request.generateRequestHeader()
        self.assertFalse("If-None-Match:" in hdrs)
        self.assertFalse("If-Match:" in hdrs)
예제 #7
0
    def writeData(self, rurl, data, contentType):

        assert(isinstance(rurl, URL))

        # Create WebDAV PUT
        request = Put(self, rurl.relativeURL())
        dout = RequestDataString(data, contentType)
        request.setData(dout, None)

        # Process it
        self.runSession(request)

        # Check response status
        if request.getStatusCode() not in (statuscodes.OK, statuscodes.Created, statuscodes.NoContent,):
            self.handleHTTPError(request)
예제 #8
0
    def test_Bad(self):

        server = Session("www.example.com")
        request = Put(server, "/")
        self.assertRaises(AssertionError, request.setData, None, None, **{
            "etag": "\"12345\"",
            "new_item": True
        })
예제 #9
0
    def test_Method(self):

        server = Session("www.example.com")
        request = Put(server, "/")
        self.assertEqual(request.getMethod(), "PUT")
예제 #10
0
    def writeData(self, rurl, data, contentType, etag=None, method="PUT"):

        assert (isinstance(rurl, URL))

        # Create WebDAV PUT
        if method == "PUT":
            request = Put(self, rurl.relativeURL())
        elif method == "POST":
            request = Post(self, rurl.relativeURL())
        elif method == "OPTIONS":
            request = Options(self, rurl.relativeURL())

        dout = ResponseDataString()

        if data is not None:
            din = RequestDataString(data, contentType)
            if method == "PUT":
                request.setData(din, dout, etag=etag)
            elif method == "POST":
                request.setData(din, dout)
        else:
            request.setData(None, dout)

        # Process it
        self.runSession(request)

        # Check response status
        if request.getStatusCode() not in (
                statuscodes.OK,
                statuscodes.Created,
                statuscodes.NoContent,
        ):
            self.handleHTTPError(request)

        # Return data as a string
        return dout.getData()
예제 #11
0
    def test_Method(self):

        server = Session("www.example.com")
        request = Put(server, "/")
        self.assertEqual(request.getMethod(), "PUT")