示例#1
0
 def test_docx_and_csv(self):
     """ CSV and DOCX should be 80
     """
     files = [
         ('word_document.docx', 'some/word_document.docx'),
         ('a.csv', 'and/a.csv'),
     ]
     self.assertEqual(api.calculate_score(files), 80)
示例#2
0
 def test_docx_and_csv(self):
     """ CSV and DOCX should be 80
     """
     files = [
         ('word_document.docx', 'some/word_document.docx'),
         ('a.csv', 'and/a.csv'),
     ]
     self.assertEqual(api.calculate_score(files), 80)
示例#3
0
 def test_csvs(self):
     """Everything csv should be 100
     """
     files = [
         ('something.csv', 'something.csv'),
         ('something-else.csv', 'something-else.csv'),
         ('thing.csv', 'and/also-this/thing.csv'),
     ]
     self.assertEqual(api.calculate_score(files), 100)
示例#4
0
 def test_csvs(self):
     """Everything csv should be 100
     """
     files = [
         ('something.csv', 'something.csv'),
         ('something-else.csv', 'something-else.csv'),
         ('thing.csv', 'and/also-this/thing.csv'),
     ]
     self.assertEqual(api.calculate_score(files), 100)
示例#5
0
    def test_single_files(self):
        """Test a with some basic document types

        Types:
         - csv
         - pdf
         - xlsx
        """
        r = RecordMock.get_mocked_record()
        score = api.calculate_score(r['files_to_upload'])
        self.assertEqual(score, 80)
示例#6
0
    def test_single_files(self):
        """Test a with some basic document types

        Types:
         - csv
         - pdf
         - xlsx
        """
        r = RecordMock.get_mocked_record()
        score = api.calculate_score(r['files_to_upload'])
        self.assertEqual(score, 80)
示例#7
0
    def test_record_mocking(self, get_record_mock):
        """Tests the general mocking of records.

        Namely, if the files of the record are accessible and
        also other general information.
        """
        # First get the mockeed record
        r = RecordMock.get_mocked_record()
        # Assert general information
        self.assertEqual(r['doi'], '10.1234/invenio.1234')
        self.assertEqual(r['recid'], 1)

        # Score calculation testing.
        # For each file
        score1 = api.calculate_score([r['files_to_upload'][0]])
        score2 = api.calculate_score([r['files_to_upload'][1]])
        score3 = api.calculate_score([r['files_to_upload'][2]])
        self.assertEqual(score1, 40)
        self.assertEqual(score2, 100)
        self.assertEqual(score3, 100)
        # And the average
        avg = (sum([score1, score2, score3])) / 3  # 80
        self.assertEqual(api.calculate_score(r['files_to_upload']), avg)
示例#8
0
    def test_record_mocking(self, get_record_mock):
        """Tests the general mocking of records.

        Namely, if the files of the record are accessible and
        also other general information.
        """
        # First get the mockeed record
        r = RecordMock.get_mocked_record()
        # Assert general information
        self.assertEqual(r['doi'], '10.1234/invenio.1234')
        self.assertEqual(r['recid'], 1)

        # Score calculation testing.
        # For each file
        score1 = api.calculate_score([r['files_to_upload'][0]])
        score2 = api.calculate_score([r['files_to_upload'][1]])
        score3 = api.calculate_score([r['files_to_upload'][2]])
        self.assertEqual(score1, 40)
        self.assertEqual(score2, 100)
        self.assertEqual(score3, 100)
        # And the average
        avg = (sum([score1, score2, score3])) / 3  # 80
        self.assertEqual(api.calculate_score(r['files_to_upload']), avg)
示例#9
0
    def test_tar_with_txt_csv(self):
        """Tests a tar file with a txt and csv.

        Creates a temporary dir and adds the two files inside.
        Then creates the archive inside another temporary dir.
        Score should be 100.
        Deletes directories upon finishing.
        """

        # Create a dir to store the files
        tmp_dir = tempfile.mkdtemp()
        # Create a txt file inside tmp_dir
        with open(osp.join(tmp_dir, 'file.txt'), 'w') as txt_file:
            txt_file.write('batata')
        # Create a csv file inside tmp_dir
        with open(osp.join(tmp_dir, 'file.csv'), 'w') as csv_file:
            csv_file.write('123, 123')

        # Create another temporary dir for the zip file.
        tmp_tar_dir = tempfile.mkdtemp()
        # And make an archive out of it
        tar_file = make_archive(osp.join(tmp_tar_dir, '_tar_with_txt_csv'),
                                'tar',
                                tmp_dir)

        self.assertEqual(
            api.calculate_score([(osp.basename(tar_file), tar_file)]),
            100
        )

        # Remove the temporary directories
        rmtree(tmp_dir)
        rmtree(tmp_tar_dir)

        # Test if the files were removed
        self.assertEqual(osp.isdir(tmp_dir), False)
        self.assertEqual(osp.isdir(tmp_tar_dir), False)

        # Redundant.. directory is deleted.
        self.assertEqual(osp.exists(tar_file), False)
        self.assertEqual(osp.exists(txt_file.name), False)
        self.assertEqual(osp.exists(csv_file.name), False)
示例#10
0
    def test_tar_with_txt_csv(self):
        """Tests a tar file with a txt and csv.

        Creates a temporary dir and adds the two files inside.
        Then creates the archive inside another temporary dir.
        Score should be 100.
        Deletes directories upon finishing.
        """

        # Create a dir to store the files
        tmp_dir = tempfile.mkdtemp()
        # Create a txt file inside tmp_dir
        with open(osp.join(tmp_dir, 'file.txt'), 'w') as txt_file:
            txt_file.write('batata')
        # Create a csv file inside tmp_dir
        with open(osp.join(tmp_dir, 'file.csv'), 'w') as csv_file:
            csv_file.write('123, 123')

        # Create another temporary dir for the zip file.
        tmp_tar_dir = tempfile.mkdtemp()
        # And make an archive out of it
        tar_file = make_archive(osp.join(tmp_tar_dir, '_tar_with_txt_csv'),
                                'tar',
                                tmp_dir)

        self.assertEqual(
            api.calculate_score([(osp.basename(tar_file), tar_file)]),
            100
        )

        # Remove the temporary directories
        rmtree(tmp_dir)
        rmtree(tmp_tar_dir)

        # Test if the files were removed
        self.assertEqual(osp.isdir(tmp_dir), False)
        self.assertEqual(osp.isdir(tmp_tar_dir), False)

        # Redundant.. directory is deleted.
        self.assertEqual(osp.exists(tar_file), False)
        self.assertEqual(osp.exists(txt_file.name), False)
        self.assertEqual(osp.exists(csv_file.name), False)
示例#11
0
 def test_fake_tar(self):
     files = [('something.tar', 'something.tar')]
     api.calculate_score(files)
示例#12
0
 def test_fake_zip(self):
     """Tests a fake zip (bad) file.
     """
     files = [('fake.zip', 'this/is/a/fake.zip')]
     self.assertEqual(api.calculate_score(files), 0)
示例#13
0
 def test_unknown_extension(self):
     """Test if unknow or invalid extensions produce 0 score
     """
     files = [('something.ble', 'something.ble'),
              ('something', 'something')]
     self.assertEqual(api.calculate_score(files), 0)
示例#14
0
 def test_tar_with_pdf(self):
     files = [('something.ble', 'something.ble')]
     self.assertEqual(api.calculate_score(files), 0)
示例#15
0
 def test_tar_with_pdf(self):
     files = [('something.ble', 'something.ble')]
     self.assertEqual(api.calculate_score(files), 0)
示例#16
0
 def test_unknown_extension(self):
     """Test if unknow or invalid extensions produce 0 score
     """
     files = [('something.ble', 'something.ble'),
              ('something', 'something')]
     self.assertEqual(api.calculate_score(files), 0)
示例#17
0
 def test_fake_zip(self):
     """Tests a fake zip (bad) file.
     """
     files = [('fake.zip', 'this/is/a/fake.zip')]
     self.assertEqual(api.calculate_score(files), 0)
示例#18
0
 def test_fake_tar(self):
     files = [('something.tar', 'something.tar')]
     api.calculate_score(files)