Esempio n. 1
0
 def find(self, name=None):
     if name == '9999':
         # NOTE(morganfainberg): special case that raises NoUniqueMatch.
         raise exceptions.NoUniqueMatch()
     for resource_id, resource in self.resources.items():
         if resource['name'] == str(name):
             return resource
     raise exceptions.NotFound(name)
    def test_service_show_nounique(self):
        self.services_mock.find.side_effect = identity_exc.NoUniqueMatch(None)
        arglist = [
            'nounique_service',
        ]
        verifylist = [
            ('service', 'nounique_service'),
        ]
        parsed_args = self.check_parser(self.cmd, arglist, verifylist)

        try:
            self.cmd.take_action(parsed_args)
            self.fail('CommandError should be raised.')
        except exceptions.CommandError as e:
            self.assertEqual(
                "Multiple service matches found for 'nounique_service',"
                " use an ID to be more specific.", str(e))