[MERGE] Add get_username() call to the UIFactory.

Vincent Ladeuil v.ladeuil+lp at free.fr
Tue Mar 31 16:14:39 BST 2009


>>>>> "Jelmer" == Jelmer Vernooij <jelmer at samba.org> writes:

    Jelmer> The attached patch adds a get_username() function to the UIFactory. This is 
    Jelmer> required for username prompting during authentication.

    Jelmer> Cheers,

    Jelmer> Jelmer
    Jelmer> # Bazaar merge directive format 2 (Bazaar 0.90)
    Jelmer> # revision_id: jelmer at samba.org-20090331135833-fpo4w8n5tco13z81
    Jelmer> # target_branch: http://bazaar-vcs.org/bzr/bzr.dev
    Jelmer> # testament_sha1: 9c44ed4333831cc40628c617459c8365200b3bed
    Jelmer> # timestamp: 2009-03-31 15:59:10 +0200
    Jelmer> # base_revision_id: pqm at pqm.ubuntu.com-20090331122525-77wqe7gqpr2gcl7u
    Jelmer> # 
    Jelmer> # Begin patch
    Jelmer> === modified file 'bzrlib/tests/test_ui.py'
    Jelmer> --- bzrlib/tests/test_ui.py	2009-03-23 14:59:43 +0000
    Jelmer> +++ bzrlib/tests/test_ui.py	2009-03-31 13:58:33 +0000
    Jelmer> @@ -254,6 +254,27 @@
    Jelmer>          finally:
    Jelmer>              pb.finished()

    Jelmer> +
    Jelmer> +    def test_text_ui_getusername(self):
    Jelmer> +        factory = TextUIFactory(None, None, None)
    Jelmer> +        factory.stdin = StringIO("someuser\n\n")
    Jelmer> +        factory.stdout = StringIO()
    Jelmer> +        # there is no output from the base factory
    Jelmer> +        self.assertEqual("someuser", 
    Jelmer> +            factory.get_username('Hello %(host)s', host='some'))
    Jelmer> +        self.assertEquals("Hello some: ", factory.stdout.getvalue())
    Jelmer> +        self.assertEqual("", factory.get_username("Gebruiker"))
    Jelmer> +        # stdin should be empty
    Jelmer> +        self.assertEqual('', factory.stdin.readline())
    Jelmer> +

You want to do the same tests than get_password (utf8, etc).
 
    Jelmer>  class TestTextProgressView(TestCase):
    Jelmer>      """Tests for text display of progress bars.

    Jelmer> === modified file 'bzrlib/ui/__init__.py'
    Jelmer> --- bzrlib/ui/__init__.py	2009-03-23 14:59:43 +0000
    Jelmer> +++ bzrlib/ui/__init__.py	2009-03-31 13:58:33 +0000
    Jelmer> @@ -189,6 +189,21 @@
    Jelmer>          # as opposed to 'my password is empty' -- does it matter?
    Jelmer>          return self.get_non_echoed_password(prompt)
 
    Jelmer> +    def get_username(self, prompt, **kwargs):
    Jelmer> +        """Prompt the user for a password.
    Jelmer> +
    Jelmer> +        :param prompt: The prompt to present the user
    Jelmer> +        :param kwargs: Arguments which will be expanded into the prompt.
    Jelmer> +                       This lets front ends display different things if
    Jelmer> +                       they so choose.
    Jelmer> +        :return: The password string, return None if the user
    Jelmer> +                 canceled the request.

s/password/user/

    Jelmer> +        """
    Jelmer> +        prompt += ': '
    Jelmer> +        prompt = (prompt % kwargs)
    Jelmer> +        self.prompt(prompt)
    Jelmer> +        return self.stdin.readline().rstrip("\n")

get_non_echoed_password can raise NotATerminal and encode the
prompt according to the terminal encoding, I think get_username
should do the same, time to refactor...

With the missing tests added, that's

BB:tweak

        Vincent



More information about the bazaar mailing list