Beispiel #1
0
    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)
Beispiel #2
0
    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)
Beispiel #3
0
 def test_upload_challenge_file_uploader_is_none(self):
     temp_dir = tempfile.mkdtemp()
     try:
         params = D3RParameters()
         chall = ChallengeDataTask(temp_dir, params)
         chall._upload_challenge_file('/foo')
         self.assertEqual(chall.get_email_log(), 'No uploader available '
                                                 'to upload challenge '
                                                 'data\n')
     finally:
         shutil.rmtree(temp_dir)
Beispiel #4
0
 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)
Beispiel #5
0
    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)