def testFailingFileUpload(self): """ The method upload a file (data/TestUpload.txt) and check if the server API has saved it """ uploadedFilename = "UploadedFile.txt" fileName = os.path.join(os.path.dirname(__file__), "../../../data/TestUpload.txt") # Check the uploaded file is not there if os.path.isfile(uploadedFilename): os.remove(uploadedFilename) self.assertFalse(os.path.isfile(uploadedFilename)) # do the upload using the wrong address try: res = uploadFile(fileName, "http://127.0.0.1:8888/unittests/rest/iAmNotThere/") self.fail() except HTTPException, he: self.assertEqual(he.status, 404)
def testFileUpload(self): """ The method upload a file (data/TestUpload.txt) and check if the server API has saved it """ uploadedFilename = "UploadedFile.txt" fileName = os.path.join(os.path.dirname(__file__), "../../../data/TestUpload.txt") # Check the uploaded file is not there if os.path.isfile(uploadedFilename): os.remove(uploadedFilename) self.assertFalse(os.path.isfile(uploadedFilename)) # do the upload res = uploadFile(fileName, "http://127.0.0.1:8888/unittests/rest/file/") # the file is there now (?) self.assertTrue(os.path.isfile(uploadedFilename)) self.assertEquals(open(uploadedFilename).read(), open(fileName).read()) # delete the uploaded file os.remove(uploadedFilename) self.assertTrue("Success" in res)
def testFailingFileUpload(self): """ The method upload a file (data/TestUpload.txt) and check if the server API has saved it """ uploadedFilename = 'UploadedFile.txt' fileName = os.path.join(os.path.dirname(__file__), "../../../data/TestUpload.txt") #Check the uploaded file is not there if os.path.isfile(uploadedFilename): os.remove(uploadedFilename) self.assertFalse(os.path.isfile(uploadedFilename)) #do the upload using the wrong address try: res = uploadFile( fileName, 'http://127.0.0.1:8888/unittests/rest/iAmNotThere/') self.fail() except HTTPException, he: self.assertEqual(he.status, 404)
def upload(self, fileName, subDir=None, name=None): """ Upload the file """ #TODO: the following three lines will not be needed anymore if we only support the new REST endpointSuffix = '/userfilecache/upload/' if not self['newrest'] else '' cksumParam = 'checksum' if not self['newrest'] else 'hashkey' fieldName = 'userfile' if not self['newrest'] else 'inputfile' uploadURL = self['endpoint'] + endpointSuffix params = [(cksumParam, self.checksum(fileName))] if subDir or name: params.append(('subDir', subDir)) params.append(('name', name)) resString = uploadFile(fileName=fileName, fieldName=fieldName, url=uploadURL, params=params, \ verb='PUT', ckey=self['proxyfilename'], cert=self['proxyfilename'], capath=self['capath'] ) return json.loads(resString)
def testFileUpload(self): """ The method upload a file (data/TestUpload.txt) and check if the server API has saved it """ uploadedFilename = 'UploadedFile.txt' fileName = os.path.join(os.path.dirname(__file__), "../../../data/TestUpload.txt") #Check the uploaded file is not there if os.path.isfile(uploadedFilename): os.remove(uploadedFilename) self.assertFalse(os.path.isfile(uploadedFilename)) #do the upload res = uploadFile(fileName, 'http://127.0.0.1:8888/unittests/rest/file/') #the file is there now (?) self.assertTrue(os.path.isfile(uploadedFilename)) self.assertEquals(open(uploadedFilename).read(), open(fileName).read()) #delete the uploaded file os.remove(uploadedFilename) self.assertTrue('Success' in res)