def update_object(self, new_object=None, old_object=None): update_dictionary = { 'processed_analysis': self._update_processed_analysis(new_object, old_object), 'files_included': update_included_files(new_object, old_object), 'virtual_file_path': update_virtual_file_path(new_object, old_object), } if isinstance(new_object, Firmware): update_dictionary.update({ 'version': new_object.version, 'device_name': new_object.device_name, 'device_part': new_object.part, 'device_class': new_object.device_class, 'vendor': new_object.vendor, 'release_date': convert_str_to_time(new_object.release_date), 'tags': new_object.tags, }) collection = self.firmwares else: update_dictionary.update({ 'parent_firmware_uids': list(set.union(set(old_object['parent_firmware_uids']), new_object.parent_firmware_uids)) }) collection = self.file_objects collection.update_one({'_id': new_object.uid}, {'$set': update_dictionary})
def test_update_virtual_file_path_normal(mutable_test_file, mongo_entry): mutable_test_file.virtual_file_path = { 'new': ['new|path|in|another|object'] } virtual_file_path = update_virtual_file_path(mutable_test_file, mongo_entry) assert len(virtual_file_path.keys()) == 2 assert all(root in virtual_file_path for root in ['any', 'new'])
def test_update_vfp_new_archive_in_old_object(mutable_test_file, mongo_entry): mutable_test_file.virtual_file_path = { 'any': ['any|virtual|new_archive|additional_path'] } virtual_file_path = update_virtual_file_path(mutable_test_file, mongo_entry) assert len(virtual_file_path.keys()) == 1 assert sorted(virtual_file_path['any']) == [ 'any|virtual|new_archive|additional_path', 'any|virtual|path' ]
def test_update_virtual_file_path_overwrite(mutable_test_file, mongo_entry): mutable_test_file.virtual_file_path = {'any': ['any|virtual|/new/path']} virtual_file_path = update_virtual_file_path(mutable_test_file, mongo_entry) assert len(virtual_file_path.keys()) == 1 assert virtual_file_path['any'] == ['any|virtual|/new/path']
def test_update_virtual_file_path_overwrite(mutable_test_file, mongo_entry): mutable_test_file.virtual_file_path = {'any': 'new|path|from|better|unpacker'} virtual_file_path = update_virtual_file_path(mutable_test_file, mongo_entry) assert len(virtual_file_path.keys()) == 1 assert virtual_file_path['any'] == 'new|path|from|better|unpacker'