def testGetValueWithPromptingFallthrough(self, current_value):
        properties.VALUES.core.disable_prompts.Set(current_value)
        spec = copy.deepcopy(self.resource_spec)

        def GetValue():
            return console_io.PromptResponse('value? >')

        spec.attributes[0].fallthroughs = [deps.Fallthrough(GetValue, 'hint')]
        presentation_spec = presentation_specs.ResourcePresentationSpec(
            '--book',
            spec,
            'a resource',
            flag_name_overrides={'project': '--book-project'},
            prefixes=False)
        resource_info = concept_parsers.ConceptParser(
            [presentation_spec]).GetInfo(presentation_spec.name)
        ns = core_completer_test_base.MockNamespace(args={},
                                                    handler_info=resource_info)
        argument = mock.MagicMock(dest='book')

        parameter_info = resource_parameter_info.ResourceParameterInfo(
            resource_info, ns, argument)

        self.assertEqual(None, parameter_info.GetValue('projectsId'))
        # Ensure that the property is restored after GetValue.
        self.assertEqual(current_value,
                         properties.VALUES.core.disable_prompts.GetBool())
        properties.VALUES.core.disable_prompts.Set(True)
    def SetUpBookParameterInfo(self, args):
        """Creates ResourceParameterInfo for book resource.

    Args:
      args: {str: str}, dict of flag names to values for the mock namespace.

    Returns:
      resource_parameter_info.ResourceParameterInfo, the parameter info object.
    """
        ns = core_completer_test_base.MockNamespace(
            args=args, handler_info=self.resource_info)
        argument = mock.MagicMock(dest='book')
        parameter_info = resource_parameter_info.ResourceParameterInfo(
            self.resource_info, ns, argument)
        return parameter_info
 def testGetFlagNoProject(self):
     self.UnsetProject()
     presentation_spec = presentation_specs.ResourcePresentationSpec(
         '--book',
         self.resource_spec,
         'a resource',
         flag_name_overrides={},
         prefixes=False)
     resource_info = concept_parsers.ConceptParser(
         [presentation_spec]).GetInfo(presentation_spec.name)
     ns = core_completer_test_base.MockNamespace(args={},
                                                 handler_info=resource_info)
     argument = mock.MagicMock(dest='book')
     parameter_info = resource_parameter_info.ResourceParameterInfo(
         resource_info, ns, argument)
     flag = parameter_info.GetFlag('projectsId')
     self.assertEqual(None, flag)
  def ParameterInfo(self, parsed_args, argument):
    """Builds a ResourceParameterInfo object.

    Args:
      parsed_args: the namespace.
      argument: unused.

    Returns:
      ResourceParameterInfo, the parameter info for runtime information.
    """
    resource_info = parsed_args.CONCEPTS.ArgNameToConceptInfo(argument.dest)

    updaters = self._GetUpdaters()

    return resource_parameter_info.ResourceParameterInfo(
        resource_info, parsed_args, argument, updaters=updaters,
        collection=self.collection)
    def testGetValueWithFallthrough(self):
        spec = copy.deepcopy(self.resource_spec)
        spec.attributes[0].fallthroughs = [
            deps.PropertyFallthrough(properties.VALUES.core.project)
        ]
        presentation_spec = presentation_specs.ResourcePresentationSpec(
            '--book',
            spec,
            'a resource',
            flag_name_overrides={'project': '--book-project'},
            prefixes=False)
        resource_info = concept_parsers.ConceptParser(
            [presentation_spec]).GetInfo(presentation_spec.name)
        ns = core_completer_test_base.MockNamespace(args={},
                                                    handler_info=resource_info)
        argument = mock.MagicMock(dest='book')

        parameter_info = resource_parameter_info.ResourceParameterInfo(
            resource_info, ns, argument)

        self.assertEqual(self.Project(), parameter_info.GetValue('projectsId'))