def test_PUT_RAW_DATA(self): random_key = "key_" + uuid.uuid4().get_hex()[:10] random_value = "value_" + uuid.uuid4().get_hex() data = "%s:%s" % (random_key, random_value) r = requests.put(build_url('put'), data=data) self.assertEquals(r.status_code, 200) self.assertTrue(data in r.content)
def test_PUT_RAW_DATA(self): random_key = "key_" + uuid.uuid4().hex[:10] random_value = "value_" + uuid.uuid4().hex data = "%s:%s" % (random_key, random_value) r = requests.put(build_url('put'), data=data) self.assertEquals(r.status_code, 200) self.assertTrue(r.text.find(data) != -1)
def test_PUT_DATA_and_FILES(self): files = {'test_file': open('tests.py'), 'test_file2': open('README.rst')} random_key1 = "key_" + uuid.uuid4().get_hex()[:10] random_key2 = "key_" + uuid.uuid4().get_hex()[:10] random_value2 = "value_" + uuid.uuid4().get_hex() r = requests.put(build_url('put'), data={random_key1: random_value2, random_key2: random_value2}, files=files) self.assertEquals(r.status_code, 200)
def _save(self, name, content): logger.debug(u'saving {0}'.format(name)) is_tmp_file = hasattr(content.file, 'temporary_file_path') if is_tmp_file: data = None logger.debug(u"uploading from temporary file") else: # read content into memory logger.debug(u"uploading from memory") data = content.read() for location in self._locations: logger.debug(u'saving in {0}'.format(location)) if is_tmp_file: # send file without loading it in memory c = pycurl.Curl() f = content.file.temporary_file_path() c.setopt(c.URL, self._get_full_path(location, name)) c.setopt(c.PUT, True) filesize = os.path.getsize(f) c.setopt(pycurl.INFILESIZE, filesize) c.setopt(pycurl.READFUNCTION, FileReader(open(f, 'rb')).read_callback) c.setopt(pycurl.TIMEOUT, self._timeout) c.perform() status_code = int(c.getinfo(c.RESPONSE_CODE)) c.close() else: response = requests.put( self._get_full_path(location, name), data=data, timeout=self._timeout ) status_code = response.status_code if status_code not in (201, 204): msg = u"uploading {0}: status code {1}".format( self._get_full_path(location, name), status_code ) logger.error(msg) raise WebDAVException(msg) logger.debug(u'{0} successfully saved'.format(name)) return name
def test_PUT_DATA(self): random_key = "key_" + uuid.uuid4().get_hex()[:10] random_value = "value_" + uuid.uuid4().get_hex() r = requests.put(build_url('put'), data={random_key: random_value}) self.assertEquals(r.status_code, 200)
def test_HTTP_PUT(self): r = requests.put(build_url("put")) self.assertEquals(r.status_code, 200) r2 = requests.put(build_url("put"), data='kcjbwefjhwbcelihbflwkh') self.assertEquals(r2.status_code, 200)
def put(uri, data, token=None): headers = {"X-Auth-Token": token, "content-type": "application/json"} return requests.put(uri, data=json.dumps(data), headers=headers)