def generate_mock_resource(self,
                            time_created=None,
                            time_modified=None,
                            uuid=uuid.uuid4().__str__()):
     title_1 = Title('no', self.random_word(6))
     title_2 = Title('en', self.random_word(6))
     titles = {
         title_1.language_code: title_1.title,
         title_2.language_code: title_2.title
     }
     creator_one = Creator('AUTHORITY_IDENTIFIER_1')
     creator_two = Creator('AUTHORITY_IDENTIFIER_2')
     creators = [creator_one, creator_two]
     metadata = Metadata(creators, 'https://hdl.handle.net/11250.1/1',
                         'LICENSE_IDENTIFIER_1', '2019', 'Unit', titles,
                         'text')
     file_metadata_1 = FileMetadata(
         self.random_word(6) + '.txt', 'text/plain',
         '595f44fec1e92a71d3e9e77456ba80d1', '987654321')
     file_metadata_2 = FileMetadata(
         self.random_word(6) + '.pdf', 'application/pdf',
         '71f920fa275127a7b60fa4d4d41432a3', '123456789')
     file_1 = File('FILE_IDENTIFIER_1', file_metadata_1)
     file_2 = File('FILE_IDENTIFIER_2', file_metadata_2)
     files = dict()
     files[file_1.identifier] = file_1.file_metadata
     files[file_2.identifier] = file_2.file_metadata
     return Resource(uuid, time_modified, time_created, metadata, files,
                     '*****@*****.**')
Beispiel #2
0
 def test_open_file(self):
     f2 = File(self.test_file2_name)
     try:
         f2.edit()
     except Exception:
         self.fail('File cannot be opened.')
     else:
         os.remove(self.test_file2_name)
         pass
Beispiel #3
0
 def load_data(self, file_name):
     file = File(file_name)
     file.read()
     self.total_items = file.total_items
     self.capacity = file.capacity
     self.optimal_know = file.optimal_know
     i = 0
     for variable in file.items:
         v = Variable(i, variable[0], variable[1])
         self.variables.append(v)
         i += 1
Beispiel #4
0
 def test_invalid_ext(self):
     """ See if the program catches an invalid ext"""
     file_name = 'Word.rabbit'
     try:
         f4 = File(file_name)
     except Exception:
         pass
     else:
         self.fail('Expected not raised')
Beispiel #5
0
    def create_file(self, file_name):
        """ Creates a new file and adds it to the files list.
        
            Parameters
            ----------
            file_name: str
                The name of the file, including file extension.
        """

        new_file = File(file_name).save()
        self.add_file(file_name)
Beispiel #6
0
 def add_file(self, file_name):
     """ Adds an existing file to the list of files
         File must be existing. If not, throw error.
         TODO: prevent adding duplicates
     
         Parameters
         ----------
         file_name : str
             Must include the suffix of the file name
     """
     if file_name not in self.files:
         if self.validate_file(file_name):
             new_file = File(file_name).save()
             self.files.append(new_file)
             print('New file created.')
         else:
             raise ('File type is not valid.')
     else:
         raise ('File already in list.')
Beispiel #7
0
 def setUp(self):
     self.f1 = File('data.txt')
     self.test_file2_name = 'test_data2.txt'
 def get_data(self):
     file = File(self.filename)
     return file.getCSVasDataframe()
Beispiel #9
0
 def set_data(self):
     file = File(self.filename)
     return file.setDataframeasCSV(data=self.dataframe)