fuel-web/nailgun/nailgun/test/unit/test_plugin_loader.py
Evgeny L daa2799ab4 Set legacy tasks to empty if file is removed or empty
During plugin synchronisation or plugin update, if legacy
tasks (tasks.yaml) are removed, they should be set to empty
value [] in the database.

Closes-bug: #1648223
Related-bug: #1626855
Change-Id: I4c6a61eb6ac0bb4395b843c4ba7df5bcd8ab2f7b
2016-12-07 21:05:10 +00:00

52 lines
1.6 KiB
Python

# -*- coding: utf-8 -*-
# Copyright 2016 Mirantis, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import copy
import mock
import os
from nailgun import errors
from nailgun.plugins.manager import PluginManager
from nailgun.test import base
class TestSync(base.BaseTestCase):
def test_removes_tasks_from_db_if_removed_from_new_plugin(self):
plugin = self.env.create_plugin(
tasks=self.env.get_default_plugin_tasks())
mocked_metadata = {
'metadata.yaml': {},
'environment_config.yaml': {},
}
self.assertNotEqual(plugin.tasks, [])
with mock.patch(
'nailgun.plugins.loaders.files_manager.FilesManager.load'
) as load:
def se(key):
# Simulate that tasks.yaml was removed
if key.endswith('tasks.yaml'):
raise errors.NoPluginFileFound()
return copy.deepcopy(
mocked_metadata.get(os.path.basename(key)))
load.side_effect = se
PluginManager.sync_plugins_metadata(plugin_ids=[plugin.id])
self.assertEqual(plugin.tasks, [])