vFW and vDNS support added to azure-plugin
[multicloud/azure.git] / azure / aria / aria-extension-cloudify / src / aria / tests / utils / test_plugin.py
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
7 #
8 #     http://www.apache.org/licenses/LICENSE-2.0
9 #
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.
15
16 import os
17
18 import pytest
19
20 from aria.orchestrator import exceptions
21 from aria.utils.plugin import create as create_plugin
22
23 from ..fixtures import (  # pylint: disable=unused-import
24     plugins_dir,
25     plugin_manager,
26     inmemory_model as model
27 )
28
29
30 PACKAGE_NAME = 'mock-plugin'
31 PACKAGE_VERSION = '100'
32
33
34 class TestPluginManager(object):
35
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)
44
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)
49
50
51 @pytest.fixture
52 def mock_plugin(tmpdir):
53     source_dir = tmpdir.join('mock_plugin')
54     source_dir.mkdir()
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))