def test_upload_challenge_file_uploader_successful(self): temp_dir = tempfile.mkdtemp() try: params = D3RParameters() yeardir = os.path.join(temp_dir, '2017') os.mkdir(yeardir) weekdir = os.path.join(yeardir, 'dataset.week.1') os.mkdir(weekdir) chall = ChallengeDataTask(weekdir, params) chall.create_dir() mockftp = D3RParameters() mockftp.put = Mock(side_effect=[3, 5]) ftp = FtpFileTransfer(None) ftp.set_remote_challenge_dir('/challenge') ftp.set_connection(mockftp) ftp.connect() chall.set_file_transfer(ftp) tarball = os.path.join(chall.get_dir(), 'celppweek1_2017.tar.gz') f = open(tarball, 'w') f.write('hi') f.flush() f.close() latest_file = os.path.join(chall.get_dir(), ChallengeDataTask.LATEST_TXT) chall._upload_challenge_file(tarball) f = open(latest_file, 'r') line = f.readline() self.assertEqual(line, 'celppweek1_2017.tar.gz') f.close() ftp.disconnect() finally: shutil.rmtree(temp_dir)
def test_upload_challenge_file_uploader_upload_fails(self): temp_dir = tempfile.mkdtemp() try: params = D3RParameters() yeardir = os.path.join(temp_dir, '2016') os.mkdir(yeardir) weekdir = os.path.join(yeardir, 'dataset.week.50') os.mkdir(weekdir) chall = ChallengeDataTask(weekdir, params) chall.create_dir() mockftp = D3RParameters() mockftp.put = Mock(side_effect=IOError('hi')) ftp = FtpFileTransfer(None) ftp.set_remote_challenge_dir('/challenge') ftp.set_connection(mockftp) ftp.connect() chall.set_file_transfer(ftp) tarball = os.path.join(chall.get_dir(), 'celppweek50_2016.tar.gz') f = open(tarball, 'w') f.write('hi') f.flush() f.close() try: chall._upload_challenge_file(tarball) self.fail('Expected exception') except Exception as e: self.assertEqual(str(e), 'Unable to upload ' + tarball + ' to /challenge/celppweek50_2016.tar.gz : ' + 'hi') ftp.disconnect() finally: shutil.rmtree(temp_dir)
def test_run_success_with_ftp_upload(self): temp_dir = tempfile.mkdtemp() try: script = self.create_gen_challenge_script(temp_dir) params = D3RParameters() params.genchallenge = script params.pdbdb = '/foo' params.version = '1' blastnfilter = BlastNFilterTask(temp_dir, params) blastnfilter.create_dir() open(os.path.join(blastnfilter.get_dir(), D3RTask.COMPLETE_FILE), 'a').close() chall = ChallengeDataTask(temp_dir, params) mockftp = D3RParameters() mockftp.put = Mock(side_effect=[3, 5]) ftp = FtpFileTransfer(None) ftp.set_remote_challenge_dir('/challenge') ftp.set_connection(mockftp) chall.set_file_transfer(ftp) dimport = DataImportTask(temp_dir, params) dimport.create_dir() ctsv = dimport.get_crystalph_tsv() f = open(ctsv, 'w') f.write('crystal') f.flush() f.close() nonpoly = dimport.get_nonpolymer_tsv() f = open(nonpoly, 'w') f.write('nonpoly') f.flush() f.close() seq = dimport.get_sequence_tsv() f = open(seq, 'w') f.write('seq') f.flush() f.close() chall.run() self.assertEqual(chall.get_error(), None) # verify test files get created errfile = os.path.join(chall.get_dir(), D3RTask.ERROR_FILE) self.assertEqual(os.path.isfile(errfile), False) compfile = os.path.join(chall.get_dir(), D3RTask.COMPLETE_FILE) self.assertEqual(os.path.isfile(compfile), True) ftp.disconnect() finally: shutil.rmtree(temp_dir)
def test_upload_challenge_file_no_remote_challenge_dir(self): temp_dir = tempfile.mkdtemp() try: params = D3RParameters() chall = ChallengeDataTask(temp_dir, params) ftp = FtpFileTransfer(None) chall.set_file_transfer(ftp) chall._upload_challenge_file('/foo') self.assertEqual(chall.get_email_log(), 'No remote challenge' ' directory set for ' 'ftp upload\n') finally: shutil.rmtree(temp_dir)
def test_upload_challenge_file_challenge_file_is_none(self): temp_dir = tempfile.mkdtemp() try: params = D3RParameters() chall = ChallengeDataTask(temp_dir, params) chall._upload_challenge_file(None) chall.set_file_transfer(params) self.assertEqual(chall.get_email_log(), 'challenge_file is None in' ' _upload_challenge_file' '\n') finally: shutil.rmtree(temp_dir)