Пример #1
0
    def test_service_list_by_fqns(self, mock_services_list):
        self.assertEqual([], env_api.service_list_by_fqns(None, None, []))

        mock_services_list.return_value = [
            {'?': {'type': 'foo/bar'}}, {'?': {'type': 'baz/qux'}}
        ]
        result = env_api.service_list_by_fqns(
            self.mock_request, 'foo_env_id', ['foo'])
        self.assertEqual([{'?': {'type': 'foo/bar'}}], result)
Пример #2
0
    def test_service_list_by_fqns(self, mock_services_list):
        self.assertEqual([], env_api.service_list_by_fqns(None, None, []))

        mock_services_list.return_value = [
            {'?': {'type': 'foo/bar'}}, {'?': {'type': 'baz/qux'}}
        ]
        result = env_api.service_list_by_fqns(
            self.mock_request, 'foo_env_id', ['foo'])
        self.assertEqual([{'?': {'type': 'foo/bar'}}], result)
Пример #3
0
        def update(self, request, environment_id, **kwargs):
            def _make_link():
                ns_url = 'horizon:murano:catalog:add'

                def _reverse(_fqn):
                    _app = pkg_api.app_by_fqn(request, _fqn)
                    if _app is None:
                        msg = "Application with FQN='{0}' doesn't exist"
                        messages.error(request, msg.format(_fqn))
                        raise Http404(msg.format(_fqn))
                    args = (_app.id, environment_id, False, True)
                    return _app.name, reverse(ns_url, args=args)

                return json.dumps([_reverse(cls) for cls in fqns])

            self.widget.add_item_link = _make_link
            apps = env_api.service_list_by_fqns(request, environment_id, fqns)
            choices = [('', self.empty_value_message)]
            choices.extend([(app['?']['id'], html.escape(app.name))
                            for app in apps])
            self.choices = choices
            # NOTE(tsufiev): streamline the drop-down UX: auto-select the
            # single available option in a drop-down
            if len(choices) == 2:
                self.initial = choices[1][0]
        def update(self, request, environment_id, **kwargs):
            matching_classes = []
            fqns_seen = set()
            # NOTE(kzaitsev): it's possible to have a private
            # and public apps with the same fqn, however the engine would
            # currently favor private package. Therefore we should squash
            # these until we devise a better way to work with this
            # situation and versioning

            for class_fqn in fqns:
                app_found = pkg_api.app_by_fqn(request, class_fqn)
                if app_found:
                    fqns_seen.add(app_found.fully_qualified_name)
                    matching_classes.append(app_found)

                apps_found = pkg_api.apps_that_inherit(request, class_fqn)
                for app in apps_found:
                    if app.fully_qualified_name in fqns_seen:
                        continue
                    fqns_seen.add(app.fully_qualified_name)
                    matching_classes.append(app)

            if not matching_classes:
                msg = _("Couldn't find any apps, required for this field.\n"
                        "Tried: {fqns}").format(fqns=', '.join(fqns))
                self.widget = ErrorWidget(message=msg)

            # NOTE(kzaitsev): this closure is needed to allow us have custom
            # logic when clicking add button
            def _make_link():
                ns_url = 'horizon:app-catalog:catalog:add'
                ns_url_args = (environment_id, False, True)

                # This will prevent horizon from adding an extra '+' button
                if not matching_classes:
                    return ''

                return json.dumps([(app.name,
                                    reverse(ns_url,
                                            args=((app.id, ) + ns_url_args)))
                                   for app in matching_classes])

            self.widget.add_item_link = _make_link

            apps = env_api.service_list_by_fqns(
                request, environment_id,
                [app.fully_qualified_name for app in matching_classes])
            choices = [('', self.empty_value_message)]
            choices.extend([(app['?']['id'], html.escape(app.name))
                            for app in apps])
            self.choices = choices
            # NOTE(tsufiev): streamline the drop-down UX: auto-select the
            # single available option in a drop-down
            if len(choices) == 2:
                self.initial = choices[1][0]
Пример #5
0
        def update(self, request, environment_id, **kwargs):
            matching_classes = []
            fqns_seen = set()
            # NOTE(kzaitsev): it's possible to have a private
            # and public apps with the same fqn, however the engine would
            # currently favor private package. Therefore we should squash
            # these until we devise a better way to work with this
            # situation and versioning

            for class_fqn in fqns:
                app_found = pkg_api.app_by_fqn(request, class_fqn)
                if app_found:
                    fqns_seen.add(app_found.fully_qualified_name)
                    matching_classes.append(app_found)

                apps_found = pkg_api.apps_that_inherit(request, class_fqn)
                for app in apps_found:
                    if app.fully_qualified_name in fqns_seen:
                        continue
                    fqns_seen.add(app.fully_qualified_name)
                    matching_classes.append(app)

            if not matching_classes:
                msg = _(
                    "Couldn't find any apps, required for this field.\n"
                    "Tried: {fqns}").format(fqns=', '.join(fqns))
                self.widget = ErrorWidget(message=msg)

            # NOTE(kzaitsev): this closure is needed to allow us have custom
            # logic when clicking add button
            def _make_link():
                ns_url = 'horizon:app-catalog:catalog:add'
                ns_url_args = (environment_id, False, True)

                # This will prevent horizon from adding an extra '+' button
                if not matching_classes:
                    return ''

                return json.dumps([
                    (app.name, reverse(ns_url, args=((app.id,) + ns_url_args)))
                    for app in matching_classes])

            self.widget.add_item_link = _make_link

            apps = env_api.service_list_by_fqns(
                request, environment_id,
                [app.fully_qualified_name for app in matching_classes])
            choices = [('', self.empty_value_message)]
            choices.extend([(app['?']['id'],
                             html.escape(app.name)) for app in apps])
            self.choices = choices
            # NOTE(tsufiev): streamline the drop-down UX: auto-select the
            # single available option in a drop-down
            if len(choices) == 2:
                self.initial = choices[1][0]
Пример #6
0
        def update(self, request, environment_id, **kwargs):
            def _make_link():
                ns_url = 'horizon:murano:catalog:add'

                def _reverse(_fqn):
                    _app = pkg_api.app_by_fqn(request, _fqn)
                    if _app is None:
                        msg = "Application with FQN='{0}' doesn't exist"
                        messages.error(request, msg.format(_fqn))
                        raise Http404(msg.format(_fqn))
                    args = (_app.id, environment_id, False, True)
                    return _app.name, reverse(ns_url, args=args)
                return json.dumps([_reverse(cls) for cls in fqns])

            self.widget.add_item_link = _make_link
            apps = env_api.service_list_by_fqns(request, environment_id, fqns)
            choices = [('', self.empty_value_message)]
            choices.extend([(app['?']['id'],
                             html.escape(app.name)) for app in apps])
            self.choices = choices
            # NOTE(tsufiev): streamline the drop-down UX: auto-select the
            # single available option in a drop-down
            if len(choices) == 2:
                self.initial = choices[1][0]