def test_update_included_files_duplicate(mutable_test_file, mongo_entry): mutable_test_file.files_included = ['beware', 'the', 'duplicated_entry'] files_included = update_included_files(mutable_test_file, mongo_entry) assert len(files_included) == 4 assert all( name in files_included for name in ['legacy_file', 'beware', 'the', 'duplicated_entry'])
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_included_files_normal(mutable_test_file, mongo_entry): mutable_test_file.files_included = ['i', 'like', 'files'] files_included = update_included_files(mutable_test_file, mongo_entry) assert len(files_included) == 5 assert all( name in files_included for name in ['i', 'like', 'files', 'legacy_file', 'duplicated_entry'])