def test_getBigFile(self, bigTestfile): # Read in original data with open(bigTestfile, 'rb') as fp: data = fp.read() # Read via fileClient startTime = time.time() cmd = projUtils.getFileReqStruct(bigTestfile) try: responseData = handleDataRequest(cmd) except Exception as err: assert False, str(err) assert responseData == data print('Read Bigfile time: {}'.format(time.time() - startTime)) # Write bigFile Synchronous startTime = time.time() cmd = projUtils.putBinaryFileReqStruct(bigTestfile) for putFilePart in projUtils.generateDataParts(data, cmd, compress=False): response = Web.sendDataMsgFromThread(putFilePart) assert response['status'] == 200 print('Write Bigfile sync time: {}'.format(time.time() - startTime)) # Write bigFile Asynchronous startTime = time.time() cmd = projUtils.putBinaryFileReqStruct(bigTestfile) callIds = [] for putFilePart in projUtils.generateDataParts(data, cmd, compress=False): callId = Web.sendDataMsgFromThreadAsync(putFilePart) callIds.append(callId) for callId in callIds: response = Web.getDataMsgResponse(callId) assert response['status'] == 200 print('Write Bigfile async time: {}'.format(time.time() - startTime)) # Read back written data writtenPath = os.path.join(CommonOutputDir, bigTestfile) with open(writtenPath, 'rb') as fp: writtenData = fp.read() assert writtenData == data
def test_ping(self): print("test_ping") global pingCallbackEvent # Send a ping request from projectInterface to fileWatcher assert Web.wsDataConn is not None cmd = {'cmd': 'ping'} response = Web.sendDataMsgFromThread(cmd, timeout=2) if response['status'] != 200: print("Ping error: {}".format(response)) assert response['status'] == 200
logging.INFO, filename=os.path.join(currPath, 'logs/sample.log')) argParser = argparse.ArgumentParser() argParser.add_argument('--filesremote', '-x', default=False, action='store_true', help='dicom files retrieved from remote server') argParser.add_argument('--config', '-c', default=defaultConfig, type=str, help='experiment file (.json or .toml)') argParser.add_argument( '--test', '-t', default=False, action='store_true', help='start projectInterface in test mode, unsecure') args = argParser.parse_args() params = StructDict({ 'fmriPyScript': scriptToRun, 'initScript': initScript, 'finalizeScript': finalizeScript, 'filesremote': args.filesremote, }) web = Web() web.start(params, args.config, testMode=args.test)
def teardown_class(cls): WsFileWatcher.stop() Web.stop() time.sleep(1) pass
def test_getFile(self, dicomTestFilename): print("test_getFile") global fileData assert Web.wsDataConn is not None # Try to initialize file watcher with non-allowed directory cmd = projUtils.initWatchReqStruct('/', '*', 0) response = Web.sendDataMsgFromThread(cmd) # we expect an error because '/' directory not allowed assert response['status'] == 400 # Initialize with allowed directory cmd = projUtils.initWatchReqStruct(testDir, '*.dcm', 0) response = Web.sendDataMsgFromThread(cmd) assert response['status'] == 200 dcmImg = readDicomFromFile(dicomTestFilename) anonDcm = anonymizeDicom(dcmImg) data = writeDicomToBuffer(anonDcm) # with open(dicomTestFilename, 'rb') as fp: # data = fp.read() cmd = projUtils.watchFileReqStruct(dicomTestFilename) try: responseData = handleDataRequest(cmd) except Exception as err: assert False, str(err) # import pdb; pdb.set_trace() assert responseData == data # Try compressed version cmd = projUtils.watchFileReqStruct(dicomTestFilename, compress=True) try: responseData = handleDataRequest(cmd) except Exception as err: assert False, str(err) assert responseData == data cmd = projUtils.getFileReqStruct(dicomTestFilename) try: responseData = handleDataRequest(cmd) except Exception as err: assert False, str(err) assert responseData == data # Try compressed version cmd = projUtils.getFileReqStruct(dicomTestFilename, compress=True) try: responseData = handleDataRequest(cmd) except Exception as err: assert False, str(err) assert responseData == data cmd = projUtils.getNewestFileReqStruct(dicomTestFilename) try: responseData = handleDataRequest(cmd) except Exception as err: assert False, str(err) assert responseData == data # Try to get a non-allowed file cmd = projUtils.getFileReqStruct('/tmp/file.nope') try: responseData = handleDataRequest(cmd) except RequestError as err: # Expecting a status not 200 error to be raised assert 'status' in str(err) else: self.fail('Expecting RequestError') # try from a non-allowed directory cmd = projUtils.getFileReqStruct('/nope/file.dcm') try: responseData = handleDataRequest(cmd) except RequestError as err: # Expecting a status not 200 error to be raised assert 'status' in str(err) else: self.fail('Expecting RequestError') # Test putTextFile testText = 'hello2' textFileName = os.path.join(tmpDir, 'test2.txt') cmd = projUtils.putTextFileReqStruct(textFileName, testText) response = Web.sendDataMsgFromThread(cmd) assert response['status'] == 200 # Test putBinaryData function testData = b'\xFE\xED\x01\x23' dataFileName = os.path.join(tmpDir, 'test2.bin') cmd = projUtils.putBinaryFileReqStruct(dataFileName) for putFilePart in projUtils.generateDataParts(testData, cmd, compress=True): response = Web.sendDataMsgFromThread(putFilePart) assert response['status'] == 200 # read back an compare to original cmd = projUtils.getFileReqStruct(dataFileName) response = Web.sendDataMsgFromThread(cmd) responseData = b64decode(response['data']) assert responseData == testData
defaultConfig = os.path.join(currPath, 'conf/faceMatching_organized.toml') if __name__ == "__main__": installLoggers(logging.INFO, logging.INFO, filename=os.path.join(currPath, 'logs/webServer.log')) argParser = argparse.ArgumentParser() argParser.add_argument('--filesremote', '-x', default=False, action='store_true', help='dicom files retrieved from remote server') argParser.add_argument('--config', '-c', default=defaultConfig, type=str, help='experiment file (.json or .toml)') args = argParser.parse_args() # HERE: Set the path to the fMRI Python script to run here params = StructDict({ 'fmriPyScript': 'projects/faceMatching/faceMatching.py', 'filesremote': args.filesremote, }) cfg = loadConfigFile(args.config) web = Web() web.start(params, cfg)