Пример #1
0
    def test_list_shows_nothing_because_filter_is_set_for_templates_that_do_not_exist(
            self, max_width_mock, echo_mock):
        # Arrange
        max_width_mock.return_value = 40
        template_retriever = Mock()
        template_retriever.get_templates = Mock(return_value=OrderedDict([
            ('gen2/networking/switch',
             ShellTemplate(
                 'gen2/networking/switch',
                 'TOSCA based template for standard Switch devices/virtual appliances',
                 '', '8.0')),
            ('gen2/networking/WirelessController',
             ShellTemplate(
                 'gen2/networking/WirelessController',
                 'TOSCA based template for standard WirelessController devices/virtual appliances',
                 '', '8.0'))
        ]))
        flag_value = 'gen1'

        standards = Mock()
        standards.fetch.return_value = []

        list_command_executor = ListCommandExecutor(
            template_retriever=FilteredTemplateRetriever(
                flag_value, template_retriever),
            standards=standards)

        # Act
        list_command_executor.list()

        # Assert
        echo_mock.assert_called_once_with('No templates matched the criteria')
Пример #2
0
    def test_console_size_small_description_wrapping_logic_ignored(
            self, max_width_mock, echo_mock):
        # Arrange
        max_width_mock.return_value = 0
        template_retriever = Mock()
        template_retriever.get_templates = Mock(return_value=OrderedDict([
            ('gen2/networking/switch',
             ShellTemplate(
                 'gen2/networking/switch',
                 'TOSCA based template for standard Switch devices/virtual appliances',
                 '', '8.0')),
            ('gen2/networking/WirelessController',
             ShellTemplate(
                 'gen2/networking/WirelessController',
                 'TOSCA based template for standard WirelessController devices/virtual appliances',
                 '', '8.0'))
        ]))

        list_command_executor = ListCommandExecutor(
            template_retriever=template_retriever)

        # Act
        list_command_executor.list()

        # Assert
        echo_mock.assert_called_once_with(
            u' Template Name                       CloudShell Ver.  Description                                                                     \n'
            u'--------------------------------------------------------------------------------------------------------------------------------------\n'
            u' gen2/networking/switch              8.0 and up       TOSCA based template for standard Switch devices/virtual appliances             \n'
            u' gen2/networking/WirelessController  8.0 and up       TOSCA based template for standard WirelessController devices/virtual appliances '
        )
Пример #3
0
    def test_single_template_is_displayed(self, max_width_mock, echo_mock):
        # Arrange
        max_width_mock.return_value = 62  # mocking the max width to eliminate the distinction
        # between the running console size

        template_retriever = Mock()
        template_retriever.get_templates = Mock(return_value={
            'gen1/base':
            [ShellTemplate('gen1/base', 'description', '', '7.0')]
        })

        standards = Mock()
        standards.fetch.return_value = {}

        list_command_executor = ListCommandExecutor(
            template_retriever=template_retriever, standards=standards)

        # Act
        list_command_executor.list()

        # Assert
        echo_mock.assert_any_call(
            u' Template Name  CloudShell Ver.  Description \n'
            u'---------------------------------------------\n'
            u' gen1/base      7.0 and up       description ')
Пример #4
0
    def test_devguide_text_note_appears_when_no_filter_was_selected(
            self, max_width_mock, echo_mock):
        # Arrange
        max_width_mock.return_value = 40
        template_retriever = Mock()
        template_retriever.get_templates = Mock(return_value=OrderedDict([
            ('gen2/networking/switch',
             ShellTemplate(
                 'gen2/networking/switch',
                 'TOSCA based template for standard Switch devices/virtual appliances',
                 '', '8.0')),
            ('gen2/networking/WirelessController',
             ShellTemplate(
                 'gen2/networking/WirelessController',
                 'TOSCA based template for standard WirelessController devices/virtual appliances',
                 '', '8.0'))
        ]))
        flag_value = None

        standards = Mock()
        standards.fetch.return_value = []

        list_command_executor = ListCommandExecutor(
            template_retriever=FilteredTemplateRetriever(
                flag_value, template_retriever),
            standards=standards)

        # Act
        list_command_executor.list()

        # Assert
        echo_mock.assert_any_call('''
As of CloudShell 8.0, CloudShell uses 2nd generation shells, to view the list of 1st generation shells use: shellfoundry list --gen1.
For more information, please visit our devguide: https://qualisystems.github.io/devguide/'''
                                  )
Пример #5
0
    def test_two_templates_are_displayed(self, max_width_mock, echo_mock):
        # Arrange
        max_width_mock.return_value = 62  # mocking the max width to eliminate the distinction
        # between the running console size

        template_retriever = Mock()
        template_retriever.get_templates = Mock(return_value=OrderedDict(
            [('gen1/base',
              ShellTemplate('gen1/base', 'base description', '', '7.0', 'base')
              ),
             ('gen1/switch',
              ShellTemplate('gen1/switch', 'switch description', '', '7.0'))]))

        standards = Mock()
        standards.fetch.return_value = []

        list_command_executor = ListCommandExecutor(
            template_retriever=template_retriever, standards=standards)

        # Act
        list_command_executor.list()

        # Assert
        echo_mock.assert_any_call(
            u' Template Name  CloudShell Ver.  Description        \n'
            u'----------------------------------------------------\n'
            u' gen1/base      7.0 and up       base description   \n'
            u' gen1/switch    7.0 and up       switch description ')
Пример #6
0
    def test_filter_by_legacy_shows_all_legacy_templates(
            self, max_width_mock, echo_mock):
        # Arrange
        max_width_mock.return_value = 62
        template_retriever = Mock()
        template_retriever.get_templates = Mock(return_value=OrderedDict([
            ('gen2/networking/switch',
             ShellTemplate(
                 'gen2/networking/switch',
                 'TOSCA based template for standard Switch devices/virtual appliances',
                 '', '8.0')),
            ('gen2/networking/WirelessController',
             ShellTemplate(
                 'gen2/networking/WirelessController',
                 'TOSCA based template for standard WirelessController devices/virtual appliances',
                 '', '8.0')),
            ('gen1/base',
             ShellTemplate('gen1/base', 'base description', '', '7.0')),
            ('gen1/switch',
             ShellTemplate('gen1/switch', 'switch description', '', '7.0'))
        ]))
        flag_value = 'gen1'
        list_command_executor = ListCommandExecutor(
            template_retriever=FilteredTemplateRetriever(
                flag_value, template_retriever))

        # Act
        list_command_executor.list()

        # Assert
        echo_mock.assert_any_call(
            u' Template Name  CloudShell Ver.  Description        \n'
            u'----------------------------------------------------\n'
            u' gen1/base      7.0 and up       base description   \n'
            u' gen1/switch    7.0 and up       switch description ')
    def test_list_command_does_not_fail(self, echo_mock):
        # Arrange
        template_retriever = Mock()
        template_retriever.get_templates = Mock(return_value={'base': ShellTemplate('base', '', '')})

        list_command_executor = ListCommandExecutor(template_retriever)

        # Act
        list_command_executor.list()

        # Assert
        echo_mock.assert_called_once_with(u'Supported templates are: \r\n base')
Пример #8
0
    def test_single_template_is_displayed(self, echo_mock):
        # Arrange
        template_retriever = Mock()
        template_retriever.get_templates = Mock(return_value={'base': ShellTemplate('base', 'description', '')})

        list_command_executor = ListCommandExecutor(template_retriever)

        # Act
        list_command_executor.list()

        # Assert
        echo_mock.assert_called_once_with(u'\r\nSupported templates are:\r\n\r\n'
                                          u' base:                 description')
Пример #9
0
    def test_filter_by_all_shows_all_templates(self, max_width_mock,
                                               echo_mock):
        # Arrange
        max_width_mock.return_value = 40
        template_retriever = Mock()
        template_retriever.get_templates = Mock(
            return_value={
                'gen1/base':
                [ShellTemplate('gen1/base', 'base description', '', '7.0')],
                'gen1/switch': [
                    ShellTemplate('gen1/switch', 'switch description', '',
                                  '7.0')
                ],
                'gen2/networking/switch': [
                    ShellTemplate(
                        'gen2/networking/switch',
                        'TOSCA based template for standard Switch devices/virtual appliances',
                        '', '8.0')
                ],
                'gen2/networking/WirelessController': [
                    ShellTemplate(
                        'gen2/networking/WirelessController',
                        'TOSCA based template for standard WirelessController devices/virtual appliances',
                        '', '8.0')
                ]
            })
        flag_value = 'all'

        standards = Mock()
        standards.fetch.return_value = {}

        list_command_executor = ListCommandExecutor(
            template_retriever=FilteredTemplateRetriever(
                flag_value, template_retriever),
            standards=standards)

        # Act
        list_command_executor.list()

        # Assert
        echo_mock.assert_any_call(
            u' Template Name                       CloudShell Ver.  Description                              \n'
            u'-----------------------------------------------------------------------------------------------\n'
            u' gen2/networking/WirelessController  8.0 and up       TOSCA based template for standard        \n'
            u'                                                      WirelessController devices/virtual       \n'
            u'                                                      appliances                               \n'
            u' gen1/base                           7.0 and up       base description                         \n'
            u' gen1/switch                         7.0 and up       switch description                       \n'
            u' gen2/networking/switch              8.0 and up       TOSCA based template for standard Switch \n'
            u'                                                      devices/virtual appliances               '
        )
Пример #10
0
    def test_list_command_does_not_fail(self, echo_mock):
        # Arrange
        template_retriever = Mock()
        template_retriever.get_templates = Mock(
            return_value={'base': ShellTemplate('base', '', '')})

        list_command_executor = ListCommandExecutor(template_retriever)

        # Act
        list_command_executor.list()

        # Assert
        echo_mock.assert_called_once_with(
            u'Supported templates are: \r\n base')
Пример #11
0
    def test_two_templates_are_displayed(self, echo_mock):
        # Arrange
        template_retriever = Mock()
        template_retriever.get_templates = Mock(return_value=OrderedDict(
            [('base', ShellTemplate('base', 'base description', '')),
             ('switch', ShellTemplate('switch', 'switch description', ''))]))

        list_command_executor = ListCommandExecutor(template_retriever)

        # Act
        list_command_executor.list()

        # Assert
        echo_mock.assert_called_once_with(
            u'\r\nSupported templates are:\r\n\r\n'
            u' base:                 base description\r\n'
            u' switch:               switch description')
Пример #12
0
    def test_shows_informative_message_when_offline(self):
        # Arrange
        template_retriever = Mock()
        template_retriever.get_templates.side_effect = SSLError()
        list_command_executor = ListCommandExecutor(
            template_retriever=template_retriever, standards=Mock())

        # Assert
        self.assertRaisesRegexp(UsageError, "offline",
                                list_command_executor.list)
Пример #13
0
    def test_two_long_named_templates_are_displayed_on_normal_window(
            self, max_width_mock, echo_mock):
        # Arrange
        max_width_mock.return_value = 40  # mocking the max width to eliminate the distinction
        # between the running console size

        template_retriever = Mock()
        template_retriever.get_templates = Mock(
            return_value={
                'gen2/networking/switch': [
                    ShellTemplate(
                        'gen2/networking/switch',
                        'TOSCA based template for standard Switch devices/virtual appliances',
                        '', '8.0')
                ],
                'gen2/networking/WirelessController': [
                    ShellTemplate(
                        'gen2/networking/WirelessController',
                        'TOSCA based template for standard WirelessController devices/virtual appliances',
                        '', '8.0')
                ]
            })

        standards = Mock()
        standards.fetch.return_value = {}

        list_command_executor = ListCommandExecutor(
            template_retriever=template_retriever, standards=standards)

        # Act
        list_command_executor.list()

        # Assert
        echo_mock.assert_any_call(
            u' Template Name                       CloudShell Ver.  Description                              \n'
            u'-----------------------------------------------------------------------------------------------\n'
            u' gen2/networking/WirelessController  8.0 and up       TOSCA based template for standard        \n'
            u'                                                      WirelessController devices/virtual       \n'
            u'                                                      appliances                               \n'
            u' gen2/networking/switch              8.0 and up       TOSCA based template for standard Switch \n'
            u'                                                      devices/virtual appliances               '
        )
Пример #14
0
    def test_console_size_small_description_wrapping_logic_ignored(
            self, max_width_mock, echo_mock):
        # Arrange
        max_width_mock.return_value = 0
        template_retriever = Mock()
        template_retriever.get_templates = Mock(
            return_value={
                'gen2/networking/switch': [
                    ShellTemplate(
                        'gen2/networking/switch',
                        'TOSCA based template for standard Switch devices/virtual appliances',
                        '', '8.0')
                ],
                'gen2/networking/WirelessController': [
                    ShellTemplate(
                        'gen2/networking/WirelessController',
                        'TOSCA based template for standard WirelessController devices/virtual appliances',
                        '', '8.0')
                ]
            })

        standards = Mock()
        standards.fetch.return_value = {
            "networking": ['2.0.0'],
            "resource": ['5.0.0', '5.0.1'],
            "vido": ['3.0.1', '3.0.2', '3.0.3']
        }
        list_command_executor = ListCommandExecutor(
            template_retriever=template_retriever, standards=standards)

        # Act
        list_command_executor.list()

        # Assert
        echo_mock.assert_called_once_with(
            u' Template Name                       CloudShell Ver.  Description                                                                     \n'
            u'--------------------------------------------------------------------------------------------------------------------------------------\n'
            u' gen2/networking/WirelessController  8.0 and up       TOSCA based template for standard WirelessController devices/virtual appliances \n'
            u' gen2/networking/switch              8.0 and up       TOSCA based template for standard Switch devices/virtual appliances             '
        )
Пример #15
0
    def test_get_cs_standards_unavailable_shows_cs_8_0_shipped_templates(
            self, max_width_mock, echo_mock):
        # Assert
        max_width_mock.return_value = 60

        from shellfoundry import ALTERNATIVE_TEMPLATES_PATH
        self.fs.add_real_file(ALTERNATIVE_TEMPLATES_PATH)

        standards = Mock(fetch=Mock(side_effect=FeatureUnavailable()))

        template_retriever = FilteredTemplateRetriever('all',
                                                       TemplateRetriever())

        list_command_executor = ListCommandExecutor(
            template_retriever=template_retriever, standards=standards)

        # Act
        list_command_executor.list()

        # Assert
        templates_output = self.get_8_0_templates_output()
        echo_mock.assert_any_call(templates_output)
Пример #16
0
    def test_shows_informative_message_when_offline(self, conf_class):
        # Arrange
        configuration = MagicMock(read=MagicMock(return_value=MagicMock(
            online_mode="True")))
        conf_class.return_value = configuration
        template_retriever = Mock()
        template_retriever.get_templates.side_effect = SSLError()
        list_command_executor = ListCommandExecutor(
            template_retriever=template_retriever, standards=Mock())

        # Assert
        self.assertRaisesRegexp(UsageError, "offline",
                                list_command_executor.list)
Пример #17
0
    def test_list_shows_nothing_because_filter_is_set_for_templates_that_do_not_exist(
            self, max_width_mock):
        # Arrange
        max_width_mock.return_value = 40
        template_retriever = Mock()
        template_retriever.get_templates = Mock(
            return_value={
                'gen2/networking/switch': [
                    ShellTemplate(
                        'gen2/networking/switch',
                        'TOSCA based template for standard Switch devices/virtual appliances',
                        '', '8.0')
                ],
                'gen2/networking/WirelessController': [
                    ShellTemplate(
                        'gen2/networking/WirelessController',
                        'TOSCA based template for standard WirelessController devices/virtual appliances',
                        '', '8.0')
                ]
            })
        flag_value = 'gen1'

        standards = Mock()
        standards.fetch.return_value = {}

        list_command_executor = ListCommandExecutor(
            template_retriever=FilteredTemplateRetriever(
                flag_value, template_retriever),
            standards=standards)

        # Act
        with self.assertRaisesRegexp(
                ClickException,
                "No templates matched the view criteria\(gen1/gen2\) or "
                "available templates and standards are not compatible"):
            list_command_executor.list()
Пример #18
0
def list(default_view):
    """
    Lists the available shell templates
    """
    ListCommandExecutor(default_view).list()
Пример #19
0
    def test_templates_are_filtered_based_upon_the_result_of_cs_standards_gen2(
            self, max_width_mock, echo_mock):
        # Arrange
        max_width_mock.return_value = 40
        templates = """templates:
        - name : gen1/resource
          description : base description
          repository : https://github.com/QualiSystems/shell-resource-standard
          params:
            project_name :
          min_cs_ver: 7.0
        - name : gen1/switch
          description : switch description
          repository : https://github.com/QualiSystems/shell-switch-standard
          params:
            project_name :
          min_cs_ver: 7.0
        - name : gen2/resource
          params:
            project_name :
            family_name:
          description : 2nd generation shell template for a standard resource
          repository : https://github.com/QualiSystems/shellfoundry-tosca-resource-template
          min_cs_ver: 8.0
        - name : gen2/networking/switch
          params:
            project_name :
            family_name: Switch
          description : 2nd generation shell template for a standard switch
          repository : https://github.com/QualiSystems/shellfoundry-tosca-networking-template
          min_cs_ver: 8.0
        - name : gen2/networking/wireless-controller
          params:
            project_name :
            family_name: WirelessController
          description : 2nd generation shell template for a standard wireless controller
          repository : https://github.com/QualiSystems/shellfoundry-tosca-networking-template
          min_cs_ver: 8.0"""

        flag_value = 'gen2'

        standards = Mock()
        standards.fetch.return_value = [{
            'StandardName': 'cloudshell_networking_standard',
            "Versions": ['5.0.0']
        }]

        template_retriever = FilteredTemplateRetriever(flag_value,
                                                       TemplateRetriever())

        httpretty.register_uri(httpretty.GET, TEMPLATES_YML, body=templates)

        list_command_executor = ListCommandExecutor(
            template_retriever=template_retriever, standards=standards)

        # Act
        list_command_executor.list()

        # Assert
        echo_mock.assert_any_call(
            u' Template Name                        CloudShell Ver.  Description                         \n'
            u'-------------------------------------------------------------------------------------------\n'
            u' gen2/networking/switch               8.0 and up       2nd generation shell template for a \n'
            u'                                                       standard switch                     \n'
            u' gen2/networking/wireless-controller  8.0 and up       2nd generation shell template for a \n'
            u'                                                       standard wireless controller        '
        )
Пример #20
0
    def test_templates_are_filtered_based_upon_the_result_of_cs_standards(
            self, _get_min_cs_version, conf_class, max_width_mock, echo_mock):
        # Arrange
        _get_min_cs_version.return_value = None
        configuration = MagicMock(read=MagicMock(return_value=MagicMock(
            online_mode="True")))
        conf_class.return_value = configuration
        max_width_mock.return_value = 40
        templates = """templates:
    - name : gen1/resource
      description : base description
      repository : https://github.com/QualiSystems/shell-resource-standard
      params:
        project_name :
      min_cs_ver: 7.0
    - name : gen1/switch
      description : switch description
      repository : https://github.com/QualiSystems/shell-switch-standard
      params:
        project_name :
      min_cs_ver: 7.0
    - name : gen2/resource
      params:
        project_name :
        family_name:
      description : 2nd generation shell template for a standard resource
      repository : https://github.com/QualiSystems/shellfoundry-tosca-resource-template
      min_cs_ver: 8.0
    - name : gen2/networking/switch
      params:
        project_name :
        family_name: Switch
      description : 2nd generation shell template for a standard switch
      repository : https://github.com/QualiSystems/shellfoundry-tosca-networking-template
      min_cs_ver: 8.0
    - name : gen2/networking/wireless-controller
      params:
        project_name :
        family_name: WirelessController
      description : 2nd generation shell template for a standard wireless controller
      repository : https://github.com/QualiSystems/shellfoundry-tosca-networking-template
      min_cs_ver: 8.0"""

        flag_value = 'all'

        standards = Mock()
        standards.fetch.return_value = {"resource": ['5.0.0']}

        template_retriever = FilteredTemplateRetriever(flag_value,
                                                       TemplateRetriever())

        httpretty.register_uri(httpretty.GET, TEMPLATES_YML, body=templates)

        list_command_executor = ListCommandExecutor(
            template_retriever=template_retriever, standards=standards)

        # Act
        list_command_executor.list()

        # Assert
        echo_mock.assert_any_call(
            u' Template Name  CloudShell Ver.  Description                         \n'
            u'---------------------------------------------------------------------\n'
            u' gen1/resource  7.0 and up       base description                    \n'
            u' gen1/switch    7.0 and up       switch description                  \n'
            u' gen2/resource  8.0 and up       2nd generation shell template for a \n'
            u'                                 standard resource                   '
        )
Пример #21
0
def list():
    """
    List shell templates.
    """
    ListCommandExecutor().list()