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)
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)
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)
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)
def test_Bad(self): server = Session("www.example.com") request = Put(server, "/") self.assertRaises(AssertionError, request.setData, None, None, **{ "etag": "\"12345\"", "new_item": True })
def test_Method(self): server = Session("www.example.com") request = Put(server, "/") self.assertEqual(request.getMethod(), "PUT")
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()