def test_update_tags_overwrite_tag(): tag = {'value': 'good', 'color': 'danger', 'propagate': False} result = update_tags(old_tags=dict(some_plugin=dict(any_tag=dict())), plugin_name='some_plugin', tag_name='any_tag', tag=tag) assert result['some_plugin']['any_tag'] == tag
def update_analysis_tags(self, uid, plugin_name, tag_name, tag): firmware_object = self.get_object(uid=uid, analysis_filter=[]) try: tags = update_tags(firmware_object.analysis_tags, plugin_name, tag_name, tag) except ValueError as value_error: logging.error('Plugin {} tried setting a bad tag {}: {}'.format( plugin_name, tag_name, str(value_error))) return None except AttributeError: logging.error('Firmware not in database yet: {}'.format(uid)) return None if isinstance(firmware_object, Firmware): try: self.firmwares.update_one({'_id': uid}, {'$set': { 'analysis_tags': tags }}) except (TypeError, ValueError, PyMongoError) as exception: logging.error('Could not update firmware: {} - {}'.format( type(exception), str(exception))) else: logging.warning( 'Propagating tag only allowed for firmware. Given: {}')
def test_update_tags_propagate_exception(): # pylint: disable=invalid-name bad_tag = {'value': 'good', 'color': 'bad color', 'propagate': True} with pytest.raises(ValueError): update_tags(dict(), 'some_plugin', 'any_tag', bad_tag)