1 # Licensed to the Apache Software Foundation (ASF) under one or more
2 # contributor license agreements. See the NOTICE file distributed with
3 # this work for additional information regarding copyright ownership.
4 # The ASF licenses this file to You under the Apache License, Version 2.0
5 # (the "License"); you may not use this file except in compliance with
6 # the License. You may obtain a copy of the License at
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
20 from aria.orchestrator import exceptions
21 from aria.utils.plugin import create as create_plugin
23 from ..fixtures import ( # pylint: disable=unused-import
26 inmemory_model as model
30 PACKAGE_NAME = 'mock-plugin'
31 PACKAGE_VERSION = '100'
34 class TestPluginManager(object):
36 def test_install(self, plugin_manager, mock_plugin, model, plugins_dir):
37 plugin = plugin_manager.install(mock_plugin)
38 assert plugin.package_name == PACKAGE_NAME
39 assert plugin.package_version == PACKAGE_VERSION
40 assert plugin == model.plugin.get(plugin.id)
41 plugin_dir = os.path.join(plugins_dir, '{0}-{1}'.format(PACKAGE_NAME, PACKAGE_VERSION))
42 assert os.path.isdir(plugin_dir)
43 assert plugin_dir == plugin_manager.get_plugin_dir(plugin)
45 def test_install_already_exits(self, plugin_manager, mock_plugin):
46 plugin_manager.install(mock_plugin)
47 with pytest.raises(exceptions.PluginAlreadyExistsError):
48 plugin_manager.install(mock_plugin)
52 def mock_plugin(tmpdir):
53 source_dir = tmpdir.join('mock_plugin')
55 setup_py = source_dir.join('setup.py')
56 setup_py.write('from setuptools import setup; setup(name="{0}", version="{1}")'
57 .format(PACKAGE_NAME, PACKAGE_VERSION))
58 return create_plugin(source=str(source_dir), destination_dir=str(tmpdir))